Coding for Arduino 2
Line Following Robot
Module 4, Project 1: Line Following Robot
Use the following guide to build the CTC-101 Line Following Robot project.
Line Following Robot
The Line Follower does exactly what the name suggests, it follows a line. Make it go where ever you want by showing the way with a 3 cm wide, black line.
Materials
- 1 x control board
- 1 x Education Shield
- 1 x IR Array
- 2 x continuous rotation servo
- 12 x jumper wire
- 1 x 9V battery
- 4 x AA battery
- 1 x AA battery holder
- 2 x power plug (One without the plug that has two loose wires)
- 1 x Line follower kit
- 1 x metal ball
- 2 x wheel
Other materials:
- 1 x black tape
Step 1
Gather all the construction materials for the Line follower.
Step 2
Let’s start building the Line follower!
Step 3
Step 4
Step 5
Step 6
Step 7
Step 8
Step 9
Step 10
Step 11
Step 12
Step 13
Step 14
Step 15
Step 16
Step 17
Step 18
Step 19
Step 20
Step 21
Step 22
Step 23
Step 24
Step 25
Step 26
Step 27
Attach the shield onto the top of the board.
Step 28
Connect 5 loose jumper wires to the IR Array, one to GND, another to VCC and three different colored ones to AN1, AN2 and AN3. These will later be connected to the board so remember what color is connected to what.
Step 29
Step 30
Step 31
Step 32
Step 33
Step 34
Step 35
Step 36
Step 37
Step 38
Connect the loose wires from the IR Array to the board . VCC to power, GND to the breadboard, AN1 to A1, AN2 to A2 and AN3 to A3.
Step 39
Connect GND to the same column in the breadboard as the GND from the IR Array.
Step 40
Using 3 jumper wires, connect the right servo. The black wire to GND, the white wire to digital pin 6, and the red wire to the breadboard.
Step 41
Using 3 jumper wires, connect the left servo. The black wire to GND, the white wire to digital pin 9, and the red wire to the breadboard.
Step 42
Step 43
Check that your wiring is ready and connect the board to the computer.
Step 44
Find the LineFollower program and open it.
/*
* LineFollower
* The Line Follower does exactly what the name suggests,
* it follows a line. Make it go where ever you want by
* showing the way with a 3 cm wide, black line.
*
* (c) 2013-2016 Arduino LLC.
*/
#include <EducationShield.h>
//IRArray(IR1, IR2, IR3)
IRArray ir = IRArray(A1, A2, A3);
//Wheels(left, right)
Wheels wheels=Wheels(6, 9);
void setup(){
wheels.begin();
//Use this line to set the threshold of the IR sensors. The default is 380. If you're using Arduino 101 board, use 530 instead.
//Use test() to check the values of each sensor in loop()
ir.setThreshold(530);
delay(1000);
}
void loop(){
int dir = ir.readLine();
wheels.follow(dir);
}
Step 45
Then upload the program to the board. Remove the USB cable, you will not run this project with it connected.
Step 46
Prepare a 6 V battery with loose wires connector.
Step 47
Using the power plug with loose wires, connect the battery pack to the shield breadboard, black wire to GND and the red wire to the two servos’ power wires.
Step 48
Step 49
Step 50
Step 51
Step 52
Step 53
Step 54
Prepare a 9 V battery with a power plug and put it inside the robot.
Step 55
Connect the 9 V battery to the board’s power socket.
Step 56
Now create some 3 cm wide, black lines, and lets follow it!
How it works
- The EducationShield library is included.
- The IRArray and Wheel objects are declared, ir and wheel.
- In setup() the wheels are initialized.
- The threshold for the IRArray is set with ir.setThreshold(threshold). If you’re using the CTC 101 board the threshold is 530, if you’re using the CTC UNO board its 380.
- The program pauses for 1000 milliseconds.
- In loop(), the variable dir is declared to hold the value read from the IR array using readLine(). The value will be between -100 and 100 and represents the direction the black line is heading.
- wheels is set to follow the value of dir.
- loop() continues to loop.
TROUBLESHOOTING
- Refer to the illustration and double check your connections. Make sure the shield and jumper wires are firmly connected.
LEARN BY DOING
- Print a track and build obstacles for the robot. If the obstacles are too difficult, see if there is a way to improve the robots performance by modifying the wheels.
- Make the robot react in some way when it “sees” only white. That is, when it has lost the track of the black line.
“The day Microsoft makes something that doesn’t suck is probably the day they start making vacuum cleaners.”
— Ernst Jan Plugge