-
Notifications
You must be signed in to change notification settings - Fork 0
/
LineFollower.ino
56 lines (56 loc) · 1.37 KB
/
LineFollower.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//this is arduino code with uses IR sensors
void setup()
{
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
//pinMode(13, OUTPUT);
}
void loop()
{
int a = analogRead(A0);
int b = analogRead(A1);
int c = analogRead(A2);
if (a > 800 && b < 800 && c > 800)
{ analogWrite(5, 250);
analogWrite(6, 0);
analogWrite(10, 250);
analogWrite(11, 0);
Serial.println("Forward condition true");
}
else if (a < 500 && b < 500 && c > 800)
{ analogWrite(5, 0);
analogWrite(6, 250);
analogWrite(10, 250);
analogWrite(11, 0);
Serial.println(" sudden left condition true");
delay(200);
}
else if (a > 800 && b < 800 && c < 800)
{ analogWrite(5, 250);
analogWrite(6, 0);
analogWrite(10, 0);
analogWrite(11, 250);
Serial.println("sudden right condition true");
delay(200);
}
else if (a > 800 && b > 800 && c < 800)
{ analogWrite(5, 200);
analogWrite(6, 0);
analogWrite(10, 0);
analogWrite(11, 0);
Serial.println("slightright condition true");
}
else if (a < 800 && b > 800 && c > 800)
{ analogWrite(5, 0);
analogWrite(6, 0);
analogWrite(10, 200);
analogWrite(11, 0);
Serial.println("slightleft condition true");
}
}