#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust the address to 0x27 or 0x3F if needed
const int moisturePins[4] = {A0, A1, A2, A3};
int moistureReadings[4];
int avgMoisture;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.backlight();
}
void loop() {
int totalMoisture = 0;
// Read and map each moisture sensor value to percentage
for (int i = 0; i < 4; i++) {
moistureReadings[i] = analogRead(moisturePins[i]);
int moisturePercentage = map(moistureReadings[i], 0, 1023, 100, 0); // Map to 0-100%, adjust if needed
totalMoisture += moisturePercentage;
}
// Calculate average moisture as percentage
avgMoisture = totalMoisture / 4;
// Display average moisture percentage on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Avg Moisture:");
lcd.setCursor(0, 1);
lcd.print(avgMoisture);
lcd.print("%");
// Send average moisture as percentage to S Arduino
Serial.write(avgMoisture);
delay(1000); // Update every second
}