-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Menu_test_arduino_plant_watering.ino
2310 lines (1894 loc) · 87.2 KB
/
Menu_test_arduino_plant_watering.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
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
// working on SD card Logging for mega 2560 board (not enough progmem space on nano /uno)
// working on creates a comma seperated log file datestamp .txt on SD card each day
// on a mega2560 allmost everything / every change is logged to sdcard
//
//*****************************************************************************
// BUT HOW do a visualize such a LOG file online or in a spreadsheet editor???
//
// if you drag the log .txt file from sdcard to here https://www.csvplot.com/
// they will make a chart
// https://github.com/ldijkman/Arduino_Plant_Watering_System/blob/main/csvplot.com_log_txt_mega2560.jpg
// drag menu items on left to x or y
//
// if you know a good (simple) online/ofline chart maker to view (all) the data
// let me know??? https://m.facebook.com/luberth.dijkman
//
// sudo apt-get install kst install on my linux raspberry pi400
// kst2 command to start it = kst2 / it is also in startmenu Education
// kst-plot has a ton / load of options
// and is fast with big data
// https://miscircuitos.com/using-kst-plot-visualize-data-real-time/
// https://kst-plot.kde.org/
// https://kst-plot.kde.org/video_tutorials/
// WOW!
// plot data from serial port in realtime https://miscircuitos.com/plot-real-time-signal-coming-arduino/
//
// should make a menu for mega2560 version => dump sdcard ?file to serial port
// serialdata to file => pi@raspberrypi:~ $ (stty raw; cat > received.csv) < /dev/ttyUSB0
// why always a restart of arduino when connect serial
//
// this csv graph viewer is easier menu on left side to turn things on/off
// another windows linux mac csv graph viewer
// http://www.analogflavor.com/en/view-csv-files-as-graphs/
// http://www.analogflavor.com/en/bespice/downloads/
// sorry kst but this Analog Flavor - BeSpice Wave is easier
// also does realtime plot serial to file => pi@raspberrypi:~ $ (stty raw; cat > received.csv) < /dev/ttyUSB0
//
//
//***********************************************************************
//
// Arduino Advanced Automated Plant Watering System, StandAlone, Low Cost, Low Power Consumption
// Copyright 2021 Dirk Luberth Dijkman Bangert 30 1619GJ Andijk The Netherlands
/*
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Arduino Nano / Uno / Mega2560
Arduino Automated Plant Watering System, automatic irrigation system
Arduino Advanced Automated Plant Watering System, StandAlone, Low Cost, Low Power Consumption
Copyright 2021 Dirk Luberth Dijkman Bangert 30 1619GJ Andijk The Netherlands
https://m.facebook.com/luberth.dijkman
https://github.com/ldijkman/Arduino_Plant_Watering_System
https://github.com/ldijkman/Arduino_Plant_Watering_System/discussions
https://youtu.be/1jKAxLyOY_s
GNU General Public License,
which basically means that you may freely copy, change, and distribute it,
but you may not impose any restrictions on further distribution,
and you must make the source code available.
https://www.gnu.org/licenses
used code for rotary encoder from:
Robust Rotary encoder reading
Copyright John Main - best-microcontroller-projects.com
https://www.best-microcontroller-projects.com/rotary-encoder.html
http://Paypal.Me/LDijkman
All above must be included in any redistribution
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
*/
//
// it all started with a Question from Jo
// Jo de Martelaer Arduino UNO / NANO WaterGift
// Boomkwekerij Hortus Conclusus
// https://www.hortusconclusus.be/
// Catalogus => https://www.hortusconclusus.be/collections
//
// Arduino PlantWatering Examples i have seen on the internet are to simple, overwatering, no pause, no limmits, no timebounds, less feedback,
// no standalone system ability to change parameters / settings, Calibrate sensors
//
// Jo Says has problems with sensors influencing eachother?
// https://www.youtube.com/c/HortusconclususBe/videos
// maybe use i2c analog 4 channel 16bit https://www.google.com/search?q=aliexpress+ads1115
// is the ads1115 multiplexing like arduino?
// or use 2 single channel i2c analog to digital converters with a different i2c adress, No Noise?
// future maybe 2x 1 channel 12bit? MCP4725 I2C, both with different i2c adres
// https://www.google.com/search?q=aliexpress+MCP4725
//
// What is maximum sensor wire length for analog? for i2c?
// soil-watch sells 5v analog with 20meter cables
// (No grounded shield?, unshielded?=does that make sense) https://pino-tech.eu/soilwatch10/
//
//
// with irrigation drippers / drip emmiters you have more control of amount of water per time!?
// different types liters/per hour
// white tyleen hose less heat / polution, better not use black, do not use transparent
// use an extra dripper in a measurecan to monitor/check water given each day (empty can each day)
//
//
// DS3231 RTC realtimeclock connected to +5vdc GND SCL SDA
// 4x20 i2c LCD connected to +5vdc GND SCL SDA
//
// Cheap dollar capacitive soil moisture sensors are in the Khz range
// more expensive capacitive soil moisture sensors are in the +/-75Mhz range (mineral/contemination transperency?)
// but it isnt the 555 timer replacement that Justifys the 30x and up price
// https://www.google.com/search?q=LTC6905+soil+moisture
//
// 2 capacitive soil moisture sensors connected to analog A0 and A3
//
// Pump and or valve output D13 (wich is also onboard LED)
//
// rotarybutton_SW 2 // input D2 rotary encoder SW
// CLK 3 // input D3 rotary encoder CLK
// DATA 4 // input D4 rotary encoder DT
// and connect rotary encoder to +5vdc and GND to 0vdc, -, min, GND, ground, or whatever they call it
// parts list:
// Uno https://www.google.com/search?q=aliexpress+arduino+uno
// or a nano 1 dollar?
// Nano https://www.google.com/search?q=aliexpress+arduino+nano
// RTC DS3231 https://www.google.com/search?q=aliexpress+RTC+DS3231
// i2c LCD 20x4 https://www.google.com/search?q=aliexpress+LCD+20x4+i2c
// 2 sensors https://www.google.com/search?q=aliexpress+aduino+capacitive+soil+moisture+V2
// capacitive soil moisture sensor, most are V1.2 there is a V2, maybe better?
// dupont wires or better solder wires for permanent device
// relays https://www.google.com/search?q=aliexpress+WeMos+relais+Shield
//
// for mega sd card log https://www.google.com/search?q=aliexpress+Micro+SD+card+mini+TF+card+reader+module+SPI+interfaces+for+arduino+with+level+converter+chip
// other sensors https://www.tindie.com/products/miceuz/i2c-soil-moisture-sensor/#product-name
// https://github.com/ldijkman/Arduino_Plant_Watering_System/discussions
// future SD Card log // not enough space nano uno == 105% for mega 2560 or mega pro mini
#if (defined(__AVR_ATmega2560__))
#include <SPI.h>
#include <SD.h>
/*
i used an SPI TFT LCD SD-Card reader, maybe not safe 5v / 3.3v ???????? !!!!!!!! !!!!!
https://diyi0t.com/sd-card-arduino-esp8266-esp32/
https://www.google.com/search?q=aliexpress+Micro+SD+card+mini+TF+card+reader+module+SPI+interfaces+for+arduino+with+level+converter+chip
SPI bus pins:
mega pin i/o 50 = MISO
mega pin i/o 51 = MOSI
mega pin i/o 52 = CLK (on SPI TFT LCD == SCK)
mega pin i/o 53 = CS
i used an SPI TFT LCD SD-Card reader, maybe not safe 5v / 3.3v ???????? !!!!!!!! !!!!!
*/
const int chipSelect = 53;
#endif
// future SD Card log // not enough space nano uno == 105% for mega 2560 or mega pro mini
#include "RTClib.h" // https://github.com/adafruit/RTClib
RTC_DS3231 rtc;
#include <EEPROM.h>
#include <LiquidCrystal_I2C.h> // https://github.com/marcoschwartz/LiquidCrystal_I2C/archive/master.zip
LiquidCrystal_I2C lcd(0x27, 20, 4); // Configure LiquidCrystal_I2C library with 0x27 address, 20 columns and 4 rows
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int start_hour = 9; // starttime 9 o clock in the morning
int end_hour = 21; // endtime 21 o clock in te evening
signed long watering_duration = 60; // in seconds = 60 seconds
signed long pauze_after_watering = 1 ; // in minutes = 1 minute
signed long watergifttimer;
signed long pauzetimer;
signed long startpauzetimer;
signed long starttime;
String lastwatering;
unsigned long previousMillis = 0;
unsigned long currentMillis;
int moistureforstartwatering = 30; // if smaller als 30% start watering
int dry_sensor_one = 795; // my sensor value Dry in air 795
int wet_sensor_one = 435; // my sensor value wet in water 435
int dry_sensor_two = 795; // my sensor value Dry in air 795
int wet_sensor_two = 435; // my sensor value wet in water 435
int sense1;
int sense2;
long Read_A0 = 0;
long Read_A3 = 0;
int dummy_read;
int averageinprocent; // average of 2 sensors in %
byte watergiftcounter = 0;
byte ValveStatus = 0;
byte second_now;
byte last_second;
byte maximumaantalbeurtenperdag = 8;
byte Calibrate_Sensors = 1;
byte eepromerase = 1;
byte settimedate = 1;
byte backtobegin = 1;
long loopspeed;
String ClearLine = " "; // 20 spaces
// rotary encoder push button KY-040 https://www.google.com/search?q=KY-040
// Robust Rotary encoder reading
// Copyright John Main - best-microcontroller-projects.com
// https://www.best-microcontroller-projects.com/rotary-encoder.html
#define rotarybutton_SW 2 // input D2 rotary encoder SW
#define CLK 3 // input D3 rotary encoder CLK
#define DATA 4 // input D4 rotary encoder DT
// and connect rotary encoder to +5vdc and GND to 0vdc, -, min, GND, ground, or whatever they call it
static uint8_t prevNextCode = 0;
static uint16_t store = 0;
//
byte menu_nr = 0;
long TempLong; // Temporary re-used over and over again
float TempFloat;
int TempInt;
byte TempByte;
int backlightofftimeout = 5; // time to switch backlight off in minutes
long backlightstart;
byte backlightflag;
byte blinknodelay_flag; // a blink flag that is 1 second==1, and 1 second==0
int counter;
byte exitflag = 0;
byte errorflag = 0;
byte alarmoutput = 10;
byte buzzeroutput = 8; // https://www.google.com/search?q=aliexpress+KY-006+passive+buzzer+module
//**********************************************************************************************
void setup () {
pinMode(alarmoutput, OUTPUT); // error light blink
pinMode(13, OUTPUT); // pin 13 for valve open / close is also the onboard LED
// i have 3 pullup resistors on my KY-040 so INPUT_PULLUP should not be needed
// BUT
// Jo says NO pullup resistor on SW on his rotary decoder => so made it input_pullup
pinMode(rotarybutton_SW, INPUT_PULLUP); // rotary encoder SW = pulled up by resistor on KY-040 to +
pinMode(CLK, INPUT_PULLUP); // rotary encoder CLK = pulled up by resistor on KY-040 to +
pinMode(DATA, INPUT_PULLUP); // rotary encoder DATA = pulled up by resistor on KY-040 to +
Serial.begin(115200); // serial monitor
lcd.begin(); // Initialize I2C LCD module (SDA = GPIO21, SCL = GPIO22)
// lcd.begin(21, 22); // Jo de Martelaer says lcd.begin(); does not work on win10, use lcd.init(); he says
// lcd.init(); // strange i have no problem with it on linux arduino ide 1.8.13
lcd.backlight(); // Turn backlight ON
lcd.clear(); // clear lcd
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
// want to see the contents of EEPROM there is a read example Arduino IDE =>File=>Examples=>EEPROM=>eeprom_read
// Six Hundred and Sixty-Six on adres Six Hundred and Sixty-Six is written in EEPROM like this
// 665 255
// 666 154 2x256+154=666
// 667 2
// 668 255
// DO NEXT ONLY ONCE
// first run ??? write some val to eeprom if value at eepromadres 90 not is 666
// if this is first run then val will not be 666 at eeprom adres 90
// so next will be run
EEPROM.get(90, TempInt); // read eeprom adress 90 into TempInt
if (TempInt != 666) { // IF this is the first run THEN val at eeprom adres 90 is not 666 ???
EEPROM.put(0, moistureforstartwatering);
EEPROM.put(5, dry_sensor_one);
EEPROM.put(10, wet_sensor_one);
EEPROM.put(15, dry_sensor_two);
EEPROM.put(20, wet_sensor_two);
EEPROM.put(25, watering_duration);
EEPROM.put(30, pauze_after_watering);
EEPROM.put(35, maximumaantalbeurtenperdag);
EEPROM.put(40, start_hour);
EEPROM.put(45, end_hour);
EEPROM.put(50, backlightofftimeout);
// EEPROM.put(55, Variable-Here);
// EEPROM.put(60, Variable-Here);
EEPROM.put(90, 666); // ONLY ONCE, Make His Mark, set eepromadres 90 to val 666 no need to call / run this anymore in future
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Hi There! First run"));
lcd.setCursor(0, 1);
lcd.print(F("Have written value's"));
lcd.setCursor(0, 2);
lcd.print(F("to EEPROM "));
lcd.setCursor(0, 3);
lcd.print(F("Thanks for trying"));
for (int i = 30 ; i >= 0 ; i--) { // on LCD countdown 30 to 0 half a second tick
lcd.setCursor(18, 3);
if (i <= 9) lcd.print(" ");
lcd.print(i);
delay(500);
}
delay(1000); // want to see the 0
lcd.clear();
}// END Do it ONLY ONCE, MADE HIS MARK
// Read stored valeus from EEPROM
EEPROM.get(0, moistureforstartwatering);
EEPROM.get(5, dry_sensor_one);
EEPROM.get(10, wet_sensor_one);
EEPROM.get(15, dry_sensor_two);
EEPROM.get(20, wet_sensor_two);
EEPROM.get(25, watering_duration);
EEPROM.get(30, pauze_after_watering);
EEPROM.get(35, maximumaantalbeurtenperdag);
EEPROM.get(40, start_hour);
EEPROM.get(45, end_hour);
EEPROM.get(50, backlightofftimeout);
// EEPROM.get(55, Variable-Here);
// EEPROM.get(60, Variable-Here);
backlightstart = millis(); // load millis() in backlightstart
lcd.clear();
// they say eeprom life 100 thousand writes
// say i write/erase a byte 4 times a day = 25 thousand days = 68 Years
// could also use i2c eeprom that is on the ds3231 rtc board wich i think has 1 milion writes, RTC DS3231 with AT24C32 eeprom
// https://www.google.com/search?q=AT24C32+pdf
for (int i = 100 ; i < 1010 /*EEPROM.length()*/ ; i++) { // erase eprom water start times
lcd.setCursor(0, 0);
lcd.print("Erase WaterTime LOG");
lcd.setCursor(8, 2);
lcd.print(i);
EEPROM.write(i, 0); // erase eprom water start times
//Serial.println(i);
}
lcd.clear();
//Serial.print("Initializing SD card...");
#if (defined(__AVR_ATmega2560__))
//Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
//Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
//Serial.println("card initialized.");
#endif
//rtc.adjust(DateTime(2021, 5, 9,9, 59, 00));
// header for realtime serial to file kst plot CSV graph Viewer pi@raspberrypi:~ $ (stty raw; cat > received.csv) < /dev/ttyUSB0
Serial.println("time, dry1, wett1, dry2, wett2, sensor1, sensor2, averageinprocent, moisturestartprocent, starthour, endhour, temperature, jobcounter, maxjobs, wateringduration, pauzeduration, lastwateringtime, ValveStatus, watergifttimer, pauzetimer, outputread, errorflag,");
}
//**********************************************************************************************************
void loop () {
if (backlightflag == 1 && millis() - backlightstart > (backlightofftimeout * 60 * 1000L)) { // if backlight timed out turn it off
lcd.noBacklight(); // Turn backlight OFF
backlightflag = 0;
}
if (backlightflag == 0 && millis() - backlightstart < (backlightofftimeout * 60 * 1000L)) {
lcd.backlight(); // Turn backlight ON
backlightflag = 1;
}
// 5-ways-to-blink-an-led-with-arduino
// https://urish.medium.com/5-ways-to-blink-an-led-with-arduino-8f8a41b4fc7d
// like this oneliner
// used for blinking text when time is not in range
blinknodelay_flag = (millis() / 1000) % 2; // continues 1second high, 1second low
// read the sensors 10 times and divide by 10
readsensors();
// end read the sensors 10 times and divide by 10
if (SetButton() == LOW) { // SW = pulled up by resistor on KY-040 to +, so LOW is button pressed
backlightstart = millis(); // load current millis() into backlightstart
lcd.backlight(); // turn backlight on
TempLong = millis(); // load current millis() into TempLong
while (SetButton() == LOW) { // while setbutton==LOW, pulled up by resistor, LOW is pressed
if ((millis() - TempLong) < 3000) { // only show this mssage the first 5 seconds
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Backlight ON"));
lcd.setCursor(5, 3);
lcd.print(F("Menu Enter in"));
lcd.setCursor(19, 3);
lcd.print(3 - (millis() - TempLong) / 1000); // on LCD countdown until menu system enter
delay(250);
}
if ((millis() - TempLong) > 3000) { // after 5 seconds pressed we get into menu system
lcd.clear();
lcd.setCursor(7, 1);
lcd.print(F("in Menu"));
lcd.setCursor(3, 3);
lcd.print(F("Release Button"));
delay(500);
menu_nr = 1;
}
}
lcd.clear();
}
if (menu_nr != 0) { // only check next menus if menu_nr not = 0
// 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
// setpoint setpoint setpoint setpoint setpoint setpoint setpoint setpoint setpoint setpoint setpoint setpoint setpoint setpoint
TempLong = millis(); // load current millis() into TempLong
if (menu_nr == 1) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("1 Set SwitchPoint %"));
lcd.setCursor(8, 2);
lcd.print(moistureforstartwatering);
lcd.print(F(" % "));
}
while (menu_nr == 1) {
lcd.setCursor(18, 3);
if ((10 - (millis() - TempLong) / 1000) <= 9)lcd.print(" "); // move 1 char when smaller a 10 wich is 2 chars
lcd.print(10 - (millis() - TempLong) / 1000); // on lcd timeout countdown
if ((millis() - TempLong) > 10000) {
delay(1000); // want to see the zero 0
TimeOut();
break;
}
float rval;
if ( rval = read_rotary() ) {
moistureforstartwatering = moistureforstartwatering + (rval);
if (moistureforstartwatering >= 70) moistureforstartwatering = 70;
if (moistureforstartwatering <= 10) moistureforstartwatering = 10;
TempLong = millis(); // load current millis() into TempLong
lcd.setCursor(8, 2);
lcd.print(moistureforstartwatering);
lcd.print(F(" % "));
}
if (SetButton() == LOW) { // if setbutton==LOW, pulled up by resistor, LOW is pressed
while (SetButton() == LOW) {
/*wait for button released*/
}
menu_nr = 2;
lcd.clear();
EEPROM.get(0, TempInt); // limmited write to eeprom = read is unlimmited
if (moistureforstartwatering != TempInt) { // only write to eeprom if value is different
EEPROM.put(0, moistureforstartwatering); // put already checks if val is needed to write
lcd.setCursor(0, 0);
lcd.print(F("Saving to EEPROM"));
lcd.setCursor(0, 2);
lcd.print("old= ");
lcd.print(TempInt);
lcd.print(F(" new= "));
lcd.print(moistureforstartwatering);
TempLong = millis(); // load millis() into Templong for next countdown delay
while ((millis() - TempLong) <= 5000) {
lcd.setCursor(19, 3);
lcd.print(5 - (millis() - TempLong) / 1000); // on lcd timeout countdown
}
delay(1000); // want to see the zero 0
// for (int i = 0; i < 10; i++)Serial.println(F("moistureforstartwatering DATA WRITTEN / SAVED TO EEPROM "));
lcd.clear();
}
}
}// end menu_nr 1
// 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
// Calibrate sensors Calibrate sensors Calibrate sensors Calibrate sensors Calibrate sensors Calibrate sensors
TempLong = millis(); // load current millis() into TempLong
if (menu_nr == 2) {
lcd.setCursor(0, 0);
lcd.print(F("2 Calibrate Sensors"));
lcd.setCursor(7, 2);
if (Calibrate_Sensors == 1)lcd.print(F(" No "));
if (Calibrate_Sensors == 2)lcd.print(F(" Yes "));
if (Calibrate_Sensors == 3)lcd.print(F("Adjust"));
}
while (menu_nr == 2) {
lcd.setCursor(18, 3);
if ((10 - (millis() - TempLong) / 1000) <= 9)lcd.print(" "); // move 1 char when smaller a 10 wich is 2 chars
lcd.print(10 - (millis() - TempLong) / 1000); // on lcd timeout countdown
if ((millis() - TempLong) > 10000) {
delay(1000); // want to see the zero 0
TimeOut();
break;
}
float rval;
if ( rval = read_rotary() ) {
Calibrate_Sensors = Calibrate_Sensors + rval;
TempLong = millis(); //reset innactive time counter
if (Calibrate_Sensors < 1)Calibrate_Sensors = 3;
if (Calibrate_Sensors > 3)Calibrate_Sensors = 1;
lcd.setCursor(7, 2);
if (Calibrate_Sensors == 1)lcd.print(F(" No "));
if (Calibrate_Sensors == 2)lcd.print(F(" Yes "));
if (Calibrate_Sensors == 3)lcd.print(F("Adjust"));
}
if (SetButton() == LOW) { // LOW setbutton is pressed
while (SetButton() == LOW) {
/*wait for button released*/
}
menu_nr = 3;
lcd.clear();
delay(250);
}
}// end menu_nr 2
if (Calibrate_Sensors == 2) { // you chose Yes so whe go to calibrate
Calibrate_Sensors = 1;
// WARNING!!!
// there is no timeout on this calibrate screens => for safety turn water off => its up to you to do a succesfull calibration
digitalWrite(13, LOW); // 13 is onboard led en waterklep en/of waterpomp stop
// there is no timeout on this calibrate screens => for safety turn water off => its up to you to do a succesfull calibration
// WARNING!!!
lcd.clear();
while (0 == 0) {
readsensors();
lcd.setCursor(0, 0);
lcd.print("Sensor1 analog A0");
lcd.setCursor(0, 1);
lcd.print("Clean Dry in Air?");
lcd.setCursor(9, 3);
lcd.print(sense1);
delay(250);
if (SetButton() == LOW) { // LOW setbutton is pressed
while (SetButton() == LOW) {
/*wait for button released*/
}
dry_sensor_one = sense1;
EEPROM.put(5, dry_sensor_one);
lcd.clear();
delay(500); // user gets a better experience switch to next screen?
break;
}
}
while (0 == 0) {
readsensors();
lcd.setCursor(0, 0);
lcd.print("Sensor1 analog A0");
lcd.setCursor(0, 1);
lcd.print("Wet in Watter?");
lcd.setCursor(9, 3);
lcd.print(sense1);
delay(250);
if (SetButton() == LOW) { // LOW setbutton is pressed
while (SetButton() == LOW) {
/*wait for button released*/
}
wet_sensor_one = sense1;
EEPROM.put(10, wet_sensor_one);
lcd.clear();
delay(500); // user gets a better experience switch to next screen?
break;
}
}
while (0 == 0) {
readsensors();
lcd.setCursor(0, 0);
lcd.print("Sensor2 analog A3");
lcd.setCursor(0, 1);
lcd.print("Clean Dry in Air?");
lcd.setCursor(9, 3);
lcd.print(sense2);
delay(250);
if (SetButton() == LOW) { // LOW setbutton is pressed
while (SetButton() == LOW) {
/*wait for button released*/
}
dry_sensor_two = sense2;
EEPROM.put(15, dry_sensor_two);
lcd.clear();
delay(500); // user gets a better experience switch to next screen?
break;
}
}
while (0 == 0) {
readsensors();
lcd.setCursor(0, 0);
lcd.print("Sensor2 analog A3");
lcd.setCursor(0, 1);
lcd.print("Wet in Watter?");
lcd.setCursor(9, 3);
lcd.print(sense2);
delay(250);
if (SetButton() == LOW) { // LOW setbutton is pressed
while (SetButton() == LOW) {
/*wait for button released*/
}
wet_sensor_two = sense2;
EEPROM.put(20, wet_sensor_two);
lcd.clear();
delay(500); // user gets a better experience switch to next screen?
Calibrate_Sensors = 3;
break;
}
}
}// end calibrate sensors==2
// Calibrate_Sensors == 3 Calibrate_Sensors == 3 Calibrate_Sensors == 3 Calibrate_Sensors == 3 Calibrate_Sensors == 3 Calibrate_Sensors == 3
if (Calibrate_Sensors == 3) { // you chose Adjust
Calibrate_Sensors = 1;
// lcd.clear();
// lcd.print("Adjust not yet!");
// delay(2000);
lcd.clear();
while (exitflag == 0) {
readsensors();
lcd.setCursor(0, 0);
lcd.print("actual dry wet ");
lcd.setCursor(0, 1);
lcd.print("s1 "); lcd.print(sense1); lcd.setCursor(9, 1); lcd.print(dry_sensor_one); lcd.setCursor(15, 1); lcd.print(wet_sensor_one);
lcd.setCursor(0, 2);
lcd.print("s2 "); lcd.print(sense2); lcd.setCursor(9, 2); lcd.print(dry_sensor_two); lcd.setCursor(15, 2); lcd.print(wet_sensor_two);
lcd.setCursor(0, 3);
lcd.print("s1 "); lcd.print(map(sense1, dry_sensor_one, wet_sensor_one, 0, 100)); lcd.print("% ");
lcd.setCursor(9, 3);
lcd.print("s2 "); lcd.print(map(sense2, dry_sensor_two, wet_sensor_two, 0, 100)); lcd.print("% ");
// dry_sensor_one dry_sensor_one dry_sensor_one dry_sensor_one dry_sensor_one dry_sensor_one dry_sensor_one dry_sensor_one dry_sensor_one
if (exitflag == 0) {
while (1 == 1) {
lcd.setCursor(8, 1); lcd.print("["); lcd.setCursor(12, 1); lcd.print("]");
float rval;
if ( rval = read_rotary() ) {
dry_sensor_one = dry_sensor_one + (rval);
lcd.setCursor(8, 1); lcd.print("["); lcd.setCursor(12, 1); lcd.print("]");
readsensors();
lcd.setCursor(0, 0);
lcd.print("actual dry wet ");
lcd.setCursor(0, 1);
lcd.print("s1 "); lcd.print(sense1); lcd.setCursor(9, 1); lcd.print(dry_sensor_one); lcd.setCursor(15, 1); lcd.print(wet_sensor_one);
lcd.setCursor(0, 2);
lcd.print("s2 "); lcd.print(sense2); lcd.setCursor(9, 2); lcd.print(dry_sensor_two); lcd.setCursor(15, 2); lcd.print(wet_sensor_two);
lcd.setCursor(0, 3);
lcd.print("s1 "); lcd.print(map(sense1, dry_sensor_one, wet_sensor_one, 0, 100)); lcd.print("% ");
lcd.setCursor(9, 3);
lcd.print("s2 "); lcd.print(map(sense2, dry_sensor_two, wet_sensor_two, 0, 100)); lcd.print("% ");
}
if (SetButton() == LOW) { // if setbutton==LOW, pulled up by resistor, LOW is pressed
TempLong = millis();
while (SetButton() == LOW) {
lcd.setCursor(0, 0);
lcd.print("long press exit ");
if ((millis() - TempLong) > 2500) { // after 5 seconds pressed we get into menu system
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Ok, EXIT "));
lcd.setCursor(0, 3);
lcd.print(F(" Release Button "));
delay(500);
exitflag = 1;
}
}
lcd.setCursor(0, 0);
lcd.print("actual dry wet ");
EEPROM.put(5, dry_sensor_one);
lcd.setCursor(8, 1); lcd.print(" "); lcd.setCursor(12, 1); lcd.print(" ");
break;
}
}
}
// wet_sensor_one wet_sensor_one wet_sensor_one wet_sensor_one wet_sensor_one wet_sensor_one wet_sensor_one wet_sensor_one wet_sensor_one wet_sensor_one
if (exitflag == 0) {
while (1 == 1) {
lcd.setCursor(14, 1); lcd.print("["); lcd.setCursor(18, 1); lcd.print("]");
float rval;
if ( rval = read_rotary() ) {
wet_sensor_one = wet_sensor_one + (rval);
lcd.setCursor(14, 1); lcd.print("["); lcd.setCursor(18, 1); lcd.print("]");
readsensors();
lcd.setCursor(0, 0);
lcd.print("actual dry wet ");
lcd.setCursor(0, 1);
lcd.print("s1 "); lcd.print(sense1); lcd.setCursor(9, 1); lcd.print(dry_sensor_one); lcd.setCursor(15, 1); lcd.print(wet_sensor_one);
lcd.setCursor(0, 2);
lcd.print("s2 "); lcd.print(sense2); lcd.setCursor(9, 2); lcd.print(dry_sensor_two); lcd.setCursor(15, 2); lcd.print(wet_sensor_two);
lcd.setCursor(0, 3);
lcd.print("s1 "); lcd.print(map(sense1, dry_sensor_one, wet_sensor_one, 0, 100)); lcd.print("% ");
lcd.setCursor(9, 3);
lcd.print("s2 "); lcd.print(map(sense2, dry_sensor_two, wet_sensor_two, 0, 100)); lcd.print("% ");
}
if (SetButton() == LOW) { // if setbutton==LOW, pulled up by resistor, LOW is pressed
TempLong = millis();
while (SetButton() == LOW) {
lcd.setCursor(0, 0);
lcd.print("long press exit ");
if ((millis() - TempLong) > 2500) { // after 5 seconds pressed we get into menu system
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Ok, EXIT "));
lcd.setCursor(0, 3);
lcd.print(F(" Release Button "));
delay(500);
exitflag = 1;
}
}
lcd.setCursor(0, 0);
lcd.print("actual dry wet ");
EEPROM.put(10, wet_sensor_one);
lcd.setCursor(14, 1); lcd.print(" "); lcd.setCursor(18, 1); lcd.print(" ");
break;
}
}
}
// dry_sensor_two dry_sensor_two dry_sensor_two dry_sensor_two dry_sensor_two dry_sensor_two dry_sensor_two dry_sensor_two dry_sensor_two
if (exitflag == 0) {
while (1 == 1) {
lcd.setCursor(8, 2); lcd.print("["); lcd.setCursor(12, 2); lcd.print("]");
float rval;
if ( rval = read_rotary() ) {
dry_sensor_two = dry_sensor_two + (rval);
lcd.setCursor(8, 2); lcd.print("["); lcd.setCursor(12, 2); lcd.print("]");
readsensors();
lcd.setCursor(0, 0);
lcd.print("actual dry wet ");
lcd.setCursor(0, 1);
lcd.print("s1 "); lcd.print(sense1); lcd.setCursor(9, 1); lcd.print(dry_sensor_one); lcd.setCursor(15, 1); lcd.print(wet_sensor_one);
lcd.setCursor(0, 2);
lcd.print("s2 "); lcd.print(sense2); lcd.setCursor(9, 2); lcd.print(dry_sensor_two); lcd.setCursor(15, 2); lcd.print(wet_sensor_two);
lcd.setCursor(0, 3);
lcd.print("s1 "); lcd.print(map(sense1, dry_sensor_one, wet_sensor_one, 0, 100)); lcd.print("% ");
lcd.setCursor(9, 3);
lcd.print("s2 "); lcd.print(map(sense2, dry_sensor_two, wet_sensor_two, 0, 100)); lcd.print("% ");
}
if (SetButton() == LOW) { // if setbutton==LOW, pulled up by resistor, LOW is pressed
TempLong = millis();
while (SetButton() == LOW) {
lcd.setCursor(0, 0);
lcd.print("long press exit ");
if ((millis() - TempLong) > 2500) { // after 5 seconds pressed we get into menu system
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Ok, EXIT "));
lcd.setCursor(0, 3);
lcd.print(F(" Release Button "));
delay(500);
exitflag = 1;
}
}
lcd.setCursor(0, 0);
lcd.print("actual dry wet ");
EEPROM.put(15, dry_sensor_two);
lcd.setCursor(8, 2); lcd.print(" "); lcd.setCursor(12, 2); lcd.print(" ");
break;
}
}
}
// wet_sensor_two wet_sensor_two wet_sensor_two wet_sensor_two wet_sensor_two wet_sensor_two wet_sensor_two wet_sensor_two wet_sensor_two
if (exitflag == 0) {
while (1 == 1) {
lcd.setCursor(14, 2); lcd.print("["); lcd.setCursor(18, 2); lcd.print("]");
float rval;
if ( rval = read_rotary() ) {
wet_sensor_two = wet_sensor_two + (rval);
lcd.setCursor(14, 2); lcd.print("["); lcd.setCursor(18, 2); lcd.print("]");
readsensors();
lcd.setCursor(0, 0);
lcd.print("actual dry wet ");
lcd.setCursor(0, 1);
lcd.print("s1 "); lcd.print(sense1); lcd.setCursor(9, 1); lcd.print(dry_sensor_one); lcd.setCursor(15, 1); lcd.print(wet_sensor_one);
lcd.setCursor(0, 2);
lcd.print("s2 "); lcd.print(sense2); lcd.setCursor(9, 2); lcd.print(dry_sensor_two); lcd.setCursor(15, 2); lcd.print(wet_sensor_two);
lcd.setCursor(0, 3);
lcd.print("s1 "); lcd.print(map(sense1, dry_sensor_one, wet_sensor_one, 0, 100)); lcd.print("% ");
lcd.setCursor(9, 3);
lcd.print("s2 "); lcd.print(map(sense2, dry_sensor_two, wet_sensor_two, 0, 100)); lcd.print("% ");
}
if (SetButton() == LOW) { // if setbutton==LOW, pulled up by resistor, LOW is pressed
TempLong = millis();
while (SetButton() == LOW) {
lcd.setCursor(0, 0);
lcd.print("long press exit ");
if ((millis() - TempLong) > 2500) { // after 5 seconds pressed we get into menu system
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Ok, EXIT "));
lcd.setCursor(0, 3);
lcd.print(F(" Release Button "));
delay(500);
exitflag = 1;
}
}
lcd.setCursor(0, 0);
lcd.print("actual dry wet ");
EEPROM.put(20, wet_sensor_two);
lcd.setCursor(14, 2); lcd.print(" "); lcd.setCursor(18, 2); lcd.print(" ");
break;
}
}
}
}
} // end if (Calibrate_Sensors == 3) { // you chose Adjust
lcd.clear();
exitflag = 0;
// 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
// watering_duration watering_duration watering_duration watering_duration watering_duration
TempLong = millis(); // load current millis() into TempLong
if (menu_nr == 3) {
lcd.setCursor(0, 0);
lcd.print(F("3 Watering T in Sec."));
lcd.setCursor(6, 2);
lcd.print(watering_duration);
lcd.print(F(" Sec. "));
}
while (menu_nr == 3) {
lcd.setCursor(18, 3);
if ((10 - (millis() - TempLong) / 1000) <= 9)lcd.print(" "); // move 1 char when smaller a 10 wich is 2 chars
lcd.print(10 - (millis() - TempLong) / 1000); // on lcd timeout countdown
if ((millis() - TempLong) > 10000) {
delay(1000); // want to see the zero 0
TimeOut();
break;
}
float rval;
if ( rval = read_rotary() ) {
if (watering_duration >= 600)watering_duration = watering_duration + (rval * 30); // 30+24+6=60 second steps above 600 seconds
if (watering_duration >= 300)watering_duration = watering_duration + (rval * 24); // 24+6=30 second steps above 300 seconds
if (watering_duration >= 60)watering_duration = watering_duration + (rval * 6); // 6 second steps above 60 seconds
if (watering_duration <= 60)watering_duration = watering_duration + (rval); // 1 second steps
if (watering_duration <= 2) watering_duration = 2; // minimal watering time 2 seconds
TempLong = millis(); // load current millis() into TempLong
lcd.setCursor(6, 2);
lcd.print(watering_duration);
lcd.print(F(" Sec. "));
lcd.setCursor(6, 3);
float wateringtime = watering_duration;
float minutetime = (wateringtime / 60);
lcd.print(minutetime, 1);
lcd.print(F(" Min. "));
}
if (SetButton() == LOW) { // if setbutton==LOW, pulled up by resistor, LOW is pressed
while (SetButton() == LOW) {
/*wait for button released*/
}
menu_nr = 4;
lcd.clear();
EEPROM.get(25, TempInt); // limmited write to eeprom = read is unlimmited
if (watering_duration != TempInt) { // only write to eeprom if value is different
EEPROM.put(25, watering_duration); // put already checks if val is needed to write
lcd.setCursor(0, 0);
lcd.print(F("Saving to EEPROM"));
lcd.setCursor(0, 2);
lcd.print("old= ");
lcd.print(TempInt);
lcd.print(F(" new= "));
lcd.print(watering_duration);
TempLong = millis(); // load millis() into Templong for next countdown delay
while ((millis() - TempLong) <= 5000) {
lcd.setCursor(19, 3);
lcd.print(5 - (millis() - TempLong) / 1000); // on lcd timeout countdown
}
delay(1000); // want to see the zero 0
// for (int i = 0; i < 10; i++)Serial.println(F("watering_duration DATA WRITTEN / SAVED TO EEPROM "));
lcd.clear();
}
}
}// end menu_nr 3
// 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
// pauze_after_watering pauze_after_watering pauze_after_watering pauze_after_watering pauze_after_watering
TempLong = millis(); // load current millis() into TempLong
if (menu_nr == 4) {
lcd.setCursor(0, 0);
lcd.print(F("4 PauzeTime T in Min"));
lcd.setCursor(6, 2);
lcd.print(pauze_after_watering);
lcd.print(F(" Min. "));
}
while (menu_nr == 4) {
lcd.setCursor(18, 3);
if ((10 - (millis() - TempLong) / 1000) <= 9)lcd.print(" "); // move 1 char when smaller a 10 wich is 2 chars
lcd.print(10 - (millis() - TempLong) / 1000); // on lcd timeout countdown
if ((millis() - TempLong) > 10000) {
delay(1000); // want to see the zero 0
TimeOut();
break;
}
float rval;
if ( rval = read_rotary() ) {
pauze_after_watering = pauze_after_watering + (rval); // 1 minute steps
if (pauze_after_watering <= 1) pauze_after_watering = 1; // minimal pauzetime 1 minutes
TempLong = millis(); // load current millis() into TempLong
lcd.setCursor(6, 2);
lcd.print(pauze_after_watering);
lcd.print(F(" Min. "));
}
if (SetButton() == LOW) { // if setbutton==LOW, pulled up by resistor, LOW is pressed
while (SetButton() == LOW) {