How to Make a Line Follower Using Arduino

877

16

Posted

Introduction: How to Make a Line Follower Using Arduino

If you are getting started with robotics, one of the first project that beginner make includes a line follower. It is a special toy car with property to run along a line which normally is black in color and in contrast with background.

Let's get started.

Step 1: Video

Attached comprehensive video. Please take a look.

Step 2: Major Blocks

We can divide line follower in four major blocks. IR-photodiode sensors, motor driver, arduino nano/code and toy car chassis along with plastic wheels and 6V DC motors. Lets look at these blocks one by one.

Step 3: IR-Photodiode Module (part 1 of 3)

Job of IR-Photodiode sensor in line follower is to detect if it has a black line underneath it. IR Light emitted from IR LED, bounces back from surface underneath to be captured by photodiode. Current through photodiode is proportional to photons it receives and physics says that black color absorbs IR radiations, hence if we have a black line under a photodiode it receives less photons resulting in lesser current compared to if it had reflective surface like white underneath it.

We will convert this current signal into voltage signal that arduino can read up using digitalRead in next step.

Step 4: IR-Photodiode Module (part 2 of 3)

Photodiode's current is passed through a 10 KOhm resistor to create proportional voltage drop, let's call it Vphoto. If there is white surface underneath, photodiode's current goes up and hence Vphoto, on the other hand for black surface both decreases. Vphoto is connected to Non Inverting terminal of LM741 opamp. In this configuration if voltage at Non-Inverting terminal(+) is greater than voltage at Inverting terminal(-), opamp's output is set to HIGH and LOW for other way round. We carefully set voltage at inverting pin to be in-between voltage reading for white and black colors using a potentiometer. On doing so this circuit's output is high for white and low for black color, which is perfect for arduino to read up.

I have labeled attached images in order of above description for better understanding.

Step 5: IR-Photodiode Module (part 3 of 3)

Only one IR-photodiode sensor is not enough for creating a line follower as we won't know the direction of exit to compensate for using motors. Hence I used sensor module containing 6 IR-photodiode circuit shown in attached image. 6 IR-photodiode are place as 3 clusters in a pair of 2. If center cluster reads black and other two reads white , we can keep going forward. If left cluster reads black, we need to turn follower towards left to keep follower on track. Same applies to right cluster.

Step 6: Motor Driver

To move follower I am using two 6V DC motors, which are controlled using L293D motor driver. If motor is connected as shown as highlighted in attached image number 4, setting enable and 1A pin to high along with 2A pin to low moves motor in one direction. To move it in other direction we need to exchange state of 2A and 1A pins. We won't need bidirectional moment as follower always move forward. To turn left we disable left motor while right motor is kept running and vice-versa.

Step 7: Arduino Nano and Code

5V arduino nano running at 16MHz decides whether follower needs to turn right or left. Decisions are made by looking at IR-Photodiode sensor array reading. Attached arduino code governs movement of follower. Following paragraph gives top view of arduino code.

Initially, we declare 6 sensor and 4 motor pins. In setup, we set motor pins to output as default mode is input. In loop, first we read all sensor pins, following that is a chain of if-else statements that decide the movement of follower. Some statements help it move forward. Some statements help it to stop and some allows it to go either left or right.

Go through code and let me know if you face any trouble.

Step 8: Schematic and FINISH.

Finally everything was put together according to attached schematic using few wires and breadboard. So there you have it, a line following toy car.

Thanks for reading.

Hope to see your line follower's image in comments.

Share

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • Gluten Free Challenge

    Gluten Free Challenge
  • Sew Warm Contest 2018

    Sew Warm Contest 2018
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

Comments