-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsun-seeker.ino
126 lines (107 loc) · 2.28 KB
/
sun-seeker.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//--------------------------Sun-Seeker---------------------------//
//---------------------------------------------------------------//
//assigning analog pin to the sensor input
int pinin1=A0,pinin2=A1;
//store analog value
int sensorValue1=0,sensorValue2=0;
//digital out comparing sensor values
int stpin1,stpin2;
//these digital output for driving three motors
const int m1=2,m2=3,m3=4,m4=5,m5=8,m6=9;
//counter parameters
int interval_to_read_sensor_value=0,loop_count=0;
//robot's basic functions
void stop_right_there();
void move_forward_searching_light();
void rotate_in_dir_of_light();
void setup()
{
pinMode(m1,OUTPUT);
pinMode(m2,OUTPUT);
pinMode(m3,OUTPUT);
pinMode(m4,OUTPUT);
pinMode(m5,OUTPUT);
pinMode(m6,OUTPUT);
}
void loop()
{
sensorValue1 = analogRead(pinin1);
if(sensorValue1<=150)
stpin1=HIGH;
else
stpin1=LOW;
sensorValue2 = analogRead(pinin2);
if(sensorValue2<=150)
stpin2=HIGH;
else
stpin2=LOW;
// 1st condition both sensor detect light
if (stpin1==HIGH && stpin2==HIGH)
{
stop_right_there();
}
//2nd condition both sensor doesnot detect light
else if(stpin1==LOW && stpin2== LOW)
{
move_forward_searching_light();
}
//3rd condition one of the sensor detect light
else
{
rotate_in_dir_of_light();
}
if(interval_to_read_sensor_value==500)
{
digitalWrite(m1,LOW);
digitalWrite(m2,HIGH);
digitalWrite(m3,LOW);
digitalWrite(m4,LOW);
delay(4300);
interval_to_read_sensor_value=0;
loop_count++;
stop_right_there();
}
if(loop_count==4)
exit(0);
}
void stop_right_there()
{
digitalWrite(m1,LOW);
digitalWrite(m2,LOW);
digitalWrite(m3,LOW);
digitalWrite(m4,LOW);
digitalWrite(m5,LOW);
digitalWrite(m6,LOW);
// delay(50);
return;
}
void move_forward_searching_light()
{
digitalWrite(m1,LOW);
digitalWrite(m2,HIGH);
digitalWrite(m3,LOW);
digitalWrite(m4,HIGH);
delay(20);
interval_to_read_sensor_value++;
stop_right_there();
return;
}
void rotate_in_dir_of_light()
{
if(stpin1==HIGH && stpin2==LOW)
{
digitalWrite(m5,HIGH);
digitalWrite(m6,LOW);
delay(50);
stop_right_there();
return;
}
else
{
digitalWrite(m5,LOW);
digitalWrite(m6,HIGH);
delay(50);
stop_right_there();
return;
}
}