4.10 Project: Auto-Irrigation System


Pay attention! Do not overflow water from plastic pools in experiments. Spilling water on other sensors may cause not only a short circuit to disturb normal operations but also heat generation and even explosion. Do be extra careful! Especially for younger users, please operate with your parents. To guarantee security, please obey guidances and safety regulations.


In this project, we stimulate irrigation via a water pump controlled by a relay module. Besides, we also determine whether there is water in the pool through water level sensor, and detect the soil humidity by soil humidity sensor. In this way, the system will be more intelligent in controlling the water pump.

img


4.10.1 Flow Diagram

image-20230607183214310


4.10.2 Water Pumping System

Description:

In this experiment, we use ESP32 development board to turn on/off the water pump by a relay module. A pump lifts water and transports liquids, and usually is combined with a relay module in usage.

Herein, we connect the relay module and the pump to the ESP32 board, and program to remotely turn on or off the pump through switching the state of relay. For how, we determine the state of relay according to the output value of the module or a preset time.


Relay Module:

In usage, it is often used in the management of high voltage and load current, say, motors, high-current sensors and high-power lights.

img

  • Normally Open (NO): This pin is normally open, unless a signal is received by the signal pin of the relay. Therefore, common pins are disconnected via NC pin and connected through NO pin.

  • Common Contact (COM): This pin connects to other modules, for example, water pump.

    • Water Pump:

img

  • Normally Closed (NC): NC pin is linked with COM pin to form a closed circuit. It uses ESP32 board to control the closure and the disconnection of the relay module.


Parameters:

  • Power voltage: 5V

  • Static current: 2mA

  • Maximum contact voltage: 250VAC/30VDC

  • Maximum current: 10A

Schematic Diagram:

img


Wiring Diagram:

Attention: Connect yellow to S(Signal), red to V(Power), and black to GND. Do not reverse them!

img


Test Code:

img

Test Result:

After uploading code, the device will pump water once.

In this experiment, the water pump is automatized, reducing time and efforts of manual operation and improving efficiency. Therefore, this water pumping system is wildly used in agricultural production and water treatment.


4.10.3 Auto-Irrigation System

Description:

In this experiment, we implement a smart irrigation system by a soil humidity sensor, a water level sensor, a relay module and a water pump. We connect the two sensors on ESP32 development board and program to read their output values to control the relay and water pump.

If the soil is very dry, the relay will turn on to control the water pump to irrigate plants; And if the water level is too low, the water pump will not be able to work, and the buzzer will alarm. In this way, plant watering and water level controlling are automatized, which raises production efficiency and reduces the time and efforts of manual operations.


Wiring Diagram:

  • Connect the relay module to io25; connect its NC pin to the GND(black) at io2.

  • Water pump:

    • Connect the red wire to POWER 3V3 of the board

    • Connect the black wire(GND) to the COM pin of the relay

  • Connect the soil humidity sensor to io32

  • Connect the water level sensor to io33

Attention: Connect yellow to S(Signal), red to V(Power), and black to GND. Do not reverse them!

img


Test Code:

Code Flow:

img

Code:

  • Initialize and clear the LCD, turn on the LCD back light. Define two variables as the detected sensor values.

img

  • Assign the two read sensor values to those variables.

img

  • Display these values on LCD.

img

  • If the water level value is lower than 700 or the soil humidity value is less than 1200, the buzzer will alarm.

img

  • When the soil humidity value is lower than 1200 but the water level value is greater than 700, the water pump will automatically irrigate the farm.

img

Complete code:

img

Test Result:

img

  • LCD 1602 will display the current values of soil humidity and water level. When the detected humidity is lower than the set threshold, it implies that the soil is being arid, and irrigation starts automatically.

  • When the detected water level is lower than the set threshold, the water pumping system doesn’t work, and the buzzer alarms to notify that water is insufficient.

  • Press the button to stop alarming.


To sum up, we have achieved an analog auto-irrigation system in this project, which intelligently controls the on and off of the water pump according to the water level. In application, this system usually goes for household and agricultural production.


4.10.4 FAQ

Q: Are the modules waterproof?

A: The relay module is not, yet the water pump is. The waterproof grade of the water pump is IP68.


Q: ESP32 board is reset when the water pump works.

A: When water pump works, more current is required than other modules, hence voltage and current may fluctuate in the circuit. Sometimes fluctuations may be too heavy, resulting in a reset due to extremely low voltage and current in ESP32 development board.

When operating the water pump, please follow the example code:

img


Q: Fail to pump water?

A: Several pumping operations are required to fill the water pump before using it. These initial pumpings do not actually draw the water, but to introduce sufficient water into the pump. Only after the pump is full can water be carried out. So we are first for filling, not pumping.