├── .gitattributes
├── Line_Following_robot.ino
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/Line_Following_robot.ino:
--------------------------------------------------------------------------------
1 | const int lMotFwd=9; // connection on pin 9 left motor forward
2 | const int rMotFwd=10; //connection on pin 10 right motor forward
3 | const int lMotRev=11; //connection on pin 11 left motor reverse
4 | const int rMotRev=12; //connection on pin 12 right motor reverse
5 | const int onblack= 300; // reading for black line from sensor is less than this
6 | const int onWhite= 700; // reading for white line is greater than this
7 |
8 | void setup() {
9 |
10 | Serial.begin(9600);
11 |
12 | // pinMode(A0,INPUT);
13 | pinMode(A1,INPUT); //extreme left sensor
14 | pinMode(A2,INPUT); //left
15 | pinMode(A3,INPUT); // middle sensor
16 | pinMode(A4,INPUT); // right
17 | pinMode(A5,INPUT); // extreme right sensor
18 |
19 | pinMode(lMotFwd,OUTPUT);
20 | pinMode(rMotFwd,OUTPUT);
21 | pinMode(lMotRev,OUTPUT);
22 | pinMode(rMotRev,OUTPUT);
23 |
24 |
25 |
26 | }
27 |
28 |
29 | bool isOnBlack(int sensor){
30 |
31 | if( sensor<=onblack)
32 | return true;
33 | else
34 | return false;
35 | }
36 |
37 |
38 | bool isOnWhite(int sensor){
39 | if(sensor>=onWhite)
40 | return true;
41 | else
42 | return false;
43 | }
44 |
45 |
46 |
47 |
48 | void moveForward()
49 | {
50 | digitalWrite(lMotFwd,HIGH);
51 | digitalWrite(rMotFwd,HIGH);
52 |
53 | digitalWrite(rMotRev,LOW);
54 | digitalWrite(lMotRev,LOW);
55 |
56 | }
57 |
58 | void turnLeft()
59 | {
60 | digitalWrite(lMotFwd,LOW);
61 | digitalWrite(rMotFwd,HIGH);
62 |
63 |
64 | digitalWrite(rMotRev,LOW);
65 | digitalWrite(lMotRev,LOW);
66 | }
67 |
68 |
69 | void turnRight()
70 | {
71 | digitalWrite(lMotFwd,HIGH);
72 | digitalWrite(rMotFwd,LOW);
73 |
74 | digitalWrite(rMotRev,LOW);
75 | digitalWrite(lMotRev,LOW);
76 | }
77 |
78 | void turnCircle()
79 | {
80 | digitalWrite(lMotFwd,LOW);
81 | digitalWrite(rMotRev,LOW);
82 | digitalWrite(lMotRev,HIGH);
83 | digitalWrite(rMotFwd,HIGH);
84 | }
85 |
86 | void Stop()
87 | {
88 |
89 | digitalWrite(lMotFwd,LOW);
90 | digitalWrite(rMotFwd,LOW);
91 | digitalWrite(lMotRev,LOW);
92 | digitalWrite(rMotRev,LOW);
93 |
94 | }
95 |
96 | void loop() {
97 | // put your main code here, to run repeatedly:
98 | int sensor1=analogRead(A1);//sensor1 Extreme Left
99 | int sensor2=analogRead(A2);//sensor2
100 | int sensor3=analogRead(A3);//sensor3 middle
101 | int sensor4=analogRead(A4);//sensor4
102 | int sensor5=analogRead(A5);//sensor5 Extreme right
103 | Serial.print("extreme Left: ");
104 | Serial.print(sensor1);
105 | Serial.print("\t lower left: ");
106 | Serial.print(sensor2);
107 | Serial.print("\t middle: ");
108 | Serial.print(sensor3);
109 | Serial.print("\t lowerRight: ");
110 | Serial.print(sensor4);
111 | Serial.print("\t Extreme Right: ");
112 | Serial.println(sensor5);
113 |
114 |
115 | if( isOnBlack(sensor1)){
116 | turnLeft();
117 | }else{
118 |
119 | if(isOnBlack(sensor3)&&isOnWhite(sensor1)){
120 | moveForward();
121 | }else
122 |
123 | if( isOnWhite(sensor1)&& isOnWhite(sensor3)&& isOnBlack(sensor5) ){
124 | turnRight();
125 | }else
126 |
127 | if(isOnBlack(sensor2)){
128 | turnLeft();
129 | }else
130 | if(isOnBlack(sensor4)){
131 | turnRight();
132 | }else
133 | if( isOnWhite(sensor1) && isOnWhite(sensor2) && isOnWhite(sensor3) && isOnWhite(sensor4) && isOnWhite(sensor5) ){
134 | turnCircle(); // replace with left if gap is present
135 | }
136 |
137 |
138 | }
139 |
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Line Following Robot
2 | 
3 | 
4 | 
5 | Line follower is an autonomous robot which follows either black line in white are or white line in black area. Robot must be able to detect particular line and keep following it.
6 |
7 | # LFR
8 |