Hi!
Recently we made a small remote controlled car using Sun SPOTs and IC L293D. See for yourself how easy it can get using Sun SPOTs powered by Java!!
Requirements:
1. Sun SPOT Kit. (Two Sun SPOTs)
2. IC L2393D.
3. DC Motors 2 Nos.
4. A car which you can dismantle and control using DC Motors having enough space to accomodate Sun SPOT and circuit..
5. Patience and some nice coffee and refreshments!!!
Hardware:
The Hardware basically centers around Sun SPOTs and DC Motors controlled by IC L293D.
The Basic Model is as Follows:
Here remote Sun SPOT will send data to Sun SPOT on car which will drive the IC according to DC IO pins D0 - D3. The IC will drive the Motors which will run the car.
The circuit diagram for the IC is as follows. I think its self explanatory.

Software:
The Software consist of two parts:
1. Remote Control Spot.
Make a new Sun Spot Application say - "RemoteSpot" and add the following code to the StartApp file:
package org.sunspotworld.demo;
import com.sun.spot.io.j2me.radiogram.Radiogram;
import com.sun.spot.io.j2me.radiogram.RadiogramConnection;
import com.sun.spot.peripheral.NoRouteException;
import com.sun.spot.peripheral.Spot;
import com.sun.spot.peripheral.radio.IRadioPolicyManager;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.ITriColorLED;
import com.sun.spot.sensorboard.peripheral.IAccelerometer3D;
import java.io.IOException;
import javax.microedition.midlet.MIDletStateChangeException;
import com.sun.spot.util.IEEEAddress;
import com.sun.spot.util.Utils;
import javax.microedition.io.Connector;
/**
* Remote Spot will send Tilt values to the Car Spot.
*
* @author Jay Mahadeokar
*/
public class StartApp extends javax.microedition.midlet.MIDlet {
EDemoBoard demoboard = EDemoBoard.getInstance();
protected void startApp() throws MIDletStateChangeException {
IRadioPolicyManager rpm = Spot.getInstance().getRadioPolicyManager();
IEEEAddress myAddr = new IEEEAddress(rpm.getIEEEAddress());
System.out.println("Hi! my address = " + myAddr.asDottedHex());
//This is my Car Sun SPOT address
IEEEAddress bsAddress = new IEEEAddress(new String("0014.4F01.0000.1231"));
IAccelerometer3D acc = demoboard.getAccelerometer();
while(true)
{
try{
RadiogramConnection conn = (RadiogramConnection)Connector.open("radiogram://0014.4F01.0000.1A29:10");
Radiogram rdg = (Radiogram)conn.newDatagram(conn.getMaximumLength());
try
{
//Get control called and value sent to car spot!
rdg.writeUTF(""+getControl());
conn.send(rdg);
Utils.sleep(200); // Sleep for sometime!
}
catch (NoRouteException e)
{
System.out.println ("No route to 0014.4F01.0000.1A29");
}
finally
{
conn.close();
}
}
catch(IOException e){
System.out.println("There is a problem opening the connection");
}
}
}
//Returns the numeric value corresponding to the current Tilt Positions of
//Sun SPOT
//Return values only if Tilt > 0.5 or Tilt < -0.5
public int getControl()
{
int ret = 0;
try {
double xTilt = demoboard.getAccelerometer().getTiltX();
double yTilt = demoboard.getAccelerometer().getTiltY();
if (xTilt > 0.5 && yTilt < 0.5 && yTilt > -0.5) {
ret = 110;
}
if (xTilt < -0.5 && yTilt < 0.5 && yTilt > -0.5) {
ret = 101;
}
if (yTilt > 0.5 && xTilt < 0.5 && xTilt > -0.5) {
ret = 100;
}
if (yTilt < -0.5 && xTilt < 0.5 && xTilt > -0.5) {
ret = 1000;
}
} catch (IOException ex) {
ex.printStackTrace();
}
return ret;
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
ITriColorLED [] leds = EDemoBoard.getInstance().getLEDs();
for (int i = 0; i < 8; i++) { // turn off the LEDs when we exit
leds[i].setOff();
}
}
protected void pauseApp() {
}
}
2. Car Spot Application.
Make another Sun Spot App and add following code to StartApp. This Spot will be placed on Car and will drive the IC.
import com.sun.spot.io.j2me.radiogram.Radiogram;
import com.sun.spot.io.j2me.radiogram.RadiogramConnection;
import com.sun.spot.peripheral.NoRouteException;
import com.sun.spot.peripheral.Spot;
import com.sun.spot.peripheral.radio.IRadioPolicyManager;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.ITriColorLED;
import com.sun.spot.sensorboard.peripheral.IAccelerometer3D;
import java.io.IOException;
import javax.microedition.midlet.MIDletStateChangeException;
import com.sun.spot.util.IEEEAddress;
import com.sun.spot.util.Utils;
import javax.microedition.io.Connector;
/**
* Remote Spot will send Tilt values to the Car Spot.
*
* @author Jay Mahadeokar
*/
public class StartApp extends javax.microedition.midlet.MIDlet {
EDemoBoard demoboard = EDemoBoard.getInstance();
protected void startApp() throws MIDletStateChangeException {
//This is my Car Sun SPOT address
IEEEAddress bsAddress = new IEEEAddress(new String("0014.4F01.0000.1231"));
IAccelerometer3D acc = demoboard.getAccelerometer();
while(true)
{
try{
RadiogramConnection conn = (RadiogramConnection)Connector.open("radiogram://0014.4F01.0000.1A29:10");
Radiogram rdg = (Radiogram)conn.newDatagram(conn.getMaximumLength());
try
{
//Get control called and value sent to car spot!
rdg.writeUTF(""+getControl());
conn.send(rdg);
Utils.sleep(200); // Sleep for sometime!
}
catch (NoRouteException e)
{
System.out.println ("No route to 0014.4F01.0000.1A29");
}
finally
{
conn.close();
}
}
catch(IOException e){
System.out.println("There is a problem opening the connection");
}
}
}
//Returns the numeric value corresponding to the current Tilt Positions of
//Sun SPOT
//Return values only if Tilt > 0.5 or Tilt < -0.5
public int getControl()
{
int ret = 0;
try {
double xTilt = demoboard.getAccelerometer().getTiltX();
double yTilt = demoboard.getAccelerometer().getTiltY();
if (xTilt > 0.5 && yTilt < 0.5 && yTilt > -0.5) {
ret = 110;
}
if (xTilt < -0.5 && yTilt < 0.5 && yTilt > -0.5) {
ret = 101;
}
if (yTilt > 0.5 && xTilt < 0.5 && xTilt > -0.5) {
ret = 100;
}
if (yTilt < -0.5 && xTilt < 0.5 && xTilt > -0.5) {
ret = 1000;
}
} catch (IOException ex) {
ex.printStackTrace();
}
return ret;
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
ITriColorLED [] leds = EDemoBoard.getInstance().getLEDs();
for (int i = 0; i < 8; i++) { // turn off the LEDs when we exit
leds[i].setOff();
}
}
protected void pauseApp() {
}
}
Thats It!!! Now biuld the Apps and Deploy On Sun SPOTs. Mount the Car SPOT on Car and control it using Remote Spot!!
You can control car by tilting Spot:
Left - To Move left and accelarate.
Right - To move Right and Accelarate.
Down - To Move the Car Forward.
Up - To Reverse.
Note: The connections of circuit may be really tedious and may take a lot of time!
Thanks a lot to Mr. Abhishek Hisaria who designed the Hardware.

Some Pictures:
![]()
Thats Me!! The Car The Car Again!!
See more Pictures at: http://picasaweb.google.com/jai.mahadeokar/SunBlog
Cheers!!


Cool - I really like this :)
Posted by Michael Clarke on September 17, 2008 at 08:07 AM PDT #
Nice blog post. Welcome to the league of Sun SPOT racers.. lets get down for a race between our cars someday ;)
Posted by Angad Singh on September 17, 2008 at 10:21 AM PDT #
Thanks a lot Guys!
And Angad AKA Mr Robot Control, the race would be really interesting !!
Posted by Jay Mahadeokar on September 17, 2008 at 10:35 AM PDT #
Looks like you accidentally posted the code for the remote spot twice instead of posting the code for the car spot.
Posted by anon on April 10, 2009 at 04:04 PM PDT #
I wish to learn the basics of robotics. I'd be glad if you mail me the complete information.
Posted by Santhosh on July 30, 2009 at 01:30 AM PDT #
Can you post the code for the car spot?
Posted by mejay on August 10, 2009 at 04:42 AM PDT #