Meta Title: How to Make an Automatic Livestock Watering System Using ESP32 and IoT
Meta Description: Learn how to build an Automatic Livestock Watering System using ESP32, water level sensors, ultrasonic sensors, relays, and IoT technology. Includes wiring diagrams, BOM tables, working principles, flowcharts, troubleshooting, and agricultural applications.
Providing clean and adequate drinking water is essential for livestock productivity. However, manually monitoring water troughs can be labor-intensive and may lead to water shortages, dehydration, reduced milk production, and poor animal health.
This project demonstrates how to make an Automatic Livestock Watering System that automatically monitors water levels and refills animal drinking troughs whenever the water becomes low.
This project combines Agriculture, Engineering, IoT, ICT, and Applied Technology, making it an excellent KSEF and STEM competition project.
Quick Answer: Automatic Livestock Watering Wiring Diagram
| Component | Pin | ESP32 Pin |
|---|---|---|
| Ultrasonic Sensor Trigger | TRIG | GPIO5 |
| Ultrasonic Sensor Echo | ECHO | GPIO18 |
| Float Sensor | Signal | GPIO19 |
| Relay Module | IN | GPIO23 |
| OLED Display SDA | SDA | GPIO21 |
| OLED Display SCL | SCL | GPIO22 |
| Buzzer | Positive | GPIO4 |
| GSM Module TX | TX | GPIO16 |
| GSM Module RX | RX | GPIO17 |
System Workflow
Water Tank → Sensors → ESP32 → Relay → Water Pump → Livestock Trough
7
Why Build an Automatic Livestock Watering System?
Livestock require a constant supply of clean water.
Water shortages may result in:
- Reduced milk production
- Poor growth rates
- Stress and dehydration
- Reduced reproduction efficiency
- Increased disease risks
This system automatically maintains water availability.
Objectives of the Project
- Monitor livestock water levels.
- Automatically refill drinking troughs.
- Reduce labor requirements.
- Prevent water wastage.
- Send alerts to farmers.
Bill of Materials (BOM)
| Component | Quantity | Purpose |
|---|---|---|
| ESP32 Development Board | 1 | Main controller |
| Ultrasonic Sensor HC-SR04 | 1 | Measures water level |
| Float Sensor | 1 | Backup level detection |
| Relay Module | 1 | Controls pump |
| Submersible Water Pump | 1 | Pumps water |
| OLED Display | 1 | Displays status |
| GSM Module SIM800L | 1 | Sends alerts |
| Piezo Buzzer | 1 | Audible warning |
| Jumper Wires | Several | Connections |
| Water Tank | 1 | Water storage |
| Livestock Trough | 1 | Drinking container |
| Solar Panel (Optional) | 1 | Renewable power |
Estimated Project Cost
| Item | Approximate Cost |
|---|---|
| ESP32 | $8 |
| Ultrasonic Sensor | $3 |
| Relay Module | $2 |
| Water Pump | $8 |
| GSM Module | $8 |
| Miscellaneous | $15 |
Estimated Total Cost: $40–50
Components Overview
4
Key Features
✅ Automatic water refilling
✅ Real-time water level monitoring
✅ SMS alerts
✅ Overflow prevention
✅ Solar-powered operation
✅ Low-cost farm automation
✅ IoT dashboard integration
Block Diagram
Water Tank
↓
Ultrasonic Sensor
↓
ESP32 Controller
↓
Relay Module
↓
Water Pump
↓
Livestock Trough
4
Circuit Connections Explained
HC-SR04 Ultrasonic Sensor
- VCC → 5V
- GND → GND
- TRIG → GPIO5
- ECHO → GPIO18
Float Sensor
- Signal → GPIO19
Relay Module
- IN → GPIO23
OLED Display
- SDA → GPIO21
- SCL → GPIO22
GSM Module
- TX → GPIO16
- RX → GPIO17
Alarm
- Buzzer → GPIO4
Step-by-Step Guide: How to Make an Automatic Livestock Watering System
Step 1: Assemble the Circuit
Connect all sensors, relay modules, displays, and GSM modules according to the wiring table.
Step 2: Install Sensors
Install:
- Ultrasonic sensor above the trough.
- Float switch inside the trough.
Ensure accurate water level measurements.
Step 3: Install Water Pump
Connect the water pump to:
- Main water tank
- Livestock drinking trough
Step 4: Upload the ESP32 Program
The ESP32 should:
- Measure water levels.
- Activate the pump.
- Display information.
- Send notifications.
Example logic:
IF Water Level < Minimum
Turn Pump ON
Display "Refilling"
IF Water Level = Full
Turn Pump OFF
Step 5: Test the System
Verify:
- Water level detection
- Automatic pump operation
- SMS alerts
- Overflow prevention
6
Working Principle
The ultrasonic sensor continuously measures the distance to the water surface.
The ESP32 calculates the water level.
If the level falls below a predefined threshold:
- Relay activates.
- Water pump starts.
- Trough refills automatically.
- Pump stops when the trough becomes full.
This creates a fully automated watering process.
System Flowchart
START
↓
Read Water Level
↓
Water Low?
↓
YES
↓
Turn Pump ON
↓
Monitor Water Level
↓
Water Full?
↓
YES
↓
Turn Pump OFF
↓
Repeat Monitoring
Applications
This project can be used in:
- Dairy farms
- Poultry farms
- Goat farms
- Sheep farms
- Pig farms
- Wildlife conservation centers
- Animal research facilities
Advantages
✔ Saves labor
✔ Prevents animal dehydration
✔ Reduces water wastage
✔ Improves animal productivity
✔ Suitable for remote farms
✔ Can be solar powered
Limitations
- Requires stable power supply.
- Sensors require periodic cleaning.
- GSM requires network coverage.
Future Improvements
You can improve the project by adding:
AI Prediction
Predict livestock water consumption patterns.
Mobile Application
Monitor farms remotely.
Solar Power System
Create a fully autonomous farm system.
RFID Animal Monitoring
Track water intake of individual animals.
Cloud Dashboard
Store historical farm data.
How to Fix Common ESP32 Upload Errors
Error: ESP32 Not Uploading
Solutions
- Hold BOOT button.
- Verify COM port.
- Update USB drivers.
Error: Ultrasonic Sensor Gives Incorrect Readings
Solutions
- Clean sensor surface.
- Reduce water splashes.
- Verify mounting distance.
Error: Pump Not Operating
Solutions
- Check relay wiring.
- Verify external power supply.
- Inspect pump connections.
Error: GSM Module Cannot Send SMS
Solutions
- Verify SIM card activation.
- Use stable external power.
- Check signal strength.
Real Project Photo
6
Featured Images Required for Blog
1. Components Image
- ESP32 Board
- Ultrasonic Sensor
- Float Sensor
- Water Pump
- Relay Module
- GSM Module
2. Features Illustration
- Automatic refilling
- SMS alerts
- Water monitoring
- Solar-powered operation
3. Block Diagram
Sensors → ESP32 → Relay → Pump → Livestock Trough
4. Working Principle Diagram
Water Level Detection → Pump Activation → Automatic Refill
5. Circuit Diagram
Complete ESP32 wiring layout.
6. Flowchart
System operation process.
7. Real Prototype Image
Fully assembled automatic livestock watering model.
Final Thoughts
Learning how to make an Automatic Livestock Watering System is an excellent project that combines:
✅ Agriculture
✅ Engineering
✅ IoT
✅ ICT
✅ Applied Technology
✅ Environmental Conservation




