The Versatile Arduino Robot

28K13019

Intro: The Versatile Arduino Robot

This is my first arduino robot, and I am quite happy with the outcome. What I came up with is a robot that with modifications can do just about anything in the realm of small arduino robots. The electronics are very simple. You only need an H bridge, and a simple setup for the sensor that you are using (in this case the QRD-1114 infrared reflective sensor). The chassis is also very simple. implementing the track and wheel set from Tamiya (this worked quite well with the homemade chassis), and is made from materials that are cheap, and easy to come by. If you follow this instructable, you should end up with a small robot that is capable of being configured to avoid obstacles, follow lines, and stay on a table top using the arduino microcontroller.

     If you like the instructable, please vote for it in the arduino challenge. 

STEP 1: Materials

This robot can be configured in many different ways, so the materials you will need may vary. Here is a list of parts that I ended up using.

for the chassis:
-two pieces of peg board about 6cm by 13.5 cm
-assortment of scrap wood
-Tamiya track and wheel set (get from amazon)
-screws

for electronics:
-8x 2222A NPN transistors (you can avoid the use of transistors with the use of H bridge ICs such as the 298)
-8x 1k resistors
-perfboard
-wire
-QRD-1114 
-10k resistor 
-68ohm resistor 
-type M male power jack
-Tamiya twin motor and gear box

software:
-arduino uno (any other arduino board should work)

STEP 2: Building the Chassis

I made the chassis based on the universal plate sold by Tamiya. basically you need a piece of pegboard big thin enough that there is enough of the shaft coming out from the side of your gearbox that the tracks won't get caught on the board, that is long enough that you can fit all of your hardware on it. I started by cutting a piece of pegboard about 6 cm wide (the measurement you need if using the twin motor and gear box from tamiya) by 13 cm long. I then put two pieces of wood measuring 7cm by 1.5 cm by1.5 cm on the bottom of the pegboard with equal space on either end of the wood. I then attached two thin pieces of wood to the top of the pegboard on the front of the robot. I drilled a hole on equal distances on both pieces of wood to hold the front axle of the track and wheels. I attached two smaller wheels to the bottom pieces of wood using the partially threaded screws included in the track and wheel set.   

STEP 3: Motors and Gearbox

I used the twin motor and gear box from tamiya. I am not going to explain construction, because if you buy it there is instructions included. Be sure that you assemble it as the c type or the low speed type. The c type has a gear ratio of 203:1 as opposed to the  a and b types which have a gear ratio of 58:1. The c type is the only one with enough torque for our purposes. If you are using a different gear box, assemble it with the highest gear ratio  you can. when attaching to the chassis, line up the shafts with the end of the chassis, and screw it on.

note: One of the motors the gear box came with did not work. it would begin to stain and move very slowly after moving for a few minutes. I replaced it with a geared motor I got from radio shack for much better results.

STEP 4: Building the H Bridge.

To control the motors, you need a setup called an h bridge. You probably know that when you connect the terminals on the motors to the reversed end of the battery, it turns in the opposite direction. using switches you can switch the polarity of each terminal of the motor, and change the direction. To allow the arduino to make the switches, you need to use an electronic switch. In this case, we will use transistors, but you can also use relays, or even better, a H bridge IC chip. You will need four transistors for each motor. one transistor for each polarity on both terminals. What I did, is I connected two transistor bases together, for each direction the motor would spin, and that would be connected to the output pins on the arduino. I found that for the negative connection, you had to connect the emitter of the NPN transistor to ground, and then the collector the the terminal of the motor, and for the positive connection, you had to connect the collector to power, and the emitter to the motor terminal. 

Note: the transistors I used had an Ic max of about 500 ma. The transistors got very hot unless I connected the base of the transistor to the arduino through a 1k resistor. If you choose to make a H bridge with transistors you may want to get a transistor with a higher current tolerance, or maybe even power transistors. 

STEP 5: Mounting the Electronics

to mount the electronics, I screwed another small piece of pegboard to the pieces of would used to hold the front axle. I hot glued the H bridge down, and velcroed  the arduino so I could remove it easily for use in other projects.

STEP 6: Setup the Sensor

To get it to work with the arduino, you need to setup the QRD in a specific way. If you saw my instructable on servos, you will setup the qrd in the same way. just follow the schematic.

STEP 7: Obstacle Avoiding


Finally, the actual building part is finished (once you attach your sensor). Make sure your sensor is held by the its wires several cm away from the chassis of the robot. When an object was in front of the QRD, the value from the analog pin got smaller. this works out fine for our purposes because we can using this very easily in the software. copy paste the following code to your IDE, compile and upload. 


//This code is for an obstacle avoiding robot with one QRD-1114 reflectived sensor.
//feel free to make changes to improve it or fix problems.
const int Lf = 9;//forwards on left
const int Lb = 10;//backwards on left
const int Rf = 11;//forwards on right
const int Rb = 12; // backwards on right

int val = 0;  //store data from sensor

void setup() {

  pinMode(Lf, OUTPUT); //left motor output
  pinMode(Lb, OUTPUT); //left motor output
  pinMode(Rf, OUTPUT); //right motor output
  pinMode(Rb, OUTPUT); //right motor output

  //analog pins automatically set as input

}

void loop() {

  val = analogRead(0); // reading value of sensor

  if(val < 100){
    digitalWrite(Lf, LOW);// stop going forwards
    digitalWrite(Rf, LOW);//stop going forwards
    digitalWrite(Lb, HIGH);// back away fromn object
    digitalWrite(Rb, HIGH);//back away from object
    delay(2500);
    digitalWrite(Rb, LOW);//turn away from object
    delay(2500);
    digitalWrite(Lb, LOW);// stop moving
  }  else{
    digitalWrite(Lf, HIGH);
    digitalWrite(Rf, HIGH); //go forwards if no object
  }
}

STEP 8: Wire Things Up to the Arduino

Connect the left motor's forward transistors to pin 9, left motor backwards to pin 10, right motor's forwards to pin 11, right motor backwards pin 12. connect power from the H bridge to the 3.3v pin on the arduino, and the H bridge's ground to one of the ground pins. connect the output of the sensor to analog pin 0, the power of the QRD to the 5v pin, and the ground to one of the ground pins. We will keep these connections for all three tasks the robot will be able to perform. 

STEP 9: Make the Robot Into a "table Top Wanderer"

Cliff avoidance is very easy to do with this robot. with obstacle avoiding, the robot moves forward as long as there is nothing in front of it. for cliff avoidance it is the exact opposite. Bend the sensor down so it is facing the ground. In the code it comes down to a very simple change though. simply change the less than sign to a greater than sign, and upload it. just in case, here is the code:

//This code is for an obstacle avoiding robot with one QRD-1114 reflectived sensor.
//feel free to make changes to improve it or fix problems.
const int Lf = 9;//forwards on left
const int Lb = 10;//backwards on left
const int Rf = 11;//forwards on right
const int Rb = 12; // backwards on right

int val = 0;  //store data from sensor

void setup() {

  pinMode(Lf, OUTPUT); //left motor output
  pinMode(Lb, OUTPUT); //left motor output
  pinMode(Rf, OUTPUT); //right motor output
  pinMode(Rb, OUTPUT); //right motor output

  //analog pins automatically set as input

}

void loop() {

  val = analogRead(0); // reading value of sensor

  if(val > 100){
    digitalWrite(Lf, LOW);// stop going forwards
    digitalWrite(Rf, LOW);//stop going forwards
    digitalWrite(Lb, HIGH);// back away fromn object
    digitalWrite(Rb, HIGH);//back away from object
    delay(2500);
    digitalWrite(Rb, LOW);//turn away from object
    delay(2500);
    digitalWrite(Lb, LOW);// stop moving
  }  else{
    digitalWrite(Lf, HIGH);
    digitalWrite(Rf, HIGH); //go forwards if no object
  }
}


using this code, with the sensor bent downwards, you can make your robot able to move around a table on its own without falling off. 

STEP 10: Make a Line Follower

The QRD-1114 was actually designed to be used in line following robots, so it is the perfect sensor for this. keep the sensor bent down wards facing the ground. I made a line on a dry erase board making a line with black electrical tape. use the following code:

//this is the code for line following on an arduino robot using a single
//QRD 1114 infrared reflective sensor. feel free to make improvments, as
//this is a very simple software.
const int left = 9; //left motor
const int right = 11; //right motor
//be sure to connect these pins through transistors.

int val = 0; //store value from sensor

void setup() {
  pinMode(right, OUTPUT);
  pinMode(left, OUTPUT);
}
void loop() {
  val = analogRead(0);

  if(val < 100){
    digitalWrite(right, LOW);
    digitalWrite(left, HIGH); //if the surface is white turn the left motor
                              //on and the right off.
  } else{
    digitalWrite(left, LOW);
    digitalWrite(right, HIGH); // if the surface is black turn the right motor on
                               //and the left motor off.
  }
}


Note:  The robot due to the nature of the code, will move relatively slowly along the line, I don't think you can really make it go much better with only one sensor. The robot will every now and then freeze up while running. When this happens simply nudge the robot in either direction, and it will continue to run.

STEP 11: Finished.

the robot can do three main tasks, and I feel that doing them, the robot has met its full potential. If you experience any trouble while making the robot, leave a comment and I will help you out. Also if you have any ideas for improvements please leave a comment. Good luck and have fun!

P.S. Please vote for this in the arduino challenge, and please rate it. Thank you.

18 Comments

its not pretty clear about the steps to make the robot. Could you please send a step by step algorithm for the wood work and all the connections??

that would be an extremely great help!

What are the specs for the h bridge chip

I didn't use a chip, I made my Own H-bridge with a bunch of PN2222 transistors. They have a 600ma max.

What are the specs for the h bridge chip
hey! I love the project but can you please help me find parts for this?! I really wanna build this

cool project!!!. one of my favorite.

What is the black box with the mini breadboard in the middle called?

Hi I'm new to arduino field.. I saw your Versatile Arduino Robot, it's cool :) .. Can you please explain me how to build the H-bridge and how to connect it to the arduino...
Thanks! The H-bridge is basically two switches on each pole of the motor, so that either pole can connect to either the + or - rail on the board. I posted a schematic, unfortunately it didn't seem to have come out well, but there are plenty out there. The one I used shows switches, but by replacing the switches with transistors you can control the H bridge with the output of the arduino. To build it, You basically just connect the power rail to a pole of the motor through a transistor, and then connect the ground rail to the same pole through another transistor. Do the same for every other pole of the transistor. Connect the base of the transistors to a wire that can go to the arduino. The thing that can be tricky is getting the collector and emitter pins oriented correctly. Remember that the arrow on the transistor schematic symbol shows the direction the positive charge flows. Be sure the circuit is assembled so this happens. You may want to assemble on a breadboard first to make sure you get it right. Also, you could use relays instead of transistors, but the arduino may not be able to drive them directly. There are plenty of tutorials, webpages, and videos about H bridges out there if you are still confused.
can you please explain how to build the h-bridge..
What do you use for a power supply? I have a similar robot powered by 9V, but the motors suck that thing dry in no time
These days I use a 9.6v 1200mAh RC car battery, but it is important to isolate the motor power from the logic power otherwise you could kill your arduino.
They also sell rechargeable Lithium Backpacks for the Arduino uno and mega.
Here's the page for the uno's backpack I hope you like it.


http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_2127566_-1
As long as you're not drawing the power for the motors through the VDD pin of the arduino, (trust me, I already got flamed by people on arduino.com, and it was a accidental short (jumpers crossed) and the 9V wall-wart that ended-up frying the trace on the board).. you might want to make a molex to barrel adapter, and use a 7.2V RC battery.. Plenty of power.. Get the 9.6V RC repair kit, and the 7.2V battery from Radio Shack, as well as the type-M barrel connector. this will give you a way to connect the battery through the H-Bridge board, and add a jumper from it to the arduino. 7.2V will still power the +5V regulator on the arduino without problems..
You should build a 9v power supply for your arduino, it would be easier than using wall power.
Yeah as a matter of fact I made one. One 9v battery didn't work, so I used triple and double A batteries to make a 9v supply. the batteries died really fast though, and at the time I did not have any more triple A batteries so I just used the adapter.