$USD
  • EUR€
  • £GBP
  • $USD
TUTORIALS Robotics

How to Make an Android Controlled Robot

DFRobot Jul 29 2015 372
Based on DFRobot 4x4 robot.  
Controlled using Android phone via bluetooth.  
As well as being remote controlled by a phone, also has a mode that will search out light.
 Because every robot needs flashing lights have LEDs that flash and have no real purpose. Includes a claw on a pan and tilt that is also controlled by the Android phone.

Using three micro-controllers connected via i2c:
- Romeo by DFRobot came with the robot kit, used for driving the wheels and comms.
- Arduino for display (LED's and LCD display)
- Arduino for controlling the claw.

This is one of those projects that seems never to be complete, the more you work on it the more you think about how you can extend it or make it do more.


Step 1: Assemble Kit platform

  DFRobot   DFRobot
DFRobot
Start with the DFRobot 4WD Arduino Powered Mobile Platform with Romeo.  https://www.dfrobot.com/index.php?route=product/product&path=37_69&product_id=116 .  I managed to find this and most of the other pieces from https://littlebirdelectronics.com/ if you are not in Australia I am sure there are plenty of web sites you could pick them up from.

Unpack and assemble the base kit.  There are a few choices to make.  I chose to put the wheel encoders on the rear wheels, although it probably does not matter.  I also found the 45mm standoffs to be very excessive, I have some 5mm standoffs so I used them.  The longer standoffs will come in handy later.

I plugged the left encoders into digital pin 2 on the Romeo, and the right encoder into digital pin 3.  The reason being that is where the interrupts are connected on an Arduino.

Next to the power connectors connect the "VIN=M_VIN" this will save you connecting a second power supply.

Ensure all the jumpers are set so that the Romeo uses pins 4, 5, 6 and 7.

The first thing I noticed with this is the battery pack has 2 issues:
1 - When the batteries get half flat they don't have enough grunt to be useful, making 1.2v from rechargeable batteries completely useless.
2 - Changing the batteries is a pain in the neck.

To overcome this I utilised a battery pack that takes 6 AA batteries that I had from a previous project.  This can be mounted behind the rear wheels and held in place with Velcro.


Step 2: Sensors and mounts
DFRobot   DFRobot

The DFRobot kit did come with sensor mounts, however there was not many of them and I was unsure how to use them.  So I decided to make my own.  At Bunnings (large warehouse hardware store here in Australia) I found aluminium angle bends, they came in 1 meter (40") lengths with 10mm (3/8") edges.

I bought 1 length, and using a hack saw chopped it into 25mm (1") lengths, using the sensor mounts that came with the kit as a guide.  Still using the kit mounts as I guide I drilled three holes that will take a M3 bolt.  Then used a grinder and a file to take of the sharp edges.  I made a whole heap of these for future use, however thus far I have only needed 8 for this project.

I bought 2 distance sensor - https://www.pololu.com/catalog/product/1134 .  Using two of the mounting brackets I made and some double sided tape I attached them to the from of the robot, then connected them to digital pin 11 (left) and digital pin 10 (right).  These sensors will allow us to stop the robot running into things, it will also enable us to make the phone vibrate when we get close to things.

Then bought 4 protoboards - https://www.sparkfun.com/products/8886 , 4 X orange LEDs, 4 X 330 Ohm resistors, 4 X 10K Ohm resistors and 4 X light dependant resistors and some header pin outs to make a 4 boards that have a combo of LED and a light sensor.  Originally I used double sided tape to mount these on my mounting brackets, but they kept falling off so I decided to use silicon to stick them on.  Really hot glue might have been a better option, but I don't have any.

The LEDs are just for show and we will come to them later, the light sensors are so we can put the robot in light sensing mode and it will search out light.  So they should be mounted on the sides, as far forward and back and forward as possible.  I also bent the light resistors so they faced out.


Step 3: Romeo shield

Next I needed to make a protoshield, so I got myself a five pack from Freetronics - https://www.freetronics.com/products/protoshield-basic
Note you will still need headers, and optionally capacitor, LED and resistor.

For connecting to the Android phone so we need to add bluetooth, I got one of these - https://www.sparkfun.com/products/582 .  This by defaults waits a long time at start up, this can be changed, and I suggest you do, read the doco on the product you get to find out how.

When the bluetooth is connected to pins 0 and 1 it gets in the way and prevents you programming the Arduino.  The answer to this was to connect the bluetooth power to one of the digital out pins, as the digital pins on a Arduino cannot supply enough amps to power the bluetooth I used a PNP transister as a switch that will turn the bluetooth on and off using the digital pin out.  For this I chose pin 12.

I wanted to know how much charge was left in the battery, so I used a basic voltage divider circuit and analogue pin 0 to to find out how many volts up to 10V the batteries are putting out.  You need two 10K Ohm resisters, put the resisters in series between VIN and GND, connect digital pin 0 to between the two resisters, this will give you a voltage reading up to 5 volts.  Simply double the value and you will have how many volts on the VIN. Alkaline batteries will give almost 1.7 volts when brand new and 1.1 when they are flat, the maths is pretty simple to calculate how much is left in the battery.

I thought while I am checking the volts I might as well check the amps, so I found https://www.pololu.com/catalog/product/1185 and connected it to analogue pin 1.

Lastly I wanted the robot to have the potential to have different modes, to switch between modes I needed a button that when pressed will cycle through the options.  The Romeo does have 7 buttons connected to the analogue pins, however I have used all of the analogue pins for other things, so I needed to add another button to digital pin 8.


Step 4: The upper platform
DFRobot
Picture of The upper platform
I needed another 2 Arduino's to be mounted somewhere on the robot.  I found a small sheet of aluminium in a clearance bin at Dick Smith.  I needed to cut it down in size with a jigsaw.  I then marked and drilled enough holes to mount it, and to mount 2 Arduino's on top.

I would have mounted with 5mm standoff brackets, like I did with the microcontroller on the robot base.  However I run out of them, what I did have was a plastic chopping board I picked up from the Reject shop.  I heard these were great for building robots, so I thought I should give it a go.

Before you mount the upper platform I suggest you connect some jumpers to VCC, Gnd, A5 and A6, because they will be a lot harder to plug in later.


Step 5: The Lights

  DFRobot   DFRobot

DFRobot

There was absolutely no need for it, but I felt the robot needed some lights that will flash.  We have already mounted 4 of them with the light sensor, however we have not wired them up yet.  Also Cylons have them, KITT have them, so I figured I also needed red lights moving from side to side.

This is simply 10 X red LEDs and 10 X 330 Ohm resistors.

Now we get another one of the protoshields we used earlier and mounted two 74HC595 chips on it.  Refer to the Arduino tutorial for the circuit https://arduino.cc/en/Tutorial/ShiftOut .  I used digital pin 11 for ST_CP (latch pin), pin 12 for CH_CP (clock pin) with data on pin 2.  I also set aside pin 3 for future expansion it could be used on a second set of 74HC595 chips if needed in the future.

Into the first chip connect the LEDs on the light sensor protoshield.  Left front is pin 0, right front is pin 1, left back is pin 2, right back is pin 3.  Pin 6 and 7 of the first chip goes to two of the red LEDs along with the 8 pins of the second chip.

Lights were fun, but seeing what is going on a LCD screen also comes in handy from time to time.  One of my work mates gave me a box of old stuff he was no longer using, in it was a 4x20 LCD display (Thanks Sebastian).  Using the circuit at the Arduino tutorial I built another protoshield - https://arduino.cc/en/Tutorial/LiquidCrystal .

These boards get piggybacked on top of each other and placed on the one Arduino.


Step 6: The claw
DFRobot   DFRobot     DFRobot DFRobot
  Looking at the large square hole in the front of the robot, you have to ask yourself what goes here.  The answer is https://www.dfrobot.com/index.php?route=product/product&path=46&product_id=146 .  (Thanks to Maddy at LittleBird how went to a bit of trouble to get me one of these https://littlebirdelectronics.com/ )

Once the pan and tilt kit is in, it needs to have something attached to it.  There is only one possibility - https://www.sparkfun.com/products/10332

Now you can probably guess what the last Arduino is for.  So time for another protoshield, this time one that I already had lying around with a mini breadboard on top.

Only catch here to be aware of is the servos draw too much power to run of the Arduino 5V VCC power source.  The answer is to use the VIN pin on the Arduino and put it through a 7805 voltage regulator.

I wish somebody had told me how to put the tilt and pan kit together with the claw, I ended up doing it several times before I worked out how to do it.  So here are the important steps in order to avoid rework.
- Put the server into the robot
- Assemble the tilt and pan kit without the servo
- Attach the claw with its servo to the tilt an pan kit
- Attach the tilt an pan to the servo on the robot
- Insert the final servo.

The other big hint is ensure the servo has the full range of motion you wish it to have as you place each servo.  Note you may have to tweak the code to find the centre position of each servo once assembled.

I connected pan to digital pin 9, tilt to 10, claw open and close to 11.


Step 7: Final steps

The three Arduinos need to be connected together.  Ensure the VIN, VCC, GND, A4 and A5 pins are linked to their respective pins on all the Arduino boards.  The first three probably make sense without much explanation, the A4 and A5 are because the boards communicate using i2c which needs these two pins to be connected.

The three boards require their own software:
- the Romeo board gets loaded with the botCntrl2 sketch
- the Arduino that controls the LEDs and LCD gets loaded with botDisplay3 sketch
- the Arduino connected to the pan, tilt and claw gets loaded with the clawControl sketch

To control it all from your mobile phone, you need an Android 2.2 device with accelerometer and bluetooth, and load the botControl application.  To compile this up you will need to set up your development environment by following the instructions on the Android development web site https://developer.android.com/sdk/index.html .  For those not brave enough, the .apk file is included in the bin directory, load this to your phone and run it, it will install the app for you.

To set up you phone after you install the software, on the phone you will need to pair the bluetooth device,  that will be in the phone settings.  Start the app, press the menu button and choose settings, you will need to set which bluetooth device you are connecting to.  You only need to do this once.

Once the app is set up, there is a connect option available when you press the menu.  On screen you should have a button that will toggle between go and hold, and a button that will toggle between controlling the wheels and controlling the claw, plus some buttons to open and close the claw.  Tilt the phone back and forward to move back and forward or control the tilt of the claw.  Tilt the phone phone left and right to move the robot left or right or the pan the claw.

BotControl1.zip
BotCntrl2.zip
botCommon.zip
botDisplay3.zip
clawControl.zip


Step 8: The future

There seems to be always something else I want to add to this robot.  Currently the things I would like to do are:
- Controlling with a wii nunchuck would allow moving robot and claw at the same time.
- Instead of dedicating full Arduino boards I could mount just AtMega328P microcontollers and save a lot of space.
- I would love to put a camera on it (both normal camera and infra-red camera), don't know how as Arduino is not powerful enough to drive a camera, and the bluetooth probably isn't quick enough either.
- There really needs to be more distance sensors on the front as it is easy to miss things that are between the sensors.
- The software on the phone has been written so that it should be easily converted to run from a PC.  Would like to do this, however still thinking about the best way to do the user interface.

 
REVIEW