-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bottle_v2.ino
344 lines (252 loc) · 12.2 KB
/
bottle_v2.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
// Arduino Bottle Filler - Arduino Bucket Filler conveyor type
// http://paypal.me/LDijkman
/*
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 rotary encoder for water_valve_opentime setting
https://github.com/ldijkman/Arduino_emmer_vuller_bucket_filling
add a second valve arduino lemonade machine conveyor
add a timer/countdown output and pump or valve for nutricients / chloride / medicine / lemonade sirop ???
Arduino Nano or Uno 2 to 5 euro
https://www.google.com/search?q=arduino+nano
https://www.google.com/search?q=arduino+uno
i2c 20x4 dot matrix LCD 5 euro
https://www.google.com/search?q=20x4+i2c
rotary encoder 0.5 euro
https://www.google.com/search?q=arduino+rotary+encoder+ky-040
buttons 1 euro
ir optic or ultrasonic sensors for bottle bucket detection 1 to 10 euro
https://www.google.com/search?q=arduino+HW-201
hw201 output is low when object seen / output high with no object
valve or pump_or_valve for water ??? euro
relais engine conveyer belt beltmotor ??? euro
Arduino Code ??? euro http://paypal.me/LDijkman
*/
#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
// connect LCD i2c BackPack sda scl
// Arduino uno A4=SDA A5=SCL
// Arduino nano A4=SDA A5=SCL
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; // not used button stop // now only start button is used for start and 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; // I/O D13 Buzzer not yet used in code?
int timer = 0;
int pump_or_valve = 8; // I/O D8
int pump_or_valve_run = 1; // 0 or 1 value depends on if valve is open on 0 low or 1 high
int beltmotor = 9; // I/O D9 used analog output PWM but can be changed to digital for relais
int beltmotor_run = 1; // 0 or 1 value depends on if valve is open on 0 low or 1 high
int ir_start = 10; // I/O D10 IR sensor position after filling >>> should be possible without this one if code is changed
int ir_fill = 11; // I/O D11 IR sensor filling position
int ir_stop = 12; // I/O D12 IR sensor end belt stop
// I think sensors on belt looks like next setup
// >>>>>>>>>11 filling position>>>>>>>>>>>10 position after filling>>>>>>>>>>> 12 end belt stop
int val1 = 0, val2 = 0, val3 = 0, val4 = 1;
long fillingtime = 0;
long startbelttime; // timeout stop belt if running for ???? seconds
long belttimeout = 600000; //stop belt after 600 seconds = 10 minutes of no filling
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 ??? no resistors needed
pinMode (button_val_up, INPUT_PULLUP); // input pullup ??? no resistors needed
pinMode (button_stop, INPUT_PULLUP); // input pullup ??? no resistors needed
pinMode (button_start, INPUT_PULLUP); // input pullup ??? no resistors needed
// 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(beltmotor, OUTPUT);
pinMode(pump_or_valve, OUTPUT);
pinMode(buz, OUTPUT);
lcd.begin(); // initialize the LCD
lcd.backlight(); // Turn on the backlight
lcd.setCursor(0, 0); lcd.print(" EmmerVuller ");
lcd.setCursor(0, 1); lcd.print(" BucketFiller ");
lcd.setCursor(0, 2); lcd.print(" Filling ");
lcd.setCursor(0, 3); lcd.print(" System ");
delay(5000);
Serial.begin(9600);
Read(); // read eeprom fillingtime wil be 0 at the first boot ???
if (fillingtime <= 50) fillingtime = 2500; // make it 2500 miliseconds 2.5 seconds
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
while (digitalRead (button_start) == 0) {
/*nop*/ // while loop as long as button is pressed
}
stop = !stop; // !stop (stop = notstop) toggle the value in stop
delay(500);
startbelttime = millis(); // for timeout stop belt if > 60 seconds
}
lcd.setCursor(0, 0); lcd.print(" EmmerVuller ");
lcd.setCursor(0, 1); lcd.print(" BucketFiller ");
lcd.setCursor(0, 2);
if (stop == 1)lcd.print("Running");
if (stop == 0)lcd.print("Stopped");
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);
if ((millis() / 500) % 2) lcd.print(char(B01011110)); else lcd.print(" ");; // blinking cursor ^
}
if (mode == 3) { // edit fillingtime active print a ^ for selected active for change digit
lcd.setCursor(11, 1);
if ((millis() / 500) % 2) lcd.print(char(B01011110)); else lcd.print(" ");; // blinking cursor ^
}
if (mode == 2) { // edit fillingtime active print a ^ for selected active for change digit
lcd.setCursor(12, 1);
if ((millis() / 500) % 2) lcd.print(char(B01011110)); else lcd.print(" ");; // blinking cursor ^
}
if (mode == 1) { // edit fillingtime active print a ^ for selected active for change digit
lcd.setCursor(13, 1);
if ((millis() / 500) % 2) lcd.print(char(B01011110)); else lcd.print(" ");; // blinking cursor ^
}
}
if (stop == 1) {
if (digitalRead (ir_stop) == 1) {
// analogWrite(beltmotor, 200); // start belt PWM
digitalWrite(beltmotor, beltmotor_run); // start belt Relais
if (digitalRead (ir_fill) == 0) {
startbelttime = millis(); // for timeout stop belt if > 60 seconds
if (stop1 == 0) {
stop1 = 1;
//analogWrite(beltmotor, 0); // stop belt PWM
digitalWrite(beltmotor, !beltmotor_run); // stop belt Relais
delay(200);
lcd.setCursor(0, 2);
lcd.print("water open");
digitalWrite(pump_or_valve, pump_or_valve_run); // start watering pump or open valve
long startmillis = millis();
while (startmillis + fillingtime > millis()) {
lcd.setCursor(0, 2);
lcd.print("water open ");
if (fillingtime - (millis() - startmillis) < 1000)lcd.print(" "); // keep position on the right
if (fillingtime - (millis() - startmillis) < 100)lcd.print(" ");
if (fillingtime - (millis() - startmillis) < 10)lcd.print(" ");
lcd.print(long(fillingtime - (millis() - startmillis))); // show countdown
// lcd.print(" ");
// delay(100);
}
lcd.setCursor(0, 2);
lcd.print(" ");
digitalWrite(pump_or_valve, !pump_or_valve_run); // !=not stop watering pump or close valve
// analogWrite(beltmotor, 200); // start belt PWM
digitalWrite(beltmotor, beltmotor_run); // start belt Relais
}
}
if (digitalRead (ir_start) == 0) {
stop1 = 0;
}
if (millis() - startbelttime >= belttimeout)stop = 0; // timeout belt doing nothing for 600 seconds 10 minutes
Serial.println(millis() - startbelttime);
}
else {
// analogWrite(beltmotor, 0); // stop belt PWM
digitalWrite(beltmotor, !beltmotor_run); // !=not stop belt Relais
delay(300);
}
} else {
// analogWrite(beltmotor, 0); // stop belt PWM
digitalWrite(beltmotor, !beltmotor_run); // !=not stop belt Relais
}
}
// 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);
// https://github.com/ldijkman/Arduino_emmer_vuller_bucket_filling
// would you send me a video link when you got it working????
// https://github.com/ldijkman/Arduino_emmer_vuller_bucket_filling/discussions
// http://paypal.me/LDijkman
}