-
Notifications
You must be signed in to change notification settings - Fork 0
/
sourceCode.txt
1340 lines (1128 loc) · 34.9 KB
/
sourceCode.txt
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// For GSM Module
#include <SoftwareSerial.h>
//For stepper.h
#include <Stepper.h>
// Library for Servo Motor
#include <Servo.h>
// for keypad
#include <Keypad.h>
//library for loadcell
#include <HX711_ADC.h>
#if defined(ESP8266)|| defined(ESP32) || defined(AVR)
#include <EEPROM.h>
#endif
// Library for i2c display
// for i2c display
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//library for temperature sensor
#include <OneWire.h>
#include <DallasTemperature.h>
/***** Servo Motor *****/
// Define the servo objects for each pin
Servo servo1; //used to measure sugar amount
Servo servo2; //used to measure sugar amount
Servo servo3; //used to measure Anchor amount
Servo servo4; //used to measure Anchor amount
Servo servo5; //used to measure Tea leaf amount
Servo servo6; //used to measure Tea leaf amount
Servo servo7; //Used in tea leaf filter system
Servo servo8;
// Define the angles for each movement
const int angle0 = 0;
const int angle90 = 90;
const int angle180 = 180;
const int angle270 = 270;
/***********/
/*****relay****/
const int pump_relay_1 = 53; //r1 // the Arduino pin, which connects to the IN pin of relay
const int pump_relay_2 = 51; //r2
const int pumpmotor_relay = 49; //r3 //tea to cup
const int h_pump_relay_3 = 45; //r4 //heating element to mixer container
const int belt_motor_relay = 43; //r5
const int mixermotor_relay = 41;//r6
const int h_coil_relay = 47;// add externel coil relay
/*****level sensor*********/
const int levelsensor_pin = A0;
const int numReadings = 100;
int sensorReadings[numReadings];
int currentReading = 0;
long totalSensorValue = 0;
int averageSensorValue = 0;
/***** LCD Display *****/
// Set the LCD address and dimensions (change these to match your setup)
const int lcdColumns = 16;
const int lcdRows = 2;
const int lcdAddress = 0x27;
LiquidCrystal_I2C lcd(lcdAddress, lcdColumns, lcdRows);
/************/
/***** Keypad ****/
// Define the keypad layout
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
byte rowPins[ROWS] = { 37, 35, 33, 31 }; // Connect to the row pinouts of the keypad
byte colPins[COLS] = { 29, 27, 25, 23 }; // Connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
/************/
/******temporature sensor****/
const int SENSOR_PIN = 4; // Arduino pin connected to DS18B20 sensor's DQ pin
OneWire oneWire(SENSOR_PIN); // setup a oneWire instance
DallasTemperature tempSensor(&oneWire); // pass oneWire to DallasTemperature library
float temp; // temperature in Celsius
/*************/
/********IR sensor*******/
const int irSensorPin = 52; // Pin for the IR sensor
const int stepsPerRevolution = 200; // Change this value according to your stepper motor
/***stepper***/
const float STEPS_PER_REV = 32;
const float GEAR_RED = 64;
const float STEPS_PER_OUT_REV = STEPS_PER_REV * GEAR_RED;
Stepper steppermotor(STEPS_PER_REV, 38, 42, 40, 44);
void RotateStepperMotor();
/*************/
/*** GSM Module ********/
SoftwareSerial mySerial(18, 19); // RX, TX
// conect RX to TX and Tx to RX
/***********/
/*** Load Cell ********/
int count = 0;
//pins:
const int HX711_dout = 24; //mcu > HX711 dout pin
const int HX711_sck = 22; //mcu > HX711 sck pin
//HX711 constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);
const int calVal_eepromAdress = 0;
unsigned long t = 0;
/************/
/*** Other variables ******/
const int numOfTeaTypes = 3;
const char* TeaTypes[numOfTeaTypes] = {
"1. Normal",
"2. Strong",
"3. Sugarless"
};
int selectedTeaType = 0;
int TeaQuantity;
void setup() {
/*****relay****/
pinMode(pump_relay_1, OUTPUT);
pinMode(pump_relay_2, OUTPUT);
pinMode(h_pump_relay_3, OUTPUT);
pinMode(belt_motor_relay, OUTPUT);
pinMode(pumpmotor_relay, OUTPUT);
pinMode(mixermotor_relay, OUTPUT);
pinMode(h_coil_relay, OUTPUT);
/****levelsensor****/
pinMode(levelsensor_pin, INPUT);
Serial.begin(9600);
/*** i2c Display *******/
// Initialize the I2C bus
Wire.begin();
// Initialize the LCD
lcd.begin(lcdColumns, lcdRows);
lcd.setBacklight(HIGH); // Set backlight to a higher level
/************/
pinMode(irSensorPin, INPUT); // Pin mode for IR sensor
// Attach the servo objects to their respective pins
servo1.attach(45);
servo2.attach(44);
servo3.attach(43);
servo4.attach(42);
servo5.attach(41);
servo6.attach(40);
servo7.attach(39);
servo8.attach(38);
servo1.write(90);
servo2.write(0);
servo3.write(90);
servo4.write(0);
servo5.write(90);
servo6.write(0);
servo7.write(90);
servo8.write(0);
Serial.begin(9600);
delay(2000);
Serial.println();
Serial.println("Starting...");
Serial.println("SIM900A Ready");
tempSensor.begin(); // initialize the sensor
LoadCell.begin();
//LoadCell.setReverseOutput(); //uncomment to turn a negative output value to positive
float calibrationValue; // calibration value (see example file "Calibration.ino")
calibrationValue = 417.73; // to set the calibration value in the sketch
#if defined(ESP8266)|| defined(ESP32)
#endif
unsigned long stabilizingtime = 2000; // preciscion right after power-up can be improved by adding a few seconds of stabilizing time
boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
LoadCell.start(stabilizingtime, _tare);
if (LoadCell.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
while (1);
}
else {
LoadCell.setCalFactor(calibrationValue); // set calibration value (float)
Serial.println("Startup is complete");
}
}
void loop() {
int TeaQuantity = 0;
Serial.begin(9600);
// print 'starting machine' on display
lcd.clear();
lcd.print("Starting");
lcd.setCursor(0, 1);
lcd.print("Machine.......");
delay(2000);
lcd.clear(); // clear lcd
lcd.print("Avilable Tea");
lcd.setCursor(0, 1);
lcd.print("Types : ");
delay(2000);
// Print tea types in lcd types
for (int i = 0; i < numOfTeaTypes; i++) {
lcd.clear(); // Clear the LCD display
lcd.print(TeaTypes[i]);
delay(2000); // Delay to display each topping for 2 seconds
}
lcd.clear(); // Clear the LCD display
lcd.print("Select Tea");
lcd.setCursor(0, 1);
lcd.print("Type : ");
char key;
while (true) {
key = keypad.getKey(); // get keyboard input
if (key == '1') {
lcd.clear();
lcd.print("You select");
lcd.setCursor(0, 1);
lcd.print(TeaTypes[key - '1']);
selectedTeaType = 1;
delay(2000);
break;
} else if (key == '2') {
lcd.clear();
lcd.print("You select");
lcd.setCursor(0, 1);
lcd.print(TeaTypes[key - '1']);
selectedTeaType = 2;
delay(2000);
break;
} else if (key == '3') {
lcd.clear();
lcd.print("You select");
lcd.setCursor(0, 1);
lcd.print(TeaTypes[key - '1']);
selectedTeaType = 3;
delay(2000);
break;
}
if (key == 'A' || key == 'B' || key == 'C' || key == 'D' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9' || key == '0') {
lcd.clear();
lcd.print("Invalid");
lcd.setCursor(0, 1);
lcd.print("Selection!");
delay(1500);
lcd.clear();
lcd.print("Please Select");
lcd.setCursor(0, 1);
lcd.print("Option 1 / 2 / 3");
delay(1500);
}
}
lcd.clear();
lcd.print("Enter Tea");
lcd.setCursor(0, 1);
lcd.print("Quantity : ");
while (true) {
char qty = ' ';
qty = keypad.getKey();
if (qty == '1' || qty == '2' || qty == '3' || qty == '4' || qty == '5') {
switch (qty) {
case '1':
TeaQuantity = 1;
break;
case '2':
TeaQuantity = 2;
break;
case '3':
TeaQuantity = 3;
break;
case '4':
TeaQuantity = 4;
break;
case '5':
TeaQuantity = 5;
break;
}
lcd.clear();
lcd.print("Quantity ");
lcd.setCursor(0, 1);
lcd.print(qty);
delay(2000);
break;
} else if (qty == '6' || qty == '7' || qty == '8' || qty == '9' || qty == '0' || qty == 'A' || qty == 'B' || qty == 'C' || qty == 'D') {
lcd.clear();
lcd.print("Invalid");
lcd.setCursor(0, 1);
lcd.print("Quantity!");
delay(1500);
lcd.clear();
lcd.print("Select");
lcd.setCursor(0, 1);
lcd.print("Less than 5");
}
/*if (TeaQuantity > 0) {
break;
}*/
}
lcd.clear();
lcd.print("Type: " + String(TeaTypes[selectedTeaType - 1]));
lcd.setCursor(0, 1);
lcd.print("Quantity: " + String(TeaQuantity));
delay(2000);
lcd.clear();
lcd.print("A: Continue");
lcd.setCursor(0, 1);
lcd.print("B: Reset");
char ConfirmationKey;
while (true) {
ConfirmationKey = keypad.getKey();
if (ConfirmationKey == 'A') {
lcd.clear();
lcd.print("Tea Making");
lcd.setCursor(0, 1);
lcd.print("Started...");
delay(2000);
break;
} else if (ConfirmationKey == 'B') {
lcd.clear();
lcd.print("Resetting");
lcd.setCursor(0, 1);
lcd.print("Machine");
delay(2000);
break;
} else if (ConfirmationKey == '1' || ConfirmationKey == '2' || ConfirmationKey == '3' || ConfirmationKey == '4' || ConfirmationKey == '5' || ConfirmationKey == '6' || ConfirmationKey == '7' || ConfirmationKey == '8' || ConfirmationKey == '9' || ConfirmationKey == '0' || ConfirmationKey == 'C' || ConfirmationKey == 'D') {
lcd.clear();
lcd.print("Invalid");
lcd.setCursor(0, 1);
lcd.print("Selection!");
delay(1000);
lcd.print("A: Continue");
lcd.setCursor(0, 1);
lcd.print("B: Reset");
}
}
//level check
for(int i=0;i<TeaQuantity;i++){
int waterLevel_1 = measureWaterLevel(); // Measure the water level
Serial.print(waterLevel_1);
if(waterLevel_1<100) {
Serial.println("Turn on the motor"); // Water level is below or equal to 400, turn on the motor
digitalWrite(pump_relay_1, HIGH);
delay(75000);
digitalWrite(pump_relay_1, LOW);
}
int waterLevel_2 = measureWaterLevel(); // Measure the water level
Serial.print(waterLevel_2);
if (waterLevel_2 > 300) {
Serial.println("Start the progress"); // Water level is above 400, start the progress
// Perform other actions related to starting the progress
digitalWrite(pump_relay_2, HIGH); // turn on solinoid valve relay 5 seconds
delay(5000);
digitalWrite(pump_relay_2, LOW); // turn off solinoid valve relay 5 seconds
delay(5000);
// Perform other actions related to turning on the motor
//selection for the tea
Serial.println("tea type");
if(selectedTeaType==1){
selection_1_measuring();
}
if(selectedTeaType==2){
selection_2_measuring();
}
if(selectedTeaType==3){
selection_3_measuring();
}
float temperature = tempmeasurment();
digitalWrite(h_coil_relay, HIGH); // turn on coil
while(temperature<70){
temperature = tempmeasurment();
}
if (temperature>70){
Serial.print("turn off the rellay");
digitalWrite(h_coil_relay, LOW);
}
//pass the hot water to the mixer container
digitalWrite(h_pump_relay_3, HIGH); // turn on pump 5 seconds
delay(1000);
digitalWrite(h_pump_relay_3, LOW); // turn off pump 5 seconds
delay(1000);
//mix the tea
digitalWrite(mixermotor_relay, HIGH); // turn on mixer motor 5 seconds
delay(1000);
digitalWrite(mixermotor_relay, LOW);
turnServo_8(servo8, angle90, 1);
turnServo_7(servo7, angle180, 1);
delay(2000);
turnServo_8(servo8, angle0, 1);
delay(1000);
if (digitalRead(irSensorPin) == LOW) {
Serial.println("Object detected");
Serial.println("pump motor is working");
digitalWrite(pumpmotor_relay, HIGH);
delay(1000); // Duration of pump operation
digitalWrite(pumpmotor_relay, LOW);
delay(1000);
}
else {
Serial.println("No object detected");
RotateStepperMotor(-STEPS_PER_OUT_REV);
delay(10);
Serial.println("stepper motor working");
delay(5000);
// fan motor
digitalWrite(belt_motor_relay, HIGH); // turn on fan motor 5 seconds
delay(5000);
digitalWrite(belt_motor_relay, LOW); // turn off fan motor 5 seconds
Serial.println("belt_motor is working");
delay(5000);
if (digitalRead(irSensorPin) == HIGH) {
Serial.println("there is no cup in the secound dedection");
Serial.println("send sms to refill cup");
sendSMS("+94777602179", "Refill the cups"); // Send SMS when no object is detected
delay(5000); // Delay after sending the SMS
}
}
}
delay(1000);
}
float x=weight_of_waste();
if(x>500){
Serial.println("dispose the weight");
sendSMS("+94777602179", "dispose the weight"); // Send SMS
}
}
bool validQuantitySelection(char key) {
if (key == '1' || key == '2' || key == '3' || key == '4' || key == '5') {
return true;
} else if (key == '6' || key == '7' || key == '8' || key == '9' || key == '0' || key == 'A' || key == 'B' || key == 'C' || key == 'D') {
return false;
}
}
/**** Functions for loade cells ****/
/**** GSM Module ****/
void sendSMS(String recipient, String message) {
mySerial.println("AT+CMGF=1");
delay(1000);
mySerial.println("AT+CMGS=\"" + recipient + "\"");
delay(1000);
mySerial.println(message);
delay(1000);
mySerial.write(26);
delay(5000);
Serial.println("SMS Sent successfully!");
}
/***********/
/**** Servo Motor *****/
// Function to turn the servo by the given angle for the specified number of times
void turnServo(Servo servo, int angle, int numOfTimes) {
for (int i = 0; i < numOfTimes; i++) {
servo.write(angle);
delay(2000);
servo.write(0);
delay(1000);
}
}
void turnServo_8(Servo servo, int angle, int numOfTimes) {
for (int i = 0; i < numOfTimes; i++) {
servo.write(angle);
delay(1000);
}
}
void turnServo_7(Servo servo, int angle, int numOfTimes) {
for (int i = 0; i < numOfTimes; i++) {
servo.write(angle);
delay(1000);
servo.write(90);
delay(2000);
}
}
void selection_1_measuring(){
for(int i=0;i<3;i++){
//suger //Strong tea
turnServo(servo1, angle90, 1);
turnServo(servo2, angle90, 1);
}
//tea
for(int i=0;i<2;i++){
turnServo(servo3, angle90, 1);
turnServo(servo4, angle90, 1);
}
//milkpowder
for(int i=0;i<2;i++){
turnServo(servo5, angle90, 1);
turnServo(servo6, angle90, 1);
}
}
void selection_2_measuring(){
//suger
for(int i=0;i<2;i++){
turnServo(servo1, angle90, 1);
turnServo(servo2, angle90, 1);
}
//tea
for(int i=0;i<1;i++){
turnServo(servo3, angle90, 1);
turnServo(servo4, angle90, 1);
}
//milkpowder
for(int i=0;i<3;i++){
turnServo(servo5, angle90, 1);
turnServo(servo6, angle90, 1);
}
}
void selection_3_measuring(){
//suger
for(int i=0;i<3;i++){
turnServo(servo1, angle90, 1);
turnServo(servo2, angle90, 1);
}
//tea
for(int i=0;i<3;i++){
turnServo(servo3, angle90, 1);
turnServo(servo4, angle90, 1);
}
}
/***water level measurment****/
int measureWaterLevel() {
totalSensorValue = 0;
// Read the sensor value multiple times and calculate the average
for (int i = 0; i < numReadings; i++) {
sensorReadings[currentReading] = analogRead(levelsensor_pin);
totalSensorValue += sensorReadings[currentReading];
currentReading = (currentReading + 1) % numReadings;
delay(2);
}
averageSensorValue = totalSensorValue / numReadings;
//Serial.print("Average sensor value = ");
//Serial.println(averageSensorValue);
return averageSensorValue;
}
/***********/
/******calculate the weight of the weight*****/
float weight_of_waste(){
float actual_weight_value=0;
while (count < 100){
static boolean newDataReady = 0;
const int serialPrintInterval = 0; //increase value to slow down serial print activity
// check for new data/start next conversion:
if (LoadCell.update()) newDataReady = true;
// get smoothed value from the dataset:
if (newDataReady) {
if (millis() > t + serialPrintInterval) {
float weight_val = LoadCell.getData();
Serial.print("Load_cell actual weight value : ");
Serial.println(weight_val);
newDataReady = 0;
t = millis();
if (count >= 50){
actual_weight_value = actual_weight_value + weight_val;
}
count = count + 1;
}
}
}
actual_weight_value = actual_weight_value/50;
count = 0;
Serial.print("The actual weighgt is : ");
Serial.println(actual_weight_value);
return actual_weight_value;
}
/*************/
float tempmeasurment(){
tempSensor.requestTemperatures(); // send the command to get temperatures
temp = tempSensor.getTempCByIndex(0); // read temperature in Celsius
/*Serial.print("\nTemperature: ");
Serial.print(temp); // print the temperature in Celsius
Serial.print("°C");
Serial.print(" ~ "); // separator between Celsius and Fahrenheit
Serial.print(tempFahrenheit); // print the temperature in Fahrenheit
Serial.println("°F");*/
delay(500);
return temp;
}
void RotateStepperMotor(int StepsRequired)
{
steppermotor.setSpeed(1100);
steppermotor.step(StepsRequired);
}
// For GSM Module
#include <SoftwareSerial.h>
//For stepper.h
#include <Stepper.h>
// Library for Servo Motor
#include <Servo.h>
// for keypad
#include <Keypad.h>
//library for loadcell
#include <HX711_ADC.h>
#if defined(ESP8266)|| defined(ESP32) || defined(AVR)
#include <EEPROM.h>
#endif
// Library for i2c display
// for i2c display
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//library for temperature sensor
#include <OneWire.h>
#include <DallasTemperature.h>
/***** Servo Motor *****/
// Define the servo objects for each pin
Servo servo1; //used to measure sugar amount
Servo servo2; //used to measure sugar amount
Servo servo3; //used to measure Anchor amount
Servo servo4; //used to measure Anchor amount
Servo servo5; //used to measure Tea leaf amount
Servo servo6; //used to measure Tea leaf amount
Servo servo7; //Used in tea leaf filter system
Servo servo8;
// Define the angles for each movement
const int angle0 = 0;
const int angle90 = 90;
const int angle180 = 180;
const int angle270 = 270;
/***********/
/*****relay****/
const int pump_relay_1 = 53; //r1 // the Arduino pin, which connects to the IN pin of relay
const int pump_relay_2 = 51; //r2
const int pumpmotor_relay = 49; //r3 //tea to cup
const int h_pump_relay_3 = 45; //r4 //heating element to mixer container
const int belt_motor_relay = 43; //r5
const int mixermotor_relay = 41;//r6
const int h_coil_relay = 47;// add externel coil relay
/*****level sensor*********/
const int levelsensor_pin = A0;
const int numReadings = 100;
int sensorReadings[numReadings];
int currentReading = 0;
long totalSensorValue = 0;
int averageSensorValue = 0;
/***** LCD Display *****/
// Set the LCD address and dimensions (change these to match your setup)
const int lcdColumns = 16;
const int lcdRows = 2;
const int lcdAddress = 0x27;
LiquidCrystal_I2C lcd(lcdAddress, lcdColumns, lcdRows);
/************/
/***** Keypad ****/
// Define the keypad layout
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
byte rowPins[ROWS] = { 37, 35, 33, 31 }; // Connect to the row pinouts of the keypad
byte colPins[COLS] = { 29, 27, 25, 23 }; // Connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
/************/
/******temporature sensor****/
const int SENSOR_PIN = 4; // Arduino pin connected to DS18B20 sensor's DQ pin
OneWire oneWire(SENSOR_PIN); // setup a oneWire instance
DallasTemperature tempSensor(&oneWire); // pass oneWire to DallasTemperature library
float temp; // temperature in Celsius
/*************/
/********IR sensor*******/
const int irSensorPin = 52; // Pin for the IR sensor
const int stepsPerRevolution = 200; // Change this value according to your stepper motor
/***stepper***/
const float STEPS_PER_REV = 32;
const float GEAR_RED = 64;
const float STEPS_PER_OUT_REV = STEPS_PER_REV * GEAR_RED;
Stepper steppermotor(STEPS_PER_REV, 38, 42, 40, 44);
void RotateStepperMotor();
/*************/
/*** GSM Module ********/
SoftwareSerial mySerial(18, 19); // RX, TX
// conect RX to TX and Tx to RX
/***********/
/*** Load Cell ********/
int count = 0;
//pins:
const int HX711_dout = 24; //mcu > HX711 dout pin
const int HX711_sck = 22; //mcu > HX711 sck pin
//HX711 constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);
const int calVal_eepromAdress = 0;
unsigned long t = 0;
/************/
/*** Other variables ******/
const int numOfTeaTypes = 3;
const char* TeaTypes[numOfTeaTypes] = {
"1. Normal",
"2. Strong",
"3. Sugarless"
};
int selectedTeaType = 0;
int TeaQuantity;
void setup() {
/*****relay****/
pinMode(pump_relay_1, OUTPUT);
pinMode(pump_relay_2, OUTPUT);
pinMode(h_pump_relay_3, OUTPUT);
pinMode(belt_motor_relay, OUTPUT);
pinMode(pumpmotor_relay, OUTPUT);
pinMode(mixermotor_relay, OUTPUT);
pinMode(h_coil_relay, OUTPUT);
/****levelsensor****/
pinMode(levelsensor_pin, INPUT);
Serial.begin(9600);
/*** i2c Display *******/
// Initialize the I2C bus
Wire.begin();
// Initialize the LCD
lcd.begin(lcdColumns, lcdRows);
lcd.setBacklight(HIGH); // Set backlight to a higher level
/************/
pinMode(irSensorPin, INPUT); // Pin mode for IR sensor
// Attach the servo objects to their respective pins
servo1.attach(45);
servo2.attach(44);
servo3.attach(43);
servo4.attach(42);
servo5.attach(41);
servo6.attach(40);
servo7.attach(39);
servo8.attach(38);
servo1.write(90);
servo2.write(0);
servo3.write(90);
servo4.write(0);
servo5.write(90);
servo6.write(0);
servo7.write(90);
servo8.write(0);
Serial.begin(9600);
delay(2000);
Serial.println();
Serial.println("Starting...");
Serial.println("SIM900A Ready");
tempSensor.begin(); // initialize the sensor
LoadCell.begin();
//LoadCell.setReverseOutput(); //uncomment to turn a negative output value to positive
float calibrationValue; // calibration value (see example file "Calibration.ino")
calibrationValue = 417.73; // to set the calibration value in the sketch
#if defined(ESP8266)|| defined(ESP32)
#endif
unsigned long stabilizingtime = 2000; // preciscion right after power-up can be improved by adding a few seconds of stabilizing time
boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
LoadCell.start(stabilizingtime, _tare);
if (LoadCell.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
while (1);
}
else {
LoadCell.setCalFactor(calibrationValue); // set calibration value (float)
Serial.println("Startup is complete");
}
}
void loop() {
int TeaQuantity = 0;
Serial.begin(9600);
// print 'starting machine' on display
lcd.clear();
lcd.print("Starting");
lcd.setCursor(0, 1);
lcd.print("Machine.......");
delay(2000);
lcd.clear(); // clear lcd
lcd.print("Avilable Tea");
lcd.setCursor(0, 1);
lcd.print("Types : ");
delay(2000);
// Print tea types in lcd types
for (int i = 0; i < numOfTeaTypes; i++) {
lcd.clear(); // Clear the LCD display
lcd.print(TeaTypes[i]);
delay(2000); // Delay to display each topping for 2 seconds
}
lcd.clear(); // Clear the LCD display
lcd.print("Select Tea");
lcd.setCursor(0, 1);
lcd.print("Type : ");
char key;
while (true) {
key = keypad.getKey(); // get keyboard input
if (key == '1') {
lcd.clear();
lcd.print("You select");
lcd.setCursor(0, 1);
lcd.print(TeaTypes[key - '1']);
selectedTeaType = 1;
delay(2000);
break;
} else if (key == '2') {
lcd.clear();
lcd.print("You select");
lcd.setCursor(0, 1);
lcd.print(TeaTypes[key - '1']);
selectedTeaType = 2;
delay(2000);
break;
} else if (key == '3') {
lcd.clear();
lcd.print("You select");
lcd.setCursor(0, 1);
lcd.print(TeaTypes[key - '1']);
selectedTeaType = 3;
delay(2000);
break;
}
if (key == 'A' || key == 'B' || key == 'C' || key == 'D' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9' || key == '0') {
lcd.clear();
lcd.print("Invalid");
lcd.setCursor(0, 1);
lcd.print("Selection!");
delay(1500);
lcd.clear();
lcd.print("Please Select");
lcd.setCursor(0, 1);
lcd.print("Option 1 / 2 / 3");
delay(1500);
}
}
lcd.clear();
lcd.print("Enter Tea");
lcd.setCursor(0, 1);
lcd.print("Quantity : ");
while (true) {
char qty = ' ';
qty = keypad.getKey();
if (qty == '1' || qty == '2' || qty == '3' || qty == '4' || qty == '5') {
switch (qty) {
case '1':
TeaQuantity = 1;
break;
case '2':
TeaQuantity = 2;
break;
case '3':
TeaQuantity = 3;
break;
case '4':
TeaQuantity = 4;
break;
case '5':
TeaQuantity = 5;
break;
}
lcd.clear();
lcd.print("Quantity ");
lcd.setCursor(0, 1);
lcd.print(qty);
delay(2000);
break;
} else if (qty == '6' || qty == '7' || qty == '8' || qty == '9' || qty == '0' || qty == 'A' || qty == 'B' || qty == 'C' || qty == 'D') {
lcd.clear();
lcd.print("Invalid");
lcd.setCursor(0, 1);
lcd.print("Quantity!");