Line Follower Arduino - ForbiddenBit
Line Follower Arduino - ForbiddenBit
Line Follower Arduino - ForbiddenBit
Recent Posts
Arduino Music
iR Car Control Arduino
DS18B20 Arduino Example
NE555 Projects
Propeller Led Clock Arduino
Forbidden Bit
845 seguidores
Arduino Projects
YouTube 999+
Line Follower is a very simple robot ideal for beginner
electronics. The robot travels along the line using the iR sensor. The
sensor has two diodes, one diode sends infrared light, the other
diode receives the reflected light from the surface. When the infrared
rays fall on the white surface, they are reflected back. When infrared
light fall a black surface, the light is absorbed by the black surface and
no rays are reflected back, so the photodiode does not receive any
light. The sensor measures the amount of reflected light and sends
the value to the arduino. There is a potentiometer on the sensor, with
which we can adjust the sensitivity of the sensor.
https://forbiddenbit.com/en/arduino-projects/line-flower-arduino/ 1/8
21/11/22, 17:31 Line Follower Arduino – ForbiddenBit
Arduino now has to make decisions based on the data received from
the sensor, until the sensor detects no black line it will go forward. If
the left sensor detects a black line, the robot turns right, and if the
right sensor detects a black line, it turns left. The robot will stop when
both sensors detect a black line at the same time.
Schema
Now before turning on the power, check that you have connected
everything correctly. Copy the program code and upload it to your
arduino, then turn on the serial monitor (in Arduino IDE -> Tools ->
Serial Monitor). Place your robot on the black line and set the
potentiometer so that the sensor value shows ≈ 1023, and on the
white surface ≈ 33.
https://forbiddenbit.com/en/arduino-projects/line-flower-arduino/ 3/8
21/11/22, 17:31 Line Follower Arduino – ForbiddenBit
Line_Flower.ino_ Download
1 /*
2 * Forbiddenbit.com
3 */
4
5 void setup() {
6 Serial.begin(9600);
7
8 pinMode(A0, INPUT); // initialize Right sensor as an inut
9 pinMode(A1, INPUT); // initialize Left sensor as as input
10
11 }
12
13 void loop() {
14
15 int LEFT_SENSOR = analogRead(A0);
16 int RIGHT_SENSOR = analogRead(A1);
17
18 Serial.println("right:");
19 Serial.println(RIGHT_SENSOR);
20 Serial.println("left:");
21 Serial.println(LEFT_SENSOR);
22
23 delay(300);
24 }
https://forbiddenbit.com/en/arduino-projects/line-flower-arduino/ 5/8
21/11/22, 17:31 Line Follower Arduino – ForbiddenBit
Download the latest version of the library for L293D Shield from
https://github.com/adafruit/Adafruit-Motor-Shield-library.
To add a library Go to Tools -> Inclde Library -> Add .ZIP Library. And
select Adafruit-Motor-Shield-library-master.zip.
Adafruit-Motor-Shield-library-master Download
ARDUINO_LINE_FOLLOWING_CAR.ino_ Download
1 /*
2 * Forbiddenbit.com
3 */
4
5 #define Motor11 7
6 #define Motor12 6
7 #define Motor21 9
8 #define Motor22 8
9 #define PWMmotor1 5
10 #define PWMmotor2 10
11
12 int valuePWM1=120; // speed motor 1
13 int valuePWM2=150; // speed motor 2
14
15 void setup() {
16
17 pinMode(Motor11,OUTPUT);
18 pinMode(Motor12,OUTPUT);
19 pinMode(Motor21,OUTPUT);
20 pinMode(Motor22,OUTPUT);
21 pinMode(PWMmotor1,OUTPUT);
22 pinMode(PWMmotor2,OUTPUT);
23
24 pinMode(A0, INPUT); // initialize Right sensor as an inut
25 pinMode(A1, INPUT); // initialize Left sensor as as input
26
27 }
28
29 void loop() {
30
31 int LEFT_SENSOR = analogRead(A0);
32 int RIGHT_SENSOR = analogRead(A1);
33
34 if(RIGHT_SENSOR<36 && LEFT_SENSOR<36) //FORWARD
35 {
36 digitalWrite(Motor11, HIGH);
37 digitalWrite(Motor12, LOW);
38 digitalWrite(Motor21, HIGH);
39 digitalWrite(Motor22, LOW);
40
41
42 }
analogWrite(PWMmotor1, valuePWM1);
analogWrite(PWMmotor2, valuePWM1);
https://forbiddenbit.com/en/arduino-projects/line-flower-arduino/ 6/8
21/11/22, 17:31 Line Follower Arduino – ForbiddenBit
43
44 else if(RIGHT_SENSOR>36 && LEFT_SENSOR<36) //LEFT
45
{ ARDUINO ELECTRONICS COURSES CALCULATOR GENERATOR
46 digitalWrite(Motor11, LOW);
47 digitalWrite(Motor12, HIGH);
48 digitalWrite(Motor21, HIGH);
49 digitalWrite(Motor22, LOW);
50 analogWrite(PWMmotor1, valuePWM2);
51 analogWrite(PWMmotor2, valuePWM2);
52 }
53
54 else if(RIGHT_SENSOR<36 && LEFT_SENSOR>35) //RIGHT
55 {
56 digitalWrite(Motor11, HIGH);
57 digitalWrite(Motor12, LOW);
58 digitalWrite(Motor21, LOW);
59 digitalWrite(Motor22, HIGH);
60 analogWrite(PWMmotor1, valuePWM2);
61 analogWrite(PWMmotor2, valuePWM2);
62 }
63
64 else if(RIGHT_SENSOR>35 && LEFT_SENSOR>35) //BACK
65 {
66 digitalWrite(Motor11, LOW);
67 digitalWrite(Motor12, LOW);
68 digitalWrite(Motor21, LOW);
69 digitalWrite(Motor22, LOW);
70 delay(10000);
71 }
72 }
Leave a Reply
You must be logged in to post a comment.
https://forbiddenbit.com/en/arduino-projects/line-flower-arduino/ 7/8
21/11/22, 17:31 Line Follower Arduino – ForbiddenBit
https://forbiddenbit.com/en/arduino-projects/line-flower-arduino/ 8/8