-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbottle.ino
313 lines (239 loc) · 9.8 KB
/
bottle.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
/*
started with the code from
https://youtu.be/L9ZFgElnTGU
https://create.arduino.cc/projecthub/embeddedlab786/automatic-water-bottle-filling-system-e8251c
https://github.com/embeddedlab786/Automatic_Water_Bottle_Filling_System
but will change a lot and add some comments to the code
https://github.com/ldijkman/Arduino_emmer_vuller_bucket_filling
should have a screen for testing all inputs / outputs to check working
aalsmeer bloemen veiling emmervuller containervuller fustvuller
low cost water filling timer conveyer belt automation controller +/-10 euro
https://youtu.be/L9ZFgElnTGU
https://hacksterio.s3.amazonaws.com/uploads/attachments/1200705/automatic_water_bottle_filling_system_L7E1jegbDF.png
https://create.arduino.cc/projecthub/embeddedlab786/automatic-water-bottle-filling-system-e8251c
conveyer belt type water filling
want i2c lcd
want rotary encoder for water_valve_opentime setting
https://github.com/ldijkman/Arduino_emmer_vuller_bucket_filling
arduino uno
icc 20x4 dot matrix lcd
rotary encoder
buttons
optic or ultrasonic sensors for bottle bucket detection
valve or pump_or_valve for water
relais engine conveyer belt beltmotor
*/
#include <LiquidCrystal_I2C.h> // better use i2c display??? https://www.arduinolibraries.info/libraries/liquid-crystal-i2-c
#include <EEPROM.h> // for saving fillingtime tru reboot / powercycle
LiquidCrystal_I2C lcd(0x27, 20, 4); // Set the LCD address to 0x27 for a 20 chars and 4 line display
#define echopin A4 // echo pin // ultrasonic tank level detection not needed
#define trigpin A5 // Trigger pin // ultrasonic tank level detection not needed
int cont = 0;
// int ???
int button_set = A0; // button set fill timer micro seconds digit selection could be 2,9 seconds instead of 2900 milli
int button_val_up = A1; // button time digit value++ up increase
int button_stop = A2; // button stop
int button_start = A3; // button start start and stop could be made 1 button
int set = 0;
int stop = 0, stop1;
int mode = 0;
int buz = 13;
int timer = 0;
int pump_or_valve = 8;
int beltmotor = 9;
int ir_start = 10;
int ir_fill = 11;
int ir_stop = 12;
int dist; // ultrasonic tank level detection not needed
long duration; // ultrasonic tank level detection not needed
int val1 = 0, val2 = 0, val3 = 0, val4 = 1;
long fillingtime = 0;
void setup() {
// i like to use a rotary encoder for fill time setting and 1 start/stop button
pinMode (button_set, INPUT_PULLUP); // input pullup ???
pinMode (button_val_up, INPUT_PULLUP); // input pullup ???
pinMode (button_stop, INPUT_PULLUP); // input pullup ???
pinMode (button_start, INPUT_PULLUP); // input pullup ???
// i like to use a rotary encoder for fill time setting and 1 start/stop button
pinMode(ir_fill, INPUT_PULLUP);
pinMode(ir_start, INPUT_PULLUP); // 3x input pullup ??? no resistors needed
pinMode(ir_stop, INPUT_PULLUP); // think 2 product detection sensors are enough 1 fill position and 1 end conveyer position stop
pinMode (trigpin, OUTPUT); // ultrasonic tank level detection not needed
pinMode (echopin, INPUT); // ultrasonic tank level detection not needed
pinMode(beltmotor, OUTPUT);
pinMode(pump_or_valve, OUTPUT);
pinMode(buz, OUTPUT);
lcd.begin(); // initialize the LCD
lcd.backlight(); // Turn on the blacklight
lcd.setCursor(0, 0); lcd.print(" WELCOME To ");
lcd.setCursor(0, 1); lcd.print("Automatic Water");
lcd.setCursor(0, 2); lcd.print(" Filling");
lcd.setCursor(0, 3); lcd.print(" System");
delay(2000);
Serial.begin(9600);
Read(); // read eeprom fillingtime wil be 0 at the first boot ???
if (fillingtime == 0) fillingtime = 2500; // make it 2500 miliseconds 2.5 seconds
//analogWrite(beltmotor, 100);
for (int i = 0; i < 5; i ++) { // ultrasonic tank level detection not needed
dist = data1(); // ultrasonic tank level detection not needed
data2(); // ultrasonic tank level detection not needed
delay(100); // ultrasonic tank level detection not needed
} // ultrasonic tank level detection not needed
lcd.clear();
} // end setup
void loop() {
if (stop == 0) {
if (digitalRead (button_set) == 0) { // set select digit button pressed
lcd.clear();
mode = mode + 1;
if (mode > 4) { // set switch digit select 1 of 4 digits
mode = 0;
Write(); // write fillingtime to eeprom
Read(); // read fillingtime from eeprom
lcd.setCursor(0, 0);
lcd.print(" Ok Saved Data ");
delay(1000);
}
delay(300);
}
if (digitalRead (button_val_up) == 0) { // up button pressed fillingtime value++
if (mode == 1) { // digit 1 of 4 active for change
val1 = val1 + 1;
}
if (mode == 2) { // digit 2 of 4 active for change
val2 = val2 + 1;
}
if (mode == 3) { // digit 3 of 4 active for change
val3 = val3 + 1;
}
if (mode == 4) { // digit 5 of 4 active for change
val4 = val4 + 1;
}
if (val1 > 9) { // digit1 not greater as 9 make 10 zero
val1 = 0;
}
if (val2 > 9) { // digit2 not greater as 9 make 10 zero
val2 = 0;
}
if (val3 > 9) { // digit3 not greater as 9 make 10 zero
val3 = 0;
}
if (val4 > 9) { // digit4 not greater as 9 make 10 zero
val4 = 0;
}
delay(300);
}
} // end if stop == 0
if (mode == 0) {
if (digitalRead (button_stop) == 0) { // stop button pressed
stop = 0;
}
if (digitalRead (button_start) == 0) { // start button pressed start stop could me made 1 button
stop = 1;
}
/*
// start stop could me made 1 button like next
// toggle stopval
if (digitalRead (button_start) == 0) { // stop/start button pressed toggle
stop = !stop; // !stop (stop = notstop) toggle the value in stop
}
*/
lcd.setCursor(0, 0); lcd.print(" WELCOME To ");
lcd.setCursor(0, 1); lcd.print(" A W F S ");
lcd.setCursor(0, 2);
lcd.print("Tank Level=");
lcd.print(dist);
lcd.print("% ");
lcd.setCursor(0, 3);
lcd.print("Fill Time =");
lcd.print(fillingtime);
lcd.print(" ");
} else {
lcd.setCursor(0, 0);
lcd.print("Set Time= ");
lcd.print(val4);
lcd.print(val3);
lcd.print(val2);
lcd.print(val1);
if (mode == 4) { // edit fillingtime active print a - for selected active for change digit
lcd.setCursor(10, 1);
lcd.print("-");
}
if (mode == 3) { // edit fillingtime active print a - for selected active for change digit
lcd.setCursor(11, 1);
lcd.print("-");
}
if (mode == 2) { // edit fillingtime active print a - for selected active for change digit
lcd.setCursor(12, 1);
lcd.print("-");
}
if (mode == 1) { // edit fillingtime active print a - for selected active for change digit
lcd.setCursor(13, 1);
lcd.print("-");
}
}
if (stop == 1) {
if (digitalRead (ir_stop) == 1) {
analogWrite(beltmotor, 200); // start belt
if (digitalRead (ir_fill) == 0) {
if (stop1 == 0) {
stop1 = 1;
analogWrite(beltmotor, 0); // stop belt
delay(200);
digitalWrite(pump_or_valve, HIGH); // start watering
delay(fillingtime); // delay fillingtiime
digitalWrite(pump_or_valve, LOW); // stop wattering
for (int i = 0; i < 10; i ++) {
dist = data1(); // ultrasonic tank level detection not needed
data2(); // ultrasonic tank level detection not needed
delay(200);
}
analogWrite(beltmotor, 200); // start belt
}
}
if (digitalRead (ir_start) == 0) {
stop1 = 0;
}
}
else {
analogWrite(beltmotor, 0); // stop belt
delay(300);
}
} else {
analogWrite(beltmotor, 0); // stop belt
}
}
// read and store filling timer value setting for reboot / powercycle
void Read() {
val1 = EEPROM.read(11);
val2 = EEPROM.read(12);
val3 = EEPROM.read(13);
val4 = EEPROM.read(14);
fillingtime = val4 * 1000 + val3 * 100 + val2 * 10 + val1;
Serial.println(fillingtime);
}
// read and store filling timer value setting for reboot / powercycle
void Write() {
EEPROM.write(11, val1);
EEPROM.write(12, val2);
EEPROM.write(13, val3);
EEPROM.write(14, val4);
}
void data2() {
dist = map(dist, 2, 30, 100, 0); // map ultrasonic tank level detection 0 to 100% not needed
if (dist > 100) {
dist = 100;
}
if (dist < 0) {
dist = 0;
}
}
long data1() { // ultrasonic tank level detection not needed
digitalWrite(trigpin, LOW);
delayMicroseconds(2);
digitalWrite(trigpin, HIGH);
delayMicroseconds(10);
duration = pulseIn (echopin, HIGH);
return duration / 29 / 2;
}
// https://github.com/ldijkman/Arduino_emmer_vuller_bucket_filling