How to Make an Automatic Livestock Watering System

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

ComponentPinESP32 Pin
Ultrasonic Sensor TriggerTRIGGPIO5
Ultrasonic Sensor EchoECHOGPIO18
Float SensorSignalGPIO19
Relay ModuleINGPIO23
OLED Display SDASDAGPIO21
OLED Display SCLSCLGPIO22
BuzzerPositiveGPIO4
GSM Module TXTXGPIO16
GSM Module RXRXGPIO17

System Workflow

Water Tank → Sensors → ESP32 → Relay → Water Pump → Livestock Trough


https://images.openai.com/static-rsc-4/hN4eBj2QkCbgGV5TnWOGU_UkKpf4bxtlWJaWzAGKT5aAp_I-9eKhTR9zmf_n5a1DHFrOxP5byEKA5ssNjVovmw6jLhcdU-vLBKX_LYk4Tzg49O6o6Si9Ieoh6jKoCi30WSOGueWNOvOe0ElMyEyH3kzhPQOdoSfCK2sY4e4lWbSJiebQ1qKSdEETmICBSwYI?purpose=fullsize
https://images.openai.com/static-rsc-4/xDE_ViErXa3nRIbggEH0o0xWJKEhzmJYUfmhDyQRvYjL3wk4RxYOzT-4SCnAug6tdqqvbsf2uaRi8GzTr_GJ5LTf6g_ZcWs3ZOUJ1BNJZgpbB7IGWqz0cwbKRIyPEd6M4zaAZ_Z5XyJW3NFig3cTBBrhgF9KLbChmVy6jFHIdncLSn0_9RMZ4RzwW5cLOVkY?purpose=fullsize
https://images.openai.com/static-rsc-4/TuXR3jILs4u0pkm0r9JjTZaSOtchTX8gBISTOHgzsZKXCfpGWhgovzk6EBZlDTZe4V5-NtK5zmG7wTkr4EpDgHi64BIBwFpeDnX09oziszKOl8knh0N27o3_u9KudJ56xROE9W8VIJWbTdHJ_oxUNxr5FTD6uPdX60KMHJT2NurzcqRDi0bI6tpU1tGDq6wT?purpose=fullsize

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

  1. Monitor livestock water levels.
  2. Automatically refill drinking troughs.
  3. Reduce labor requirements.
  4. Prevent water wastage.
  5. Send alerts to farmers.

Bill of Materials (BOM)

ComponentQuantityPurpose
ESP32 Development Board1Main controller
Ultrasonic Sensor HC-SR041Measures water level
Float Sensor1Backup level detection
Relay Module1Controls pump
Submersible Water Pump1Pumps water
OLED Display1Displays status
GSM Module SIM800L1Sends alerts
Piezo Buzzer1Audible warning
Jumper WiresSeveralConnections
Water Tank1Water storage
Livestock Trough1Drinking container
Solar Panel (Optional)1Renewable power

Estimated Project Cost

ItemApproximate Cost
ESP32$8
Ultrasonic Sensor$3
Relay Module$2
Water Pump$8
GSM Module$8
Miscellaneous$15

Estimated Total Cost: $40–50


Components Overview

https://images.openai.com/static-rsc-4/fsNqsxc50Fuyl0V-SqA2uDM4F4axZp7Uuuq7jzy_Osg4TteQOmEHiJtv8MwhiWgnpCrINMthxctiIc0iIOotK2Ui6KdB3QLkPXykL7JRUHvIqT0dGCunukvC5-T2li3V_VDJzMtqCrtkIq-_iLDvSILB4o9f_pPJmtG372FKR43QZ4r4DjCoMv3FntBRIy0o?purpose=fullsize
https://images.openai.com/static-rsc-4/iA_cwH5BnH0XHFSRgGN9J3c06Jt-aSfePtbj8iBdd6iebQXgLByQVUS46Kypy1fkVAlwXWpkdHWOaxjul_dKs3rlllGu15l1D8__WC-GgTX0SYvCxCf_7U307d9WVgL_LgarB_eLW28D7RBlXnrzSwrs-Mz40GmMdFQn9a7pcJ-ImlVh-8s13-66a8G4Ehg6?purpose=fullsize
https://images.openai.com/static-rsc-4/-ACQKkNWmwdT84htVhY8NoMUl-uecTclRIR1L8NjM53Eu6gx5s-emmFAGN3hbo-XlFojSM9Z2_Qq6-76YEQMkpTvOjsX7qx6t4y2czKfRfShZhryFxV5nB7Q4o1etOYfcesbrnssIPy1IjJOa6m4dZJFN4ICPxfnoMzbVU8geBCUVPTvGeXHYDe4FUVfdNFm?purpose=fullsize

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

https://images.openai.com/static-rsc-4/x-0YP5eer5jmu3iMQ-J_wdYcw1woyT6tc2YatwW1zf8mAM8WsY0pPeRkWa838d328u6uDO5lZmuR3TzYjdVVtZcw7T9Ihfjen02GfhN4PoDaUVP2HHgU6M-iC3CBGlMrjlA0WVCVqOLei8NgK-llrO9dD8gWuRZ2BiL-5Hxw29dx8XHLa-_KGeAaGA1KVzgz?purpose=fullsize
https://images.openai.com/static-rsc-4/mB8UZ16LHnwLvQU21gOdfu3kO2WIWnBZQCjGz3ne5sBIu89CFSaENPQ9a1II0iNovt23eZt0B7XjtSA1LN1dPKDUmMjjUNtgTa4Ylt55Vh0m8-LtdcpywTIKvnpPpVBdeyzmpIz82_JEQRql38kdhgXd-8o0vVnyQHhUgGYV8-Y6IJ3Oj0Vm_zACbQoSfejK?purpose=fullsize
https://images.openai.com/static-rsc-4/L2dlT2tx968PFgsve6x9Hb38wFPe01psFstaydIykX8KuKy_0yIoB_jU6bupE5aua8zKtofKdZgXB7XP3PPFq-dNulD1pDDjj2fe2vVN8S_kEllfz9tgxw2XXA8LDe0FQwjnnWH3G-8g7ckEo0Nc3cDedNZZlwJcgRYmEYtwhI6oE0PwVxDgwU9q0b__OfSJ?purpose=fullsize

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

https://images.openai.com/static-rsc-4/nGeOPt1dHDFwVKjPZgQAHBI-oq41Ef82UDymKVfrM4jXeMLr9KKUp2cY8hNUckEtXQqHgmiEX2siCokJjDoaDyOXsbNtYRPjy0Y-cw2F1kq7hiI-ebXiFQdtZOuzfX1zV-6Jb224H6VcIp4cj2XiwT88wWQ2zwpcUQCGT0eUIifFErn2H1ypziSCLhyxjpxs?purpose=fullsize
https://images.openai.com/static-rsc-4/Z5kflW9p35iIMhUCdezhQufZO5ghlst047Z0E8gCrBnFkIfwlRuRRx7y8QeyzaYRbDiM9ppPxfCbqYaXhimZsrAV_X_eUKhB260K4Xyz5lQ8rmRGtXtnxMMiiLVWtLDsTg6xRk8leTyP-Y8RQd789JhWhuzy4otxTftoITvtTRHu1SOgrIMavyMw9TEsl-GO?purpose=fullsize
https://images.openai.com/static-rsc-4/E7ZSUiVdTj2Kc7PwkF4_W3fXu0f2lB5jzLatDkjekoYE0fgGjVnDIYbAFPgcar0pCQ3bTePFCOXdUkM6nh9TzveN9H548vmaW6qaleE4BWr5u33XeEmtssa88z7qpcCo2Vb2o63i9yGU0NwWKv863D1pLKnAudmL3pZ5YDiPyZmvCXryzsKLrBLklmW0AF66?purpose=fullsize

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

https://images.openai.com/static-rsc-4/PtpVDQPgZZXPrDxxpgbTWsy8oz8cmsMs0HxD6zSp9E0z9sdEu_o1kVcyJ0-jy3lPg2P1t2QQpqM2zHfqEwMBtiR6STi7fizM8csdSlcRYQU-4ZhgK5l1BfKndWAOVyKSJXBbhc7Gj9MPUv56SMJEX3lM5F_g7uWlUzaUwP2Q7wCEVDQQg5kpb97qPHjkY6fd?purpose=fullsize
https://images.openai.com/static-rsc-4/TuXR3jILs4u0pkm0r9JjTZaSOtchTX8gBISTOHgzsZKXCfpGWhgovzk6EBZlDTZe4V5-NtK5zmG7wTkr4EpDgHi64BIBwFpeDnX09oziszKOl8knh0N27o3_u9KudJ56xROE9W8VIJWbTdHJ_oxUNxr5FTD6uPdX60KMHJT2NurzcqRDi0bI6tpU1tGDq6wT?purpose=fullsize
https://images.openai.com/static-rsc-4/nPi7ddz3x69rHjuXnad4Ct2AcH0NG6FWC8B9jZj-BN4mOfgK2FQzgNXmRSB1GKepsJbqRNu5QKj6rO2WS2lE9jm0Cpw1-bq1WPmpBaipqRALGF-5vP3i0yMG2OMpllXvLWMmMAh6v_g7KNDXyT-thMX-WFDD2C18MJnlve4hLRYF5u_9vpfgZyCg-8S18cZv?purpose=fullsize

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:

  1. Relay activates.
  2. Water pump starts.
  3. Trough refills automatically.
  4. 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

https://images.openai.com/static-rsc-4/TuXR3jILs4u0pkm0r9JjTZaSOtchTX8gBISTOHgzsZKXCfpGWhgovzk6EBZlDTZe4V5-NtK5zmG7wTkr4EpDgHi64BIBwFpeDnX09oziszKOl8knh0N27o3_u9KudJ56xROE9W8VIJWbTdHJ_oxUNxr5FTD6uPdX60KMHJT2NurzcqRDi0bI6tpU1tGDq6wT?purpose=fullsize
https://images.openai.com/static-rsc-4/DY1wPl5aX8Od5cJ0H7qEd_HNWH-vwXmBmMVMgKXe7_bMbp8PW5GZHvbRc7c4aau7MYz0Q6sE3jw5q_eSQhlmP3L7oX-1E4iNyLTaZUFS16usnBYU5tW28xiGM4rwzD6fwUc5ajgnbQq_Mu8MOdqkEo8-z92UyxCsm4sghvWtPmqW6gjD8tH34L388s8pf_O_?purpose=fullsize
https://images.openai.com/static-rsc-4/ZHMFjYJPvLUs49QzM2E-rdhXZFqWuHqu6Fm2CiZpuxP45n9PQURQFEvj7CC2AgMAfCRzrEtlT6TXw0Qjqbi3h9O_4c7ty95BODDs3tFS6EuqNzc4kMnhJwEUj6_5ckwIzZLemzWfOYi9eoEOR6QGbl6k_di0GQo9-boEKwaCuvodfWx-qS6lTv4gK3Z8Ab8y?purpose=fullsize

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

mbeva

Dominic Mbeva is a science teacher, experienced researcher, innovator, and creative technologist with expertise in STEM education, digital media, and scientific research. As a Kenya Science and Engineering Fair (KSEF) advisor and projects manager, he mentors young scientists, guiding them in developing award-winning innovations. He is also an IC Technorat, leading advancements in science and technology. Beyond education, Dominic is a skilled photographer and video editor, using visual storytelling to make science more engaging. His philosophy, “If you take care of minutes, hours will take care of themselves,” reflects his belief in consistent effort, strategic thinking, and innovation to drive success in both research and creativity.

Related Posts

How to Make a Periodic Trends LED Board Using Arduino

Meta Title: How to Make a Periodic Trends LED Board Using Arduino and LEDs Meta Description: Learn how to build a Smart Periodic Trends LED Board using Arduino, RGB LEDs,…

Read more

How to Make a Smart Periodic Table Model Using Arduino and ESP32

Meta Title: How to Make a Smart Periodic Table Model Using Arduino, ESP32, LEDs and IoT Meta Description: Learn how to make a Smart Periodic Table Model using Arduino and…

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *