#define SOIL_SENSOR_PIN 32 // GPIO for Soil Moisture Sensor
#define YELLOW_LED_PIN 15 // GPIO for Yellow LED (Wet soil)
#define GREEN_LED_PIN 12 // GPIO for Green LED (Ideal soil)
#define RED_LED_PIN 14 // GPIO for Red LED (Dry soil)
#define BUZZER_PIN 13 // GPIO for Buzzer
int thresholdLow = 300; // Example threshold for dry soil
int thresholdHigh = 700; // Example threshold for wet soil
void setup() {
Serial.begin(115200);
// Set pin modes for LEDs and buzzer
pinMode(YELLOW_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
int soilMoistureValue = analogRead(SOIL_SENSOR_PIN);
Serial.print("Soil Moisture: ");
Serial.println(soilMoistureValue);
bool buzzerOn = false;
// Control LEDs and buzzer for Soil Moisture Sensor
if (soilMoistureValue < thresholdLow) { // Soil is too dry
digitalWrite(RED_LED_PIN, HIGH); // Red LED on
digitalWrite(GREEN_LED_PIN, LOW); // Green LED off
digitalWrite(YELLOW_LED_PIN, LOW); // Yellow LED off
tone(BUZZER_PIN, 1000); // Buzzer on for soil moisture alert
buzzerOn = true;
} else if (soilMoistureValue > thresholdHigh) { // Soil is too wet
digitalWrite(YELLOW_LED_PIN, HIGH); // Yellow LED on
digitalWrite(RED_LED_PIN, LOW); // Red LED off
digitalWrite(GREEN_LED_PIN, LOW); // Green LED off
noTone(BUZZER_PIN); // Buzzer off
} else { // Soil is in the ideal range
digitalWrite(GREEN_LED_PIN, HIGH); // Green LED on
digitalWrite(RED_LED_PIN, LOW); // Red LED off
digitalWrite(YELLOW_LED_PIN, LOW); // Yellow LED off
noTone(BUZZER_PIN);
}
delay(1000); // Wait for a second before the next reading
}