Good afternoon, I watered my home greenhouse, but I ran into such a problem that I can’t divide the different flow rates into two buttons (so that when you press the first button, one volume is filled, and when you press the second, another volume
I use one water flow sensor and one pump with a relay
here is the sketch
#define button_pin 3
#define relay_pin 6
#define button_pinnn 7
boolean butt_flag = 0;
boolean butt;
boolean flag = 0;
boolean butt_flagg = 0;
boolean buttt;
boolean flagg = 0;
unsigned long last_press;
volatile double waterFlow;
void setup() {
Serial.begin(9600); //baudrate
pinMode(button_pin, INPUT_PULLUP);
pinMode(button_pinnn, INPUT_PULLUP);
pinMode(relay_pin, OUTPUT);
attachInterrupt(0, pulse, FALLING); //DIGITAL Pin 2: Interrupt 0
waterFlow = 0.000;
}
void pulse() //measure the quantity of square wave
{
waterFlow += 1.0 / 3510.0;
}
void loop() {
butt = !digitalRead(button_pin);
if (butt == 1 && butt_flag == 0 && millis() - last_press > 1000) {
butt_flag = 1;
flag = !flag;
last_press = millis();
digitalWrite(relay_pin, flag);
}
if (butt == 0 && butt_flag == 1) {
butt_flag = 0;
}
if(waterFlow < 0.4){
Serial.print("waterFlow:");
Serial.print(waterFlow);
Serial.println(" L");
delay(1000);
}
else {
digitalWrite(relay_pin, 0);
waterFlow = 0.000;
}
butt = !digitalRead(button_pinnn);
if (butt == 1 && butt_flag == 0 && millis() - last_press > 1000) {
butt_flag = 1;
flag = !flag;
last_press = millis();
digitalWrite(relay_pin, flag);
}
if (butt == 0 && butt_flag == 1) {
butt_flag = 0;
}
if(waterFlow < 0.5){
Serial.print("waterFlow:");
Serial.print(waterFlow);
Serial.println(" L");
delay(1000);
}
else {
digitalWrite(relay_pin, 0);
waterFlow = 0.000;
}
}