Hi,
I need a help as I am already scrolling a lot of posts already I can not find my project to work.
I have a basic project with a ultrasonic water level monitor and pump running water from 1 tank below to 2nd tank on top of each other. Water level in top tank hit some level than pump is turned off and water slowly drips down to lower tank until sensor in the top tank reads low water level and pump is ON again.
Basically i want this process to repeat 3 times and then I need pump to work for a bit longer to reach highest level in the top tank and then pump is switched off and LCD shows ALARM, WATER TANK OVERFLOW.
I have tried couple different ways with this code:
for (i = 0; i < n; i++)
but it does not work for me.
I need this process: if(distance<6) , else if(distance>8) to be repeated 3 times and then last else if(distance>4) would finish my program.
#include <LiquidCrystal.h>
#define trigger 9
#define echo 8
#define motor A0
#include <SoftwareSerial.h>
SoftwareSerial BTserial(7, 6); // RX | TX
LiquidCrystal lcd(12,11,5,4,3,2);
float time=0,distance=0;
void setup()
{
lcd.begin(16,2);
pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
pinMode(motor, OUTPUT);
lcd.print(" Water Level “);
lcd.setCursor(0,1);
lcd.print(” Indicator ");
delay(2000);
BTserial.begin(9600);
}
void loop()
{
lcd.clear();
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH);
distance=time*340/20000;
lcd.clear();
lcd.print("Water Space In ");
lcd.setCursor(0,1);
lcd.print("Tank is: ");
lcd.print(distance);
lcd.print(“Cm”); delay(2000);
if(distance<6)
{
digitalWrite(motor, LOW);
lcd.clear();
lcd.print("Water Tank Full ");
lcd.setCursor(0,1);
lcd.print(“Motor Turned OFF”);
delay(2000);
}
else if(distance>8)
{
digitalWrite(motor, HIGH);
lcd.clear();
lcd.print(“LOW Water Level”);
lcd.setCursor(0,1);
lcd.print(“Motor Turned ON”);
delay(2000);
}
else if(distance<4)
{
digitalWrite(motor, LOW);
lcd.clear();
lcd.print(“ALARM TANK OVERFLOW”);
lcd.setCursor(0,1);
lcd.print(“Motor Turned OFF”);
delay(2000);
}
{
BTserial.print(“1234”);
BTserial.print(",");
delay(20);
}
}
Anybody can help mi this one?
Peter
project_Arduino.ino (1.6 KB)