-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline_follower.ino
52 lines (42 loc) · 956 Bytes
/
line_follower.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
/* ADAFRUIT Motor shield has been used for controlling the DC motors
CONNECTIONS/ PIN LAYOUT---
Left Motor - M4
Right Motor - M3
Right IR Sensor - A5
Left IR Sensor - A4
***** IR sensors need to be properly calibrated *****
*/
#include <AFMotor.h>
AF_DCMotor left(4);
AF_DCMotor right(3);
void setup() {
pinMode(A5, INPUT); //rightir
pinMode(A4, INPUT); //leftir
Serial.begin(9600);
}
void loop() {
left.setSpeed(255);
right.setSpeed(255);
if((analogRead(A5)<945)&&(analogRead(A4)<945))
{
left.run(FORWARD);
right.run(FORWARD);
}
if((analogRead(A4)>945)&&(analogRead(A5)<945))
{
left.run(RELEASE);
right.run(FORWARD);
delay(100);
}
if((analogRead(A5)>945)&&(analogRead(A4)<945))
{
right.run(RELEASE);
left.run(FORWARD);
delay(100);
}
if((analogRead(A5)>945)&&(analogRead(A4)>945))
{
left.run(RELEASE);
right.run(RELEASE);
}
}