-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLine_Follower.ino
More file actions
52 lines (51 loc) · 1.57 KB
/
Copy pathLine_Follower.ino
File metadata and controls
52 lines (51 loc) · 1.57 KB
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
// Please read the description file for better understanding.
int acleft4 = 4; // ac = anticlockwise
int cleft5 = 5; // c = clockwise
int acright6 = 6;
int cright7 = 7;
int pwm = 3; // Use only if you want to control the speed of dc motor
int pwm1 = 11; // Use only if you want to control the speed of dc motor
void setup() {
// put your setup code here, to run once:
//Serial.begin(9600); //Use when calibrating according to your surroundings
pinMode(acleft4, 1);
pinMode(cleft5, 1);
pinMode(acright6, 1);
pinMode(cright7, 1);
pinMode(A0,0);
pinMode(A1,0);
}
void loop() {
// put your main code here, to run repeatedly:
int x = analogRead(A0);
int y = analogRead(A1);
/*Serial.println("Value of sensor right"); //Use when calibrating according to your surroundings
Serial.println(x);
Serial.println("Value of sensor left");
Serial.println(y);*/
analogWrite(pwm,70); // Use only if you want to control the speed of dc motor
analogWrite(pwm1,70); // Use only if you want to control the speed of dc motor
if (x > 500)
{
digitalWrite(cright7, 1); // moving Right
digitalWrite(acright6, 0);
digitalWrite(cleft5, 0);
digitalWrite(acleft4, 1);
delay(650);
}
else if (y > 500)
{
digitalWrite(cright7, 0); // moving Left
digitalWrite(acright6, 1);
digitalWrite(cleft5, 1);
digitalWrite(acleft4, 0);
delay(650);
}
else
{
digitalWrite(cright7, 1); // moving Foward
digitalWrite(acright6, 0);
digitalWrite(cleft5, 1);
digitalWrite(acleft4, 0);
}
}