#define POWER_PIN 15 // ESP32 pin GPIO15 connected to sensor's VCC pin
#define SIGNAL_PIN 2 // ESP32 pin GPIO2 (ADC0) connected to sensor's signal pin
float value = 0; // variable to store the sensor value
void setup() {
Serial.begin(9600);
pinMode(POWER_PIN, OUTPUT); // configure pin as an OUTPUT
digitalWrite(POWER_PIN, LOW); // turn the sensor OFF
}
void loop() {
digitalWrite(POWER_PIN, HIGH); // turn the sensor ON
delay(10); // wait 10 milliseconds
value = analogRead(SIGNAL_PIN); // read the analog value from sensor
digitalWrite(POWER_PIN, LOW); // turn the sensor OFF
Serial.print("The water level: ");
Serial.print(value/4095*10,1);
Serial.println("/10");
if (value < 100)
Serial.println("tank is almost empty");
else if (value <2050)
Serial.println("tank is almost half");
else if (value > 4090)
Serial.println("tank is almost full");
delay(1000);
}