const int potPin = 34; // Pin for potentiometer
const int ldrPin = 32; // Pin for LDR
const int ledPin = 25; // Pin for LED
const int buzzer = 27; // Pin for Buzzer
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(buzzer, OUTPUT);
}
void loop() {
// Read potentiometer value (simulate soil moisture)
int moistureValue = analogRead(potPin);
// Read LDR value (simulate light level)
int lightValue = analogRead(ldrPin);
if (lightValue >= 2045) {
digitalWrite(ledPin, HIGH); // Turn on the LED
Serial.print("LED ON - ");
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
Serial.print("LED OFF - ");
}
// Check moistureValue and control the buzzer
if (moistureValue >= 1023 && moistureValue <= 3072) {
noTone(buzzer); // Turn off buzzer sound
Serial.print("BUZZER OFF - ");
}
else {
tone(buzzer, 1000); // Generate a sound
Serial.print("BUZZER ON - ");
}
// Print values to Serial Monitor on a single line
Serial.print("Moisture: ");
Serial.print(moistureValue);
Serial.print(" - Light: ");
Serial.println(lightValue);
delay(1000); // Delay for readability
}