#define sensorPin 34
#define relayPin 8
void setup() {
Serial.begin(115200);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
}
void loop() {
int sensorValue = analogRead(sensorPin);
int moisturePercent = map(sensorValue, 0, 4095, 100, 0);
Serial.print("Moisture: ");
Serial.print(moisturePercent);
Serial.print("%");
if (moisturePercent < 30) {
digitalWrite(relayPin, HIGH);
Serial.println("Pump ON");
} else {
digitalWrite(relayPin, LOW);
Serial.println("Pump OFF");
}
delay(1000); // this speeds up the simulation
}