The sensor collects the data and sends it to the Arduino and then it gives the desired signal to the pumps. I can set our given level from the code. If the level crosses the given threshold the pump in the tank is given a signal and it starts to pump the fluid out of the tank until its under the threshold. When the level drops below the threshold above, the pump in the reservoir will start pumping the liquid to the tank. Only the tank and one pump are used.The flow chart below explain the process of software steps and the code which I need .
#include
<LiquidCrystal.h>
int pos = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int trigPin = 9;
const int echoPin = 10;
const int buzz = 6;
const int P = 7;
long duration;
int distance;
int FTH = 30;
void setup()
{ lcd.begin(16, 2);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("FUEL TANK H=");
lcd.print(FTH);
lcd.print("CM");
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration*0.034/2;
int h = FTH-distance;
Serial.println(h);
delay(500);
lcd.setCursor(11,1);
lcd.print(h);
lcd.print("CM ");
int x = h;
if(h < = 10&&h > = 5)
{
analogWrite(buzz,200);
digitalWrite(P,HIGH);
lcd.setCursor(0,0);
lcd.print("FUEL TANK H=");
lcd.print(FTH);
lcd.print("CM ");
delay(1000);
Serial.println("PUMP ON");
lcd.setCursor(0,1);
lcd.print("PUMP ON ");
analogWrite(buzz,200);
digitalWrite(P,HIGH);
}
else if(x = = 10)
{
for(x = 10;x < = 27;x++)
{
lcd.setCursor(0,1);
lcd.print("PUMP ON ");
}
digitalWrite(P,HIGH);
}
else if(h > 10&&h < 27)
{
analogWrite(buzz,0);
}
else if(x = = 27)
{
for(x = 25;x > = 10;x–)
{
lcd.setCursor(0,1);
lcd.print(" ");
}
analogWrite(buzz,0);
}
else if(x = = 27)
{
lcd.print("PUMP OFF");
analogWrite(buzz,200);
}
else if(h > = 27&&h < = 30)
{
analogWrite(buzz,200);
digitalWrite(P,LOW);
lcd.setCursor(0,0);
lcd.print("FUEL TANK H=");
lcd.print(FTH);
lcd.print("CM ");
delay(500);
Serial.println("PUMP OFF");
lcd.setCursor(0,1);
lcd.print("PUMP OFF");
}
}