Introduction: The Versatile Arduino Robot

About: I'm Ben. I'm currently weaseling my way through undergrad at MIT where I'm majoring in physics and nuclear science and engineering. I made this account back in middle school (hence the cheesy name), and I real…

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.

Arduino Challenge

Participated in the
Arduino Challenge