#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int potPin = A1; // Analog pin for potentiometer
const int ledPin = 2; // Digital pin for the LED
void setup() {
lcd.begin(16, 2);
lcd.backlight();
pinMode(potPin, INPUT); // Set potentiometer pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600);
}
void loop() {
int potValue = analogRead(potPin);
int moistureLevel = map(potValue, 0, 1023, 0, 100);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Moist:");
lcd.setCursor(6, 0);
lcd.print(moistureLevel);
lcd.print("%");
// Turn off the LED initially
digitalWrite(ledPin, LOW);
// Turn on the LED if the potentiometer value indicates low moisture
if (moistureLevel < 30) {
digitalWrite(ledPin, HIGH); // Moisture LED indication
}
Serial.print("Moisture Level: ");
Serial.print(moistureLevel);
Serial.println("%");
delay(1000);
}