JACK
Published

Water Level Detection System Using ESP32

In this Article, we learn about how to make Water Level Detection System Using ESP32.

ExpertFull instructions provided5 hours1,661
Water Level Detection System Using ESP32

Things used in this project

Hardware components

ESP32
Espressif ESP32
×1
Grove - Relay
Seeed Studio Grove - Relay
×1
DC motor (generic)
×1
Samsung SmartThings Water Leak Sensor
Samsung SmartThings Water Leak Sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Diagram

Code

Program code

C/C++
#define RELAY_PIN   13  // The ESP32 pin GPIO13 that connects to the relay to control the pump
#define POWER_PIN   32  // The ESP32 pin GPIO32 that provides the power to the water sensor
#define SIGNAL_PIN  34  // The ESP32 pin GPIO36 that reads the value from the water sensor

#define THRESHOLD   1000 // The threshold for water detectiion

void setup() {
  Serial.begin(9600);
  pinMode(RELAY_PIN,   OUTPUT); // configure D2 pin as an OUTPUT
  pinMode(POWER_PIN, OUTPUT);   // configure D7 pin as an OUTPUT
  digitalWrite(POWER_PIN, LOW); // turn the water sensor OFF
  digitalWrite(RELAY_PIN, LOW); // turn the pump OFF
}

void loop() {
  digitalWrite(POWER_PIN, HIGH);  // turn the water sensor's power  ON
  delay(10);                      // wait 10 milliseconds
  int value = analogRead(SIGNAL_PIN); // read the analog value from sensor
  digitalWrite(POWER_PIN, LOW);   // turn the water sensor's power OFF

  if (value < THRESHOLD) {
    Serial.print("The water is detected");
    digitalWrite(RELAY_PIN, LOW);  // turn the pump ON
  } else {
    digitalWrite(RELAY_PIN, HIGH);   // turn the pump OFF
  }

  delay(1000); // pause for 1 sec to avoid reading sensors frequently to prolong the sensor lifetime
}

Credits

JACK
21 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.