#define moisturePin A0
#define relayPin 2
int humidityRate = 30;
void setup() {
pinMode(moisturePin, INPUT);
pinMode(relayPin, OUTPUT);
}
void loop() {
int moisture = map(analogRead(moisturePin), 280, 640, 100, 0);
if (moisture <= humidityRate) {
digitalWrite(relayPin, 1);
} else {
digitalWrite(relayPin, 0);
}
delay(300);
}