#define soilSensor A0
#define pumpRelay 4
int upperThresshold = 80;
int lowerThresshold = 40;
void setup() {
Serial.begin(115200);
pinMode(soilSensor, INPUT);
pinMode(pumpRelay, OUTPUT);
}
void loop() {
float sensorValue = analogRead(soilSensor);
Serial.println(sensorValue);
int valMap = map(sensorValue, 0, 1023, 0, 100);
Serial.print("mosture: ");
Serial.println(valMap);
if (valMap < lowerThresshold) {
digitalWrite(pumpRelay, HIGH);
} else if(valMap > upperThresshold) {
digitalWrite(pumpRelay, LOW);
}
delay(200);
}