-
Notifications
You must be signed in to change notification settings - Fork 0
/
Line_Following_Robot_by_Maxhar30.ino
68 lines (54 loc) · 1.33 KB
/
Line_Following_Robot_by_Maxhar30.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
57
58
59
60
61
62
63
64
65
66
67
68
//Motor shields connections with arduino Nano or Uno
int In1 = 7;
int In2 = 8;
int In3 = 4;
int In4 = 3;
int ENA = 5;
int ENB = 6;
int SPEED = 250;
/// Sensors Pins
const int Ir1 = A0;
const int Ir2 = A1;
// Defining values of IR sensors
int Ir1Val = analogRead(Ir1);
int Ir2Val = analogRead(Ir2);
void setup() {
pinMode(In1, OUTPUT);
pinMode(In2, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(In3, OUTPUT);
pinMode(In4, OUTPUT);
pinMode(ENB, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (analogRead(Ir1)<200){
digitalWrite(In1, HIGH);
digitalWrite(In2, LOW);
analogWrite(ENA, SPEED);
}
else {
digitalWrite(In1, LOW);
digitalWrite(In2, HIGH);
analogWrite(ENA, SPEED);
digitalWrite(In3, HIGH);
digitalWrite(In4, LOW);
analogWrite(ENB, SPEED);
}
if(analogRead(Ir2)<200){
digitalWrite(In3, HIGH);
digitalWrite(In4, LOW);
analogWrite(ENB, SPEED);
}
else {
digitalWrite(In1, HIGH);
digitalWrite(In2, LOW);
analogWrite(ENA, SPEED);
digitalWrite(In3, LOW);
digitalWrite(In4, HIGH);
analogWrite(ENB, SPEED);
}
Serial.print(analogRead(Ir1));
Serial.print("Hurray ");
Serial.println(analogRead(Ir2));
}