Sunday, 29 June 2014

Bluetooth Controlled Arduino Robot

Recently just for fun (Back in April!!) I decided to make an Arduino based bluetooth robot - a rover if you will!

I wanted to try to keep things as simple as possible so I looked online for some inspiration and decided a simple 3 wheeled rover would be best.  In order to make the project remote control I decided to use a simple bluetooth module and remote control the rover from my Android based mobile phone tablet.

Here are the components needed for this project:

2x continuous rotation servos - Available from Ebay here!

1x bluetooth HC-06 module - Available from Ebay here!

1x Arduino Uno or compatible - Available from Ebay here!

1x Swivel Castor Wheel - Available from Clas Ohlson Here!

1x AA Battery box - Available from Ebay here!

2x Breadboards - (optional, but useful) - Available from Ebay Here!

2x Ultrasonic sensor boards (optional) - Available from Ebay here!

1x Chassis - to be designed

2x Plastic Wheels - to be 3d printed using designs from Thingiverse - Download design file in STL format

The first thing I did once I had obtained all of the off the shelf parts was check everything worked.  The servos were very easy to test.  All I did was load up the arduino website and search for a servo control library and followed the on screen instructions:

Arduino Servo library sweep tutorial

I followed the instructions present to the letter and whaddya know....worked first time!  I checked both servos were working.  I then modified the code as I wanted to be able to use my servos to power wheels.  I learned a tip on the way, setting the servo position to '90' stops the servo running, 180 sends the servo running at full speed and 0 sends the servo running at full speed in the opposite direction - useful to know!  I normally draw a schematic diagram for displaying how I made the connections but today I think I will use fritzing:


I then wrote the following code based on the example code from the arduino servo sweep tutorial.  If the user presses the keys 1 to 4 in the serial terminal followed by return the servo motors will respond and choose a direction.  The code should be fairly self explanatory.

/* Robot servo test - 31-03-2014

Uses the servo library 

Press keys 1 to 9 to make the servos move in a direction or stop 

*/

#include <Servo.h> 

Servo myServoLeft;  // create servo object to control the left                           // servo 
Servo myServoRight; // create servo object to control the right                         // servo                  

int posLeft = 90;   // variable to store the left servo position
int posRight = 90;  // variable to store the right servo position
                    // they are set to 90 to prevent movement at                         // start

char var=0;         // variable to store user choice

void setup() 


  // initialize serial:
  Serial.begin(9600);
  
  myServoLeft.attach(10);  // attaches the Left servo on pin 9 to                              // myServoLeft object
  myServoRight.attach(5);  // attaches the Right servo on pin 10 to                            // myServoRight object 
  
  stopMoving();            // a function to ensure the wheels don't 
                           // move until we are ready!


void loop() 

  Serial.flush();          // Clear the serial comms
  
  var = Serial.read();     // read the user keypress
  
  switch (var) 
  {
    case '1':
      delay(100);
      moveForward();
      break;
    case '2':
      moveBackward();
      delay(100);
      break;
    case '3':
      leftTurn();
      break;
    case '4':
      rightTurn();
      delay(100);
      break;
    case '5':
      stopMoving();
      break;
    case '6':
     stopMoving();
      break;
    case '7':
      stopMoving();
      break;
    case '8':
      stopMoving();
      break;
    case '9':
      stopMoving();
      break;  
  }  
}

void moveForward()
{
  
  Serial.print("Moving Forwards ");
  Serial.println();
  
  //set left servo going forward
  posLeft = 0;
  myServoLeft.write(posLeft);
  
  //set Right servo going forward
  posRight = 180;
  myServoRight.write(posRight);
  
  Serial.flush();
  
  delay(15);
  
}

void moveBackward()
{
    
  Serial.print("Moving Back ");
  Serial.println();
  
  //set left servo going back
  posLeft = 180;
  myServoLeft.write(posLeft);
  
  //set Right servo going back
  posRight = 0;
  myServoRight.write(posRight);
  
  Serial.flush();
    
  delay(15);
  
}

void leftTurn()
{
  Serial.print("Turning Left ");
  Serial.println();
   
  //set left servo going back
  posLeft = 0;
  myServoLeft.write(posLeft);
  
  //set Right servo going back
  posRight = 0;
  myServoRight.write(posRight);
  
  Serial.flush();
  
  delay(15);
}

void rightTurn()
{
  Serial.print("Turning Right ");
  Serial.println();
  
  //set left servo going back
  posLeft = 180;
  myServoLeft.write(posLeft);
  
  //set Right servo going back
  posRight = 180;
  myServoRight.write(posRight);
  
  Serial.flush();
  
  delay(15);
}

void stopMoving()
{
  Serial.print("Robot Halted");
  Serial.println();
  
  //set left servo to stop
  posLeft = 90;
  myServoLeft.write(posLeft);
  
  //set Right servo to stop
  posRight = 90;
  myServoRight.write(posRight);
  
  Serial.flush();
  
  delay(15);  
}

I then added the best bit - a bluetooth tranceiver module - this gizmo allows me to control the servos remotely (and therefore the rover) using any bluetooth connected device.  These things are available everywhere on ebay, are fairly cheap and work out of the box...mostly.


All that needed to be done was to make the correct connections of +5V to Vcc, 0V to GND and RX connects to TX on the arduino uno and TX connects to RX on the arduino UNO.  Then using a serial terminal program on my PC and a bluetooth USB dongle acting as a COM port I could control the servos remotely - <REALLY BIG GRIN>

Once I had the servos working I designed a shield to take the servo connections directly to the arduino without having wires everywhere.  I added connectivity for the bluetooth module and some ultrasonic sensors to make things easy for me so I can plug and unplug things easily.  I intend to use this board as a learning and development tool.  Here is the schematic diagram and PCB layout:

ServoMotor Shield Schematic
ServoMotor Shield PCB Layout

I then made the PCB, populated it and slapped in on my arduino - for once it worked first time!!  The next thing to do was to design a chassis.  In this case I had options - I'm not the best at mechanical design but the more I practice the better I will get.  I chose to laser cut a chassis and use a flat plate which I can augment as and when I need to.  I ended up drawing something similar to a plastic tombstone in Sketchup and Inkscape and getting it laser cut in acrylic...Function is of course better than form!

The tombstone rover chassis!

I then designed a servo motor bracket in Inkscape using tabbed box maker and had that laser cut in acrylic.  The inkscape image is shown below.  If people are interested I can share the design files....

Continuous rotation servo mount
Here is the assembled servo mount in bright yellow acrylic!



The whole thing bolts together with M3 machine screws, nuts and washers.  I then added the caster wheel I bought from Clas Ohlson...Next I used a 3d printer - a mendle90 to print the wheels.  The designs are from thingiverse and I just searched for wheels for servo motors and selected ones that looked about right.  I'm not particularly good at mechanical engineering!  When printed they look like this:


Once it was all screwed together and working I powered the arduino from 8x 1.5 V AA batteries so the device was completely wireless.  I used my PC at first to check all was working and then finally the best part - I went on google play and searched for an application which allows me to communicate via my mobile phone's bluetooth to control the rover - Here is the link to a fantastic app which allows this:

Arduino Bluetooth Joystick Lite - By Felipe Porge


The app was loaded and installed and then all that was needed was to pair my phone with the bluetooth HC-06 module which was painless....then the fun begins!

Here is a short video showing the rover in operation - That's all for now people, take care Langster!


No comments :

Post a comment