Line Follower

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 Arduino Uno board
  • 1 Education Shield
  • 1 IR Array
  • 2 continuous rotation servos
  • 4 black jumper wires
  • 8 colored jumper wires
  • 1 9V battery
  • 4 AA batteries
  • 1 AA battery holder
  • 2 power plugs (One without the plug but with two loose wires)
  • Line follower kit
  • 1 metal ball

Instructions

  1. Attach the shield onto the top of the Arduino board.
  2. Attach the wheels on the servos.
  3. Attach one servo on each side of the line follower.
  4. Assemble the ball piece on the middle part of the line follower.
  5. Connect five jumper wires to 5V, GND, IR1, IR2, and IR3 of the IRArray.
  6. Put the jumper wires through the front hole of the middle base and then finish assembling the main body.
  7. Connect the loose wires of the IRArray. 5V to 5V, GND to GND using an extra jumper wire, IR1 to A1, IR2 to A2 and IR3 to A3.
  8. Using 3 jumper wires, connect the left servo. The black wire to GND, the white wire to digital pin 10,  and the red wire to the bread board.
  9. Using 3 jumper wires, connect the right servo. The black wire to GND, the white wire to digital pin 9, and the red wire to the bread board.
  10. Connect the Arduino board to the computer and upload example LineFollower.
  11. Place 4 AA batteries in the battery holder. Using the power plug with loose wires, connect the battery back to the board, black wire to GND and the red wire to the two servos’ power wires on the breadboard. Connect the 9V battery to the Arduino power socket.
  12. Place the electronics on top of the Line Follower and connect the 9V battery with a power plug to the Arduino power socket.

Code

Find the code in File>Examples>EducationShield>Block4-Robots>Projects>LineFollower

How it works

  • The EducationShield and Servo libraries are included.
  • The IRArray and Wheel objects are declared, ir and wheel.
  • In setup() the wheels are initialized.
  • 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.
  • If the motors are not working, see the reference about how to debug servo motors used as wheels.
  • Debug the IRArray, see the IR Array reference.

Experiment further

  • 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.