0% found this document useful (0 votes)
86 views

Line Follower Arduino - ForbiddenBit

This document describes how to build a line follower robot using an Arduino. It provides two versions, one using an L298N motor shield and the other using an L293D motor shield. The robot uses an infrared sensor to detect a black line on the surface and make decisions to follow the line by turning or moving forward. It also provides the code to control the robot's movement and read sensor values to allow it to trace the black line.

Uploaded by

geloandima1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

Line Follower Arduino - ForbiddenBit

This document describes how to build a line follower robot using an Arduino. It provides two versions, one using an L298N motor shield and the other using an L293D motor shield. The robot uses an infrared sensor to detect a black line on the surface and make decisions to follow the line by turning or moving forward. It also provides the code to control the robot's movement and read sensor values to allow it to trace the black line.

Uploaded by

geloandima1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

21/11/22, 17:31 Line Follower Arduino – ForbiddenBit

 ARDUINO  ELECTRONICS COURSES  CALCULATOR  GENERATOR 

Recent Posts

Arduino Music
iR Car Control Arduino
DS18B20 Arduino Example
NE555 Projects
Propeller Led Clock Arduino

Forbidden Bit
845 seguidores

Arduino Projects

Line Follower Arduino Seguir página

 24/02/2020  Jarek  0 Comments  Arduino, ir, l298d, line flower, robot,


sensor Forbidden Bit

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  ELECTRONICS COURSES  CALCULATOR  GENERATOR 

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.

Version with L298N Shield:

To assemble your robot you need: 


https://forbiddenbit.com/en/arduino-projects/line-flower-arduino/ 2/8
21/11/22, 17:31 Line Follower Arduino – ForbiddenBit

 ARDUINO  ELECTRONICS COURSES  CALCULATOR  GENERATOR 

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

 ARDUINO  ELECTRONICS COURSES  CALCULATOR  GENERATOR 

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 }

Copy the code below and upload it to arduino. Have fun


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
21
pinMode(Motor22,OUTPUT);
pinMode(PWMmotor1,OUTPUT); 
22 pinMode(PWMmotor2,OUTPUT);
https://forbiddenbit.com/en/arduino-projects/line-flower-arduino/ 4/8
21/11/22, 17:31 Line Follower Arduino – ForbiddenBit
23
24 pinMode(A0, INPUT); // initialize Right sensor as an inut
25  ARDUINO
pinMode(A1, ELECTRONICS
INPUT); // initialize COURSES
Left sensor 
as as input CALCULATOR  GENERATOR 
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 analogWrite(PWMmotor1, valuePWM1);
41 analogWrite(PWMmotor2, valuePWM1);
42 }
43
44 else if(RIGHT_SENSOR>36 && LEFT_SENSOR<36) //LEFT
45 {
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 }

Line Follower Robot Arduino And L293D Shield


https://forbiddenbit.com/en/arduino-projects/line-flower-arduino/ 5/8
21/11/22, 17:31 Line Follower Arduino – ForbiddenBit

 ARDUINO  ELECTRONICS COURSES  CALCULATOR  GENERATOR 

Version with L293D Shield:

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 }

← 0.96″ OLED i2c Oscilloscope 0.96″ Arduino →

 You May Also Like

Joystick Control Digispark made Flappy Bird Game


Arduino Car and at home Arduino
NRF24L01  10/01/2020  0  10/01/2020  0
 22/03/2020

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

Copyright © 2022 ForbiddenBit. All rights reserved.


Theme: 
ColorMagARDUINO
by ThemeGrill.
 Powered by WordPress.
ELECTRONICS COURSES  CALCULATOR  GENERATOR 


https://forbiddenbit.com/en/arduino-projects/line-flower-arduino/ 8/8

You might also like