How To Make Line Follower Car with Speed Control | 6 IR Sensor Arduino Line Following Car


It's easy to make a robot that follows a line or smooth curves, but it becomes challenging to design the line follower robot when its track is complex. But we got you covered. Using 6 sensors and speed control of our car, we'll design our fast and advanced line following robot. 

Before starting on this advanced project make sure you understand How Does An IR Sensor Works and have tried making 2 Sensor Line Follower or 3 Sensor Line Follower.

Hardware Setup

Components Required

  • Arduino UNO
  • Motor Driver L298N
  • 6 x IR Sensors (1 x TCRT5000 & 1 x HX-01)
  • Car Chassis (Base & Motors & Wheel & Caster Wheel)
  • 12V Battery Pack
  • Jumper Cables

Car Chassis Assembly



Circuit Diagram


Note: For speed control remove the tiny black jumper covering ENA and ENB pins on L298N. Make sure they are covered when not using the speed control, else project may not work.

Software Setup

Reading Analog Values of IR Sensor

In our previous projects, we read digital values from IR Sensor - 0 for White and 1 for Black. This time we'll use analog output of IR sensor. Our first step will be to read the analog output of the IR Sensor on a black and white surface and then find a threshold value such that for either side of that threshold value either black or white surface values are read. 

Note: The analog output values may vary for different sensors being used. For greater understanding refer to the video at the end.

Circuit Diagram



Code

We note, that for TCRT5000 (5 channel sensor), the output of IR sensor was less than 400 on black surface while greater than 400 on white surface. While for HX-01 (used as a front sensor), the output was greater than 400 on black surface while less than 400 on white surface. These results are later used in the programming of line following car.

Programming Logic of Line Follower Robot



Adding Speed Control

For speed control, connect ENA and ENB pins of L298N to Digital I/O pins of Arduino UNO marked with PWM (~). The only addition in software would be to declare those pins, set them up in OUTPUT pinMode in void set up, and add the following lines of code at the start of void loop:

    analogWrite(ENA, <speed>);

    analogWrite(ENB, <speed>);

 Where the value speed can take is between 0-255, 0 being stop, and 255 being highest achievable speed. 

Code

Demo

Let's now see our line following car following the advanced track smoothly. 



Now it's your turn to make a Line follower robot with speed control. For any problem that you may face, Team DeepLift is always there to help :) 

Comments

Popular Posts

How To Make Line Follower Using Three IR Sensor | Arduino Line Following Car