Line Follower (Arduino)
Most of you have heard of the line follower robot. Have you ever thought about how the robot perceives the line? In this topic, I'll tell you about the sensor and I'll talk about the Arduino codes. (Sensor name is QTR-8A)
the QTR-8A doesn't consist of a single sensor. It has 8 sensors on it. This sensor sends infrared (IR) rays across the lower part and hits the lower part, so it comes to the upper part. It generates a value based on the force of the corresponding rays and communicates through the analog inputs of Arduino (or any card). Even in competitions, they can cheat, they can hold a laser on the robot's sensor
The connections are very easy. Since Arduino Uno has 6 analog inputs, we'll consider 6 sensors of the QTR-8A. Numbers 1 to 8 above QTR-8A are the number of sensors.
Sensor numbers = to Arduino analog inputs, Vcc = 5V, Gnd = Gnd, Ledon = to any digital output pins.
For testing purposes, you can use a breadboard and male-to-male jumper wires.
I'll leave a visual here for you:
How Is It Used In Programming?
As I said in the working principle, we'll use the values it provides us. Because IR is reflected in light on a white background, its analog value will be high, and its value on a black background will be low. On the black ground, the value is less than 50. We can accept other situations as else.
if(sensor1<=50) s1 = 1; else s1 = 0; if(sensor2<=50) s2 = 2; else s2 = 0; if(sensor3<=50) s3 = 3; else s3 = 0;
So if the sensor is on the black ground s1=1, if not s1 = 0
By collecting the number of these "s" variables, we can understand which ones are in the white ground and which ones are in the black ground.
int control = s1 + s2 + s3 + s4 + s5 + s6;
If the control variable is 3+4=7, then the black line is under sensors 3 and 4. I mean, straight. If the control variable is 2+3=5, then the black line is under sensors 2 and 3. In this case, the left engine should slow down and the right engine should accelerate. Because the line must be centered. If the control variable is below the sensor 1 and sharp rotation is required. In this case, the left engine should stop and go back if necessary. In addition, the right engine also needs to accelerate. Thanks to small calculations, it follows the line straight, and its deviation decreases.