#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#define SOIL_PIN A0
#define BUZZER_PIN 8
#define SERVO_PIN 9
#define DRY_THRESHOLD 600
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo valve;
void setup() {
pinMode(BUZZER_PIN, OUTPUT);
valve.attach(SERVO_PIN);
lcd.init();
lcd.backlight();
lcd.print("Plant Guardian");
delay(1500);
lcd.clear();
}
void loop() {
int moisture = analogRead(SOIL_PIN);
lcd.setCursor(0, 0);
lcd.print("Level: ");
lcd.print(moisture);
lcd.print(" ");
lcd.setCursor(0, 1);
if (moisture > DRY_THRESHOLD) {
lcd.print("Status: DRY!");
tone(BUZZER_PIN, 1000);
valve.write(90);
} else {
lcd.print("Status: OK ");
noTone(BUZZER_PIN);
valve.write(0);
}
delay(500);
}