const int moisturePin = A0; // Analog pin for soil moisture sensor
const int redLEDPin = 2; // Digital pin for red LED
const int yellowLEDPin = 3; // Digital pin for yellow LED
const int greenLEDPin = 4; // Digital pin for green LED
const int thresholdLow = 300; // Adjust this threshold for your specific sensor
const int thresholdMedium = 600;
const int thresholdHigh = 800;
void setup() {
pinMode(redLEDPin, OUTPUT);
pinMode(yellowLEDPin, OUTPUT);
pinMode(greenLEDPin, OUTPUT);
Serial.begin(9600); // Initialize serial communication for debugging (optional)
}
void loop() {
int moistureValue = analogRead(moisturePin); // Read moisture level
if (moistureValue <= thresholdLow) {
// Low moisture level
digitalWrite(redLEDPin, HIGH);
digitalWrite(yellowLEDPin, LOW);
digitalWrite(greenLEDPin, LOW);
} else if (moistureValue <= thresholdMedium) {
// Medium moisture level
digitalWrite(redLEDPin, LOW);
digitalWrite(yellowLEDPin, HIGH);
digitalWrite(greenLEDPin, LOW);
} else if (moistureValue <= thresholdHigh) {
// High moisture level
digitalWrite(redLEDPin, LOW);
digitalWrite(yellowLEDPin, LOW);
digitalWrite(greenLEDPin, HIGH);
}
// For debugging, you can print the moisture value to the serial monitor
Serial.print("Moisture Level: ");
Serial.println(moistureValue);
delay(1000); // Delay for stability (adjust as needed)
}