#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 2 // DHT22 pin
#define MOISTURE_PIN_1 A0 // First potentiometer for soil moisture
#define MOISTURE_PIN_2 A1 // Second potentiometer for another soil moisture
#define LED_PIN 3 // LED pin
#define BUZZER_PIN 4 // Buzzer pin
DHT dht(DHTPIN, DHT22);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust the address as necessary
void setup() {
Serial.begin(9600);
dht.begin();
lcd.begin(16, 2); // Set the number of columns and rows
lcd.backlight();
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
// Read DHT22
float h = dht.readHumidity();
float t = dht.readTemperature();
// Read soil moisture
int moistureLevel1 = analogRead(MOISTURE_PIN_1);
int moistureLevel2 = analogRead(MOISTURE_PIN_2);
// Display readings on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(t);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Moisture 1: ");
lcd.print(moistureLevel1);
// Alerts
if (moistureLevel1 < 300 || moistureLevel2 < 300) {
digitalWrite(LED_PIN, HIGH);
tone(BUZZER_PIN, 1000);
} else {
digitalWrite(LED_PIN, LOW);
noTone(BUZZER_PIN);
}
// Wait before the next loop
delay(2000);
}