const int sensorPin = A0; // Analog pin to read the sensor data
int sensorValue = 0; // Variable to store the sensor value
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Read the sensor value
sensorValue = analogRead(sensorPin);
// Convert the sensor value to a percentage
int waterLevel = map(sensorValue, 0, 1023, 0, 100);
// Display the water level on the Serial Monitor
Serial.print("Water level: ");
Serial.print(waterLevel);
Serial.println("%");
if (waterLevel <= 20) {
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
// Wait for 500 milliseconds before reading the sensor again
delay(500);
}