
This project introduces how to use a kidsIOT mainboard, a soil moisture sensor, a water level sensor, a passive buzzer, an OLED display, a relay and a water pump to build an automatic irrigation system.
We will read the analog values of the soil moisture sensor and water level sensor by writing code to control the relay and the water pump.
When the soil is too dry, the relay will be turned on to control the water pump to irrigate the plants, when too low, the water pump will not be started and the buzzer will alarm.
At the same time, the OLED display will display the dryness of the soil and the water level, thus realizing automated plant watering and water level control, improving production efficiency while reducing the time and energy costs of manual operations.
|
|
|
|
|
|---|---|---|---|
|
kidsIOT Mainboard×1 |
Water Level Sensor×1 |
Soil Moisture Sensor×1 |
Passive Buzzer×1 |
|
|
|
|
|
|
GPIO Shield×1 |
Relay Module×1 |
Water Pump×1 |
Wire×3 |
|
|
|
|
|
|
Battery Holder×1 |
Slotted Screwdriver×1 |
M-F DuPont Wires |
F-F DuPont Wires |
|
|
|
|
|
|
Water Pipe×1 |
Soil Moisture/Water Level/Automatic Irrigation System LEGO Pieces×1 |
AA Battery(Not provide)×6 |
Sink×2 |

It shares the same structural shape with Project 07. If the assembly parts of Project 07 have finished, there is no need to assemble it again.
|
Module |
GPIO Shield |
kidsIOT Mainboard |
|---|---|---|
|
Soil Moisture Sensor |
G→G,V→V,S→S3 |
No.4 port(control pin of S3 is io27) |
|
Water Level Sensor |
G→G,V→V,S→S4 |
No.4 port(control pin of S4 is io39) |
|
Passive Buzzer |
No.8 port(control pin is io5) |
|
|
Relay Module |
No.2 port(control pin is io2) |
Connect the kidsIOT mainboard to your computer via USB cable, connect the external power supply and turn the DIP switch on the mainboard to ON end.


① Set the pin IO2 connected to the relay module to “input” mode.

② Set the relay module to close for 0.5 seconds and then disconnect, controlling the water pump to pump water for 0.5 seconds.

③ Complete Program

Click
to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, the relay module will control the water pump to pump water.



① Initialize pin IO27 of the soil moisture sensor and pin IO39 of the water level sensor to “input” mode.

② Initialize pin IO2 of the relay module and pin IO5 of the passive buzzer to “Output” mode.

③ Initialize the width, height, I2C address, text size and color as well as background color of the OLED display.

④ Define a “Soil_humidity_sensor” global variable to store the analog value of the soil moisture sensor and a “Water_level_sensor” global variable to store the analog value of the water level sensor.

⑤ Assign sensor data to variables.

⑥Display the sensor data at the corresponding position on the OLED display.

⑦ Judgment: When the water level is less than 1000, or the soil moisture is less than 500, the buzzer will sound an alarm.

⑧ When the soil moisture is less than 500 and the water level in the sink is greater than 1000, the relay will drive the water pump for automatic irrigation.

⑨ Complete Program

Click
to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, the OLED displays current soil moisture and sink water level information.
When the soil moisture is lower than the set threshold, then the soil is too dry, the buzzer will sound an alarm. At this time, the pumping system will automatically irrigate the soil. When the water level in the sink is lower than the set threshold, the pumping system will not work and the buzzer will sound an alarm to indicate that there is insufficient water in the sink.

A: The relay is not waterproof.