-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduino_code.ino
335 lines (283 loc) · 7.89 KB
/
Arduino_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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
//Including the Library code
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
const int rs = 37, rw =36, en = 35, d4 = 33, d5 = 32, d6 = 31, d7 = 30;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//Declaring Variables
int red, green, blue;
//associating the sensor variables to their pin numbers
int s0 = 12;
int s1 = 7;
int s2 = 8;
int s3 = 38;
int output = 21;
int l1=0,l2=0,l3=0; //Initializing the lcd screen values to zero
int A[9], B[9], C[9];
int k=0, l=0, m=0, i;
int table=1;
void setup()
{
//Pin Delecartion for WHite Line Sensors
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
//Pin Declaration for turning on the White Line Sensors
pinMode(39,OUTPUT);
//Pin Declaration for turning on the Motors
pinMode(25,OUTPUT);
pinMode(24,OUTPUT);
pinMode(23,OUTPUT);
pinMode(22,OUTPUT);
//Pin Declaration of PWN Speed Control for Motors
pinMode(46,OUTPUT); //Left Motor
pinMode(45,OUTPUT); //Right Motor
//Setting Speed
analogWrite(46,100);
analogWrite(45,100);
//Declaring pin modes
pinMode(s0,OUTPUT); //s0
pinMode(s1,OUTPUT); //s1
pinMode(s2,OUTPUT); //s2
pinMode(s3,OUTPUT); //s3
pinMode(output,INPUT); //output
//Setting s0 ans s1 to get 20% frequency
digitalWrite(s0,HIGH);
digitalWrite(s1,LOW);
//Settig Up LCD Output
pinMode(rw,OUTPUT);
digitalWrite(rw,LOW);
lcd.begin(16, 2);
}
void SenVal() //Reading Sensor Value
{
l1 = analogRead(A1); //l1 for Right Sesnor
l2 = analogRead(A2); //l2 for Center Sensor
l3 = analogRead(A3); //l3 for Left Sesnor
}
//Fuctions to control motion speed and direction of the motors
void forward() //Moving Forward
{
//Right Motor
digitalWrite(24,HIGH); //Right Fwd Wheel
digitalWrite(25,LOW); //Right Bwd Wheel
//Left Motor
digitalWrite(23,HIGH); //Left Fwd Wheel
digitalWrite(22,LOW); //Left Bwd Wheel
}
void left() //Moving Left
{
//Right Motor
digitalWrite(24,LOW); //Right Fwd Wheel
digitalWrite(25,LOW); //Right Bwd Wheel
//Left Motor
digitalWrite(23,HIGH); //Left Fwd Wheel
digitalWrite(22,LOW); //Left Fwd Wheel
}
void right() //Moving Right
{
//Right Motor
digitalWrite(24,HIGH); //Right Fwd Wheel
digitalWrite(25,LOW); //Right Bwd Wheel
//Left Motor
digitalWrite(23,LOW); //Left Fwd Wheel
digitalWrite(22,LOW); //Left Bwd Wheel
}
void stop() //Stopping
{
//Right Motor
digitalWrite(24,LOW ); //Right Fwd Wheel
digitalWrite(25,LOW); //Right Bwd Wheel
//Left Motor
digitalWrite(23,LOW); //Left Fwd Wheel
digitalWrite(22,LOW); //Left Bwd Wheel
}
void Backward() //Moving Reverse
{
//Right Motor
digitalWrite(24,LOW); //Right Fwd Wheel
digitalWrite(25,HIGH); //Right Bwd Wheel
//Left Motor
digitalWrite(23,LOW); //Left Fwd Wheel
digitalWrite(22,HIGH); //Left Bwd Wheel
}
void color() // Reading Color
{
//Reading Red Color
digitalWrite(s2,LOW);
digitalWrite(s3,LOW);
red = pulseIn(output,LOW);
//Reading Green Color
digitalWrite(s2,HIGH);
digitalWrite(s3,HIGH);
green = pulseIn(output,LOW);
//Reading Blue Color
digitalWrite(s2,LOW);
digitalWrite(s3,HIGH);
blue = pulseIn(output,LOW);
}
void order() //Taking Order
{
if(red<green && red<blue)
A[k++] = table++;
else if(green<red && green<blue)
B[l++] = table++;
else if(blue<red && blue<green)
C[m++] = table++;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Thank You");
lcd.setCursor(0,1);
lcd.print("Order Taken");
delay(1000);
}
void place() //Placing Order
{
if(red<green && red<blue)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Order from - ");
lcd.setCursor(0,1);
lcd.print(" ");
for(i=0;i<k;i++)
{
lcd.print(A[i]);
lcd.print(" ");
}
}
else if(green<red && green<blue)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Order from - ");
lcd.setCursor(0,1);
lcd.print(" ");
for(i=0;i<l;i++)
{
lcd.print(B[i]);
lcd.print(" ");
}
}
else if(blue<red && blue<green)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Order from - ");
lcd.setCursor(0,1);
lcd.print(" ");
for(i=0;i<m;i++)
{
lcd.print(C[i]);
lcd.print(" ");
}
}
}
// Setting the condition and applying it
void loop()
{
SenVal();
lcd.setCursor(0,0);
lcd.print("S3 S2 s1");
lcd.setCursor(0,1);
lcd.print(l3);
lcd.print(" ");
lcd.print(l2);
lcd.print(" ");
lcd.print(l1);
//Currently 5 tables are present
if (table > 5)
{
//Checking Sensor and applying conditions
if( l1>=200 && l3>=200 && l2>=200)
{
stop();
delay(100);
lcd.clear();
color();
place();
delay(1000);
lcd.clear();
forward();
delay(1000);
}
else if( l1>=200 )
{
left();
delay(100);
SenVal();
while(l2<=200 || l1>=200)
{
left();
SenVal();
}
}
else if( l3>=200 )
{
right();
delay(100);
SenVal();
while(l2<=200 || l3>=200)
{
right();
SenVal();
}
}
else if( l2>=200 )
{
forward();
}
else
{
stop();
}
delay(100);
}
//If all the tables have placed order, giving order to kitchen
else
{
//Checking Sensor and applying conditions
if(l1>=200 && l3>=200 && l2>=200) //Threshold Value is taken as 200
{
stop();
delay(100);
lcd.clear();
color();
order();
delay(100);
lcd.clear();
forward();
delay(1000);
}
else if( l1>=200 )
{
left();
delay(100);
SenVal();
while(l2<=200 || l1>=200)
{
left();
SenVal();
}
}
else if( l3>=200 )
{
right();
delay(100);
SenVal();
while(l2<=200 || l3>=200)
{
right();
SenVal();
}
}
else if( l2>=200 )
{
forward();
}
else
{
stop();
}
delay(100);
}
}