#include <LiquidCrystal.h>
#include <Servo.h>
// Pin definitions
#define pp 6 // Power pin for the sensor
#define sp A5 // Analog pin connected to the sensor output
int value = 0;
// Initialize the LCD (RS, EN, D4, D5, D6, D7)
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
Servo myServo;
void setup() {
// Initialize LCD with 16 columns and 2 rows
lcd.begin(16, 2);
myServo.attach(5); // Attach servo to pin 6
myServo.write(0); // Start position of the servo
// Set power pin for the sensor as output
pinMode(pp, OUTPUT);
digitalWrite(pp, LOW); // Make sure it's off initially
}
void loop() {
// Power the sensor for a short time to take a reading
digitalWrite(pp, HIGH);
delay(10);
// Read the sensor value
value = analogRead(sp);
// Turn off the sensor power
digitalWrite(pp, LOW);
// Display the sensor value on the LCD
lcd.clear(); // Clear the previous content
lcd.setCursor(0, 0);
lcd.print("Water Level:");
lcd.setCursor(0, 1);
lcd.print("Value: ");
lcd.print(value);
// Wait for 1 second before the next reading
delay(1000);
if(value <= 600) {
myServo.write(90);
}
else{
myServo.write(0);
}
}