Aurdino Line Chaser
Ever wanted to make a robotic car that will follow an obstacle course line? Well, now is your chance! Through this instructable, you will learn the basics of how to build a Line Chasing Robot as well as learn the code behind it. At the end of this project, you will have a fully-functioning Line chasing robot that will follow any black line. This project will take anywhere from 45 minutes to 2 hours depending on your experience in engineering. Good luck and have fun!
Gathering Materials
In this project you will need the following items:
- 2 Geared Motors
- 2 Wheels
- 1 Swivel Wheel
- 3 QTI Sensors
- 1 Large Breadboard
- 3 10k Resistors
- standoffs 1 ¼ lg with screws
- 1 L293D Chip
- Set of wires (preferably with different colours)
- 4 AA Batteries
- Aurdino Robot Car base (wooden base can also work)
- Arduino Uno with USB cable
- A computer capable of running Aurdino software
- Screws and Phillips screwdriver
- Soldering kit
- Electrical Tape
- Battery Pack
Most of these items are relatively cheap and are easily purchasable from online tech stores or eBay. Parts such as Aurdino Robot Car base can be replaced with a regular 6x6 inch wooden board.
Soldering and Attaching the Motors
Using a soldering iron, solder a capacitor and wires to the geared motors. Then, wrap an electrical tape to secure the wire and the capacitor over the motor and connect the wheels to the motor. Once this is completed, attach one motor on each side of the car base using screws. Now, screw the swivel onto the lowest part of the car base straight into the middle.
Giving Power to the Breadboard
The circuit we are about to build needs power and it is taken from the Arduino Uno.
Attach a wire from the +5V pin on the Arduino Uno to the positive rail on the Breadboard indicated by a red line. This means that +5V is now available from anywhere on the red line. Attach the negative or GND(Ground) to the blue line on the Breadboard. Now ground is available on the entire blue line.
To make the +5V and GND available on both sides of the Breadboard, use two wires to jump from one end of the Breadboard to the other end. Now, carefully insert the L293D Chip on to the position shown from the picture above.
Giving Power to the Chip
Our next step is to power the chip. Attach 4 wires from pins 1, 8, 9 and 16 of the L293D chip to the +5V positive red rail of the breadboard from both sides of the chip as shown in the diagram to your right. Attach 4 wires from pins 4, 5, 12 and 13 of the L293D chip to the negative or GND(Ground) i.e. blue rail of the breadboard. Our chip now has power and is now grounded. Use the picture above as a reference tool on where to place wires.
Connect the Signal Pins of Arduino to the L293D Chip
Attach a wire from pin 2 of the chip to pin 9 of Arduino Uno and a wire from pin 7 of the chip to pin 10 of Arduino Uno.
Then attach another wire from pin 10 of the chip to pin 11 of Arduino Uno and a wire from pin 15 of the chip to pin 12 of Arduino Uno Our chip is now connected to the Signal pins of the Arduino Uno.
If you are confused on the wire placement, please refer to the diagram above.
Connect the Geared Motors to the L293D Chip
Attach left motor to pins 3 and 6. Attach right motor to pins 11 and 14 of the L293D chip.
Our chip is now connected to the motors. The polarity of the motors doesn’t matter. The direction of rotation can be changed by programming.
Wiring the QTI Sensors
Carefully attach the three different pins (B-W-R) of the QTI Sensor to three different coloured wires (Female to Male).
Connect pins (B) to the negative of the circuit. Connect pins (W) to the positive of the circuit. Attach pin (R) to the 10k resistor which is also connected to the digital pin 2 on the Arduino Board. The other side of the 10K resistor is connected to the + 5V Do the same thing with the second and third QTI sensors and attach the pin (R) to the 10k resistor which is also connected to the digital pin 3 and pin 4 on the Arduino Board. The other side of the 10K resistor is connected to the + 5V
Once this is completed, attach the 1 ¼” standoffs to the base of the car using screws. Make sure each sensor is approximately 5 cm apart.
Clean Up and Organize the Wires
Screw in the QTI sensors to the standoffs. Attach battery pack onto the bottom side of the board using screws. Attach the Arduino as well as the breadboard on to the top side of the base of the car. Tidy up the wires and organize them by taping them neatly. You should be able to access all the wires easily after this process.
Upload Code Onto Arduino
Download the Arduino Software on your computer from Here. Open up the program and create a new sketch by pressing "Ctrl+N". Label this new sketch "Line Chaser". Copy the Code below and paste it into your program. Plug the USB cable into your computer and into your Arduino. Now save the code by pressing "Ctrl+Shift+S" and press the upload button which is shaped as an arrow facing towards the right.
Code:
/*------------------------
Both sides Test for QTI sensors and Motors
----------------------------*/ const int LeftmotorPin1 = 6; // Assign Digital pin 12 of Arduino to Left Motor Pin1 const int LeftmotorPin2 = 9; // Assign Digital pin 11 of Arduino to Left Motor Pin2 const int RightmotorPin3 = 10; // Assign Digital pin 10 of Arduino to Right Motor Pin3 const int RightmotorPin4 = 11; // Assign Digital pin 9 of Arduino to Right Motor Pin4
#define Rightsensor 2 // Assign Digital pin 2 of Arduino to Right QTI Sensor #define Leftsensor 4 // Assign Digital pin 3 of Arduino to Left QTI Sensor #define Middle 3// Assign Digital pin 4 of Arduino to Middle QTI Sensor
byte i;
void setup()
{ // set the sensor pins as an input: pinMode(Leftsensor,INPUT); pinMode( Middle, INPUT); pinMode(Rightsensor,INPUT); // set all the other pins you're using as outputs:
pinMode(LeftmotorPin1, OUTPUT);
pinMode(LeftmotorPin2, OUTPUT); pinMode(RightmotorPin3, OUTPUT);
pinMode(RightmotorPin4, OUTPUT); Serial.begin(9600);
}
void loop()
{
Serial.println(digitalRead(Leftsensor)); Serial.println(digitalRead(Middle)); Serial.println(digitalRead(Rightsensor));
delay(5); // if both sensors are 0, Left motor will turn forward and Right motor will turn forward:
if ((digitalRead(Leftsensor) == LOW && digitalRead(Rightsensor) == LOW) && digitalRead(Middle)==HIGH) { Serial.println("ForwardF"); digitalWrite(LeftmotorPin1, LOW); // set leg 1 of the H-bridge low
digitalWrite(LeftmotorPin2, HIGH); // set leg 2 of the H-bridge high digitalWrite(RightmotorPin3, LOW); // set leg 1 of the H-bridge low
digitalWrite(RightmotorPin4, HIGH); // set leg 2 of the H-bridge high
}
// if Left sensor is 0 and Right sensor is 0 and Middle sensor is 0 Left and Right motor will turn forward at slower speed else if ((digitalRead(Leftsensor) == LOW && digitalRead(Rightsensor)==LOW)&& digitalRead(Middle == LOW)){ Serial.println("ForwardSlow"); digitalWrite(LeftmotorPin1, LOW); // set leg 1 of the H-bridge low
analogWrite(LeftmotorPin2, 200); // set leg 2 of the H-bridge half power digitalWrite(RightmotorPin3, LOW); // set leg 1 of the H-bridge low
analogWrite(RightmotorPin4, 200); // set leg 2 of the H-bridge half power delay(20);
} // if Left sensor is 0 and Right sensor is 1, Left motor will stop and Right motor will turn forward:
else if (digitalRead(Leftsensor) == LOW && digitalRead(Rightsensor) == HIGH){ Serial.println("RIGHT"); digitalWrite(LeftmotorPin1, LOW); // set leg 1 of the H-bridge low
digitalWrite(LeftmotorPin2, LOW); // set leg 2 of the H-bridge low digitalWrite(RightmotorPin3, HIGH); // set leg 1 of the H-bridge low
digitalWrite(RightmotorPin4, LOW); // set leg 2 of the H-bridge high delay(20);
} // if Left sensor is 1 and Right sensor is 0, Left motor will turn forward and Right motor will stop:
else if (digitalRead(Leftsensor) == HIGH && digitalRead(Rightsensor) == LOW){ Serial.println("LEFT"); digitalWrite(LeftmotorPin1, HIGH); // set leg 1 of the H-bridge low
digitalWrite(LeftmotorPin2, LOW); // set leg 2 of the H-bridge low digitalWrite(RightmotorPin3, LOW); // set leg 1 of the H-bridge low
// digitalWrite(RightmotorPin4, LOW); // set leg 2 of the H-bridge high delay(20); } }
Test Out the Line Chaser
Using black electrical tape, make an obstacle course for the Line Chaser. Place 4 AA batteries into the battery pack. Attach the power cable from the battery pack into the Arduino. Turn the switch on and... you're ready!!! Place the Line Chaser onto the obstacle course and let it run!