Hi!
I want to have an automatic water filler in my brewery.
The setup is going to be:
Motorized ball valve connected to the kitchen tap
Water flow sensor (YF-S201) measuring the amount of water from the ball valve.
A relay-board to open, and to close the ball valve when the flow meter has registered the wanted amount of water.
A pump connected to the water line, driven by the same relay output, if needed (which I don’t believe is necessary)
An arduino MEGA.
There is this other guy who has an automatic water filler set up with a small keyboard and an LCD-screen.
My question is if this is possible to achieve with just using Blynk?
I want a slider to select the wanted amount of water, a value display to show the current amount filled and two buttons; one for starting the filling process and one for stopping/resetting (in case of wrong amount input or other errors).
My coding skills are of a beginner’s…
Can someone please atleast point me in the right direction of how to “virtualize” the code?
Do I still have to use all the cases in the loop?
The code with LCD-screen and keyboard looks like this:
/*
water filler
*/
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
byte Loe[8] = {B00000,B00001,B01110,B10101,B10101,B01110,B10000,B00000}; // norwegian ø
volatile int waterpulse = 0;
int wanted = 0;
int liter = 0;
int litergam = 1;
byte transfr =0;
int watersensor = 2;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','D'},
{'C','0','F','E'}
};
byte rowPins[ROWS] = {4,5,6,7}; //rows to keyboard
byte colPins[COLS] = {8,9,10,11}; //columns for keyboard
//Init class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void rpm () //interrupt function that is called when activity on pin 2.
{
waterpulse++; //counting pulses pin 2.
// add one every time interruption is called. Interruption is called for each increasing pulse on pin 2.
if (waterpulse >= 415) //the sensor is measured at 450 pulses pr. liter. This can be adjusted to calibrate
{liter++;
waterpulse = 0 ;
}
}
void setup()
{
pinMode(watersensor, INPUT); //set digital pin 2 as input.
pinMode(13, OUTPUT); //relay output
attachInterrupt(0,rpm, RISING);
lcd.begin(16,2); // initialize the lcd
lcd.backlight();
lcd.print("Behind Bars"); // Brewery name
lcd.setCursor(0,1);
lcd.print("Brewery");
delay(4000);
lcd.createChar(1, Loe); // definition of norwegian ø
lcd.clear();
lcd.print("Torfinns"); // for commercial matter
lcd.setCursor(0,1);
lcd.print("watermeter");
delay(3000);
lcd.clear();
lcd.print("Antall liter 00");
lcd.setCursor(0,1);
lcd.print("Overf");
lcd.write(1);
lcd.print("rt ");
lcd.setCursor(11,1);
lcd.print(liter);
}
void loop()
{
customKey = customKeypad.getKey();
switch(customKey)
{
case '0' ... '9': // Typing numbers
// lcd.setCursor(0,0);
if (transfr ==0){ //cannot change if transfer has been initiated.
wanted = wanted * 10 + (customKey - '0');
if(wanted>99)
{ wanted=0;}
lcd.clear();
lcd.print("Antall liter");
lcd.setCursor(13,0);
lcd.print(wanted);
}
break;
case 'A': //F1 function button RESET
transfr = 0;
liter = 0;
litergam = 1;
waterpulse =0;
lcd.setCursor(13,0);
lcd.print(" ");
lcd.setCursor(11,1);
lcd.print(" ");
break;
case 'B': //Function button F2 not in use
break;
case 'F': // Stop button, stop transferring
transfr = 0;
break;
case 'E': //Function button F4 not in use
break;
case 'C': // Start button, start transferring the ammount typed in
transfr = 1;
lcd.setCursor(11,1);
lcd.print(" ");
//liter =0;
//waterpulse=0;
break;
}
if (litergam <= liter){ //checking if liter has increased before display is updated
lcd.setCursor(0,1);
lcd.print("Overf");
lcd.write(1); // to get norwegian ø in the display.
lcd.print("rt ");
lcd.setCursor(11,1);
lcd.print(liter);
litergam ++;
}
if (liter >= wanted){
transfr = 0;// stop transfer. ammount achieved.
litergam=1;
liter=0;
}
if (transfr == 1){
digitalWrite(13, LOW);
lcd.setCursor(15,1);
lcd.print("P"); // a P in the display indicates pumping.
} //Open valve.
else {
digitalWrite(13, HIGH); //close valve.
lcd.setCursor(15,1);
lcd.print(" ");
}
}