-
Notifications
You must be signed in to change notification settings - Fork 0
/
line_follower_robot_Code.ino
67 lines (54 loc) · 1.65 KB
/
line_follower_robot_Code.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
/* Raheek Ayman Helal
Dr.Manal El-Belkasy
Computer Science
level(1)
*/
// defining the ouput pins of the arduino
#define Motor11 7
#define Motor21 9
#define PWMmotor1 5
#define PWMmotor2 10
int valuePWM1=100; // speed motor 1
int valuePWM2=100; // speed motor 2
void setup()
{
Serial.begin(9600);
//defining the output & the input pins
pinMode(Motor11,OUTPUT);
pinMode(Motor21,OUTPUT);
pinMode(PWMmotor1,OUTPUT);
pinMode(PWMmotor2,OUTPUT);
pinMode(A0, INPUT); // initialize Right sensor as an inut
pinMode(A1, INPUT); // initialize Left sensor as an input
}
void loop()
{
int LEFT_SENSOR = analogRead(A0);
int RIGHT_SENSOR = analogRead(A1);
if( RIGHT_SENSOR>200 && LEFT_SENSOR>200) //FORWARD
{
digitalWrite(Motor11, HIGH);
digitalWrite(Motor21, HIGH);
analogWrite(PWMmotor1, valuePWM1);
analogWrite(PWMmotor2, valuePWM1);
}
else if(RIGHT_SENSOR<36 || LEFT_SENSOR>200) //LEFT
{
digitalWrite(Motor11, LOW);
digitalWrite(Motor21, HIGH);
analogWrite(PWMmotor1, valuePWM2);
analogWrite(PWMmotor2, valuePWM2);
}
else if(RIGHT_SENSOR>200 || LEFT_SENSOR<36) //RIGHT
{
digitalWrite(Motor11, HIGH);
digitalWrite(Motor21, LOW);
analogWrite(PWMmotor1, valuePWM2);
analogWrite(PWMmotor2, valuePWM2);
}
else //STOP
{
digitalWrite(Motor11, LOW);
digitalWrite(Motor21, LOW);
}
}