Bluebots, Bluetooth, Android and a Magician

Bluebots, Bluetooth, Android and a Magician

Sounds like the title of a fairy tale, but for us techie's this is much more interesting. We bring together three great bits of kit

This tutorial will show you how easy it is to use your Android phone to control a remote vehicle or robot using either the joystick or tilt functionality.

Bluebots Android App What makes this project easy is a great little Android app called Bluebots written by one of our customers

Download it to your Android phone from the Google Play store

 

First we are going to add our HT Bluetooth Adapter to our existing Magician Chassis setup. This simply goes in place of the FTDI Basic board we use to program the Arduino.

HT Bluetooth Adapter

If you dont have a Magician chassis setup, don't worry, you can add the Bluetooth adapter to pretty much any programmable autonomous vehicle or robot that has a UART serial port.

Magician Chassis with HT Bluetooth Adapter

The Bluebots app sends out 4-byte data packets to indicate tilt angle, button presses etc. Full details of these packets are included in the help screen on the app.

Bluebots Android app main screen

When you start the Bluebots app it will show you any bluetooth devices you have already paired with and also any newly discovered devices. Either select the already paired device if you have already set one up, or go ahead and pair with a new device.

The HT Bluetooth Adapter will appear by default as 'linvor' and the pairing code is 1234.

When you select your paired bluetooth adapter it will prompt you to select one of three modes. Joystick, Tilt or Multi. For our purposes go ahead and select either Joystick or Tilt. Personally, tilt is our favourite and is the main one you will see in the video.

Bluebots Android app Joystick screen Bluebots Joystick interface also includes a slider and 5 buttons that can be used to control other features of your vehicle.

Bluebots tilt screen. Controlling the Magician chassis is simplicity itself, just tilt forward to go forwards, back for reverse and left and right to turn.

Bluebots Android app tilt screen

For our Arduino based Magician Chassis we have written a very basic sketch that reads the 4 byte commands sent from the Bluebots app and uses this to control the power applied to each motor. It simply adds or subtracts the Left and Right values from the Forward and Backward tilt values to create a value to send to each motor. It is not a very sophisticated algorithm, but it works pretty well.

The Arduino sketch is shown below. Note that we have increased the HT Bluetooth baud rate from the standard 9600 to 115200.

 

/* Magician Chassis Bluebots Bluetooth
   Hobbytronics ltd, 2012
   
*/

#define baudRate 115200

// Setup pins for SN754410 Motor chip

int lf = 6;      // Left motor Forward
int lr = 5;      // Left motor Reverse
int rf = 11;     // Right motor Forward
int rr = 10;     // Right motor Reverse

int left = 0; 
int right = 0; 

unsigned char data_packet[4];
unsigned char packet_index=0;

void setup()  { 
  
  // use the baud rate your bluetooth module is configured to 
  Serial.begin(baudRate); 
    
} 

void loop()  { 
  
  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte:
    data_packet[packet_index] = Serial.read();
    packet_index++;
    if(packet_index==4)
    {
      // full packet received
      process_packet();
    }  
  }
  setMotors();
}

void process_packet()
{
  int lspeed, lturn;
  
  packet_index=0;
  if((data_packet[0]==43) || (data_packet[0]==45))
  {
    if(data_packet[0]==43) lturn=data_packet[1];
    else lturn=data_packet[1]*-1;

    if(data_packet[2]==43) lspeed=data_packet[3]*2;
    else lspeed=data_packet[3]*-2;    
    
    left=(lspeed+lturn);
    left = constrain(left, -255, 255);
    right=(lspeed-lturn);
    right = constrain(right, -255, 255);    
      
  }  
 
}

void setMotors()
{
   int vLeft = left;
   int vRight = right;
   if (vLeft < 0)
   {
        analogWrite(lf, 0);         
        analogWrite(lr, abs(vLeft)); 
   }
   else{
        analogWrite(lf, abs(vLeft));         
        analogWrite(lr, 0);      
   }
   
   if (vRight < 0)
   {
        analogWrite(rf, 0);         
        analogWrite(rr, abs(vRight)); 
   }
   else{
        analogWrite(rf, abs(vRight));         
        analogWrite(rr, 0);      
   }          

  
}


Hopefully this tutorial has shown you how easy it can be to add bluetooth connectivity to your vehicle or robot and control it with an Android mobile phone. The Bluebots Android app helps make this easy.

Now let's show you what you have all been waiting for, the video.

Shopping Cart
0 items
 
DELIVERY/PAYMENT

Free Delivery Orders over £50

UK - £2.40 orders under £50
Airmail from £2.95 (+VAT)
More Details...

 
Brands
 
 Check out our videos
Follow us on:
acebook