hello,
I am trying to program an automatic water level controller. I have used two arduino modules. One for the sensor side and another for the control side. The program for the control side:
#include <LiquidCrystal.h>
#define echo 0
#define motor 8
#define buzzer 12
LiquidCrystal lcd(2,3,4,5,6,7);
float distance=0;
int temp=0;
void setup()
{
lcd.begin(16,2);
pinMode(echo,INPUT);
pinMode(motor, OUTPUT);
pinMode(buzzer, OUTPUT);
lcd.print(" Water Level ");
lcd.setCursor(0,1);
lcd.print(" Indicator ");
Serial.begin(9600);
delay(2000);
}
void loop()
{
while(Serial.available()>0){
distance=Serial.parseFloat()-'0';}
lcd.clear();
lcd.print("Water Space In ");
lcd.setCursor(0,1);
lcd.print("Tank is: ");
lcd.print(distance);
lcd.print("Cm");
delay(1000);
if(distance<12 && temp==0)
{
digitalWrite(motor, LOW);
digitalWrite(buzzer, HIGH);
lcd.clear();
lcd.print("Water Tank Full ");
lcd.setCursor(0,1);
lcd.print("Motor Turned OFF");
delay(2000);
digitalWrite(buzzer, LOW);
delay(3000);
temp=1;
}
else if(distance<12 && temp==1)
{
digitalWrite(motor, LOW);
lcd.clear();
lcd.print("Water Tank Full ");
lcd.setCursor(0,1);
lcd.print("Motor Turned OFF");
delay(5000);
}
else if(distance>30)
{
digitalWrite(motor, HIGH);
lcd.clear();
lcd.print("LOW Water Level");
lcd.setCursor(0,1);
lcd.print("Motor Turned ON");
delay(5000);
temp=0;
}
}
The void loop is not looping. i get only one distance from the ultrasonic sensor. when the distance changes, it is not reflected on the code. can anyone guide me where i have gone wrong. Thanks in advance
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.