π§ Project Overview
In this lesson, we will connect an Ultrasonic Sensor with ESP32 to measure water level in a tank and control a water pump using a relay.
This system will:
-
Measure water level using ultrasonic distance
-
Detect LOW and FULL tank condition
-
Control motor automatically
-
Prevent overflow
-
Prevent dry running
π¦ Components Used in This Project
-
Main microcontroller
-
Reads ultrasonic data
-
Controls relay
-
Handles automation logic
πΉ 2οΈβ£ HC-SR04 Ultrasonic Sensor
-
Measures distance to water surface
-
Calculates water level
-
Non-contact measurement
πΉ 3οΈβ£ Single Channel Relay Module
-
Controls high voltage motor
-
Electrically isolates ESP32
πΉ 4οΈβ£ DC Water Pump
-
Pumps water into tank
-
Controlled via relay
πΉ 5οΈβ£ 12V Power Supply
-
Powers water pump
-
External supply required
π Circuit Connections
πΉ Ultrasonic Sensor β ESP32
| Ultrasonic Pin | ESP32 Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| Trig | GPIO 5 |
| Echo | GPIO 18 |
β IMPORTANT:
Echo pin gives 5V output.
Use a voltage divider (10k + 20k resistor) to reduce to 3.3V for ESP32 safety.
πΉ Relay Module β ESP32
| Relay Pin | ESP32 |
|---|---|
| VCC | 5V |
| GND | GND |
| IN | GPIO 26 |
β Relay Active LOW
LOW β Motor ON
HIGH β Motor OFF
πΉ Relay β DC Pump Wiring
| Relay Terminal | Connection |
|---|---|
| COM | 12V Supply + |
| NO | Pump + |
| Pump – | 12V Supply – |
When relay activates:
COM connects to NO β Pump turns ON
π How Ultrasonic Sensor Measures Water Level
1οΈβ£ Sensor sends ultrasonic pulse
2οΈβ£ Pulse hits water surface
3οΈβ£ Echo returns
4οΈβ£ ESP32 calculates distance
Formula used:
If tank height = 30 cm:
Water Level = Tank Height β Measured Distance
Example:
| Distance | Tank Condition |
|---|---|
| 25 cm | Tank Low |
| 5 cm | Tank Full |
β‘ Power Distribution
-
ESP32 powered by USB
-
Ultrasonic powered by 5V
-
Relay powered by 5V
-
Pump powered by 12V external supply
β Always connect all GND together (Common Ground)
π¨ Important Safety Notes
β Use voltage divider for Echo pin
β Never connect pump directly to ESP32
β Use proper insulated wiring
β Keep ultrasonic sensor dry
β Mount sensor firmly at tank top
π― What Students Learn in This Lesson
-
Ultrasonic sensor interfacing
-
Distance measurement concept
-
Relay module wiring
-
Motor control circuit
-
Power isolation
-
Industrial-style wiring
π Lesson Summary
In this lesson, we successfully:
-
Connected HC-SR04 ultrasonic sensor with ESP32
-
Connected relay module safely
-
Designed pump control circuit
-
Built a complete hardware foundation for Smart Water Management System
This makes the system:
β More accurate
β Non-contact measurement
β Industry-ready
β Long-lasting solution