Using button for stop loop

Here I am working on a water level controller, in this section > `{

digitalWrite(buz,HIGH);
delay(500);
digitalWrite(buz,LOW);
}` I have to add code to add a Momentory button so that this function starts again only if this

if(f <v && t <v && h <v && q <v)

condition starts again.
please help me.

#include <LiquidCrystal.h>
int sump=A0;
int qut=A1;
int hlf=A2;
int thf=A3;
int ful=A4;
int motor=8;
int buz=7;
int s;
int q;
int h;
int t;
int f;
int i; //motor status flag
int v=100; //comparison variable(needs some adjustment)
int b=0; //buzzer flag
int m=0; //motor flag
int c=0; //sump flag

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{

pinMode(qut,INPUT);
pinMode(hlf,INPUT);
pinMode(qut,INPUT);
pinMode(ful,INPUT);
pinMode(sump,INPUT);
pinMode(motor,OUTPUT);
pinMode(buz,OUTPUT);
lcd.begin(16, 2);
digitalWrite(buz,LOW);
}

void loop()
{

i=digitalRead(motor);
s=analogRead(sump);
q=analogRead(qut);
h=analogRead(hlf);
t=analogRead(thf);
f=analogRead(ful);
lcd.clear();

if(f>v && t>v && h>v && q>v )
{
lcd.setCursor(0,0);
lcd.print(char(219));
lcd.print(char(219));
lcd.print(char(219));
lcd.print(char(219));
lcd.setCursor(5,0);
lcd.print("FULL");
m=1;
b=0;
}
else
{
if(f<v && t>v && h>v && q>v)
{
lcd.setCursor(0,0);
lcd.print(char(219));
lcd.print(char(219));
lcd.print(char(219));
lcd.print("");
lcd.setCursor(5,0);
lcd.print("3/4th");
m=0;
b=0;
}
else
{
if(f<v && t<v && h>v && q>v)
{
lcd.setCursor(0,0);
lcd.print(char(219));
lcd.print(char(219));
lcd.print("
");
lcd.print("");
lcd.setCursor(5,0);
lcd.print("HALF");
m=0;
b=0;
}
else
if(f<v && t<v && h<v && q>v)
{
lcd.setCursor(0,0);
lcd.print(char(219));
lcd.print("
");
lcd.print("");
lcd.print("
");
lcd.setCursor(5,0);
lcd.print("1/4th");
m=0;
b=0;
}
else
{
if(f<v && t<v && h<v && q<v)
{
lcd.setCursor(0,0);
lcd.print("");
lcd.print("
");
lcd.print("");
lcd.print("
");
lcd.setCursor(5,0);
lcd.print("LOW");
m=0;
b=1;

}
else

{
digitalWrite(motor,LOW);
lcd.setCursor(0,0);
lcd.print("ERROR!");
//b=1;
}
}}}
if(i==HIGH)
{
lcd.setCursor(0,1);
lcd.print("Motor Off");
}
else
{
lcd.setCursor(0,1);
lcd.print("Motor ON");
}

if(s>v && m==1)
{
digitalWrite(motor,HIGH);
}
if(s<v)
{
digitalWrite(motor,LOW);
lcd.setCursor(11,0);
lcd.print("Low");
lcd.setCursor(11,1);
lcd.print("Sump");
c=1;
}
if(s>v)
{
c=0;
}

if(m==0)
{
digitalWrite(motor,LOW);
}

if(b==1 || c==1)
{
digitalWrite(buz,HIGH);
delay(500);
digitalWrite(buz,LOW);
}
else
{
digitalWrite(buz,LOW);
}
delay(100);
lcd.clear();
}

Yikkes! Single letter variables? The year is 2021. Even FORTRAN, dating back to 1953, had six letter named variables.

Please start your journey in learning how to program by using variable names that can be read by humans that provide information about their usage and purpose.

Once you do that, others can then both read and understand your code which is necessary to provide help.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.