Lesson 7 Growing Stage: Irrigation System
Challenges: 7-1, 7-2
Students will develop programs that combine control structures, including nested loops and compound conditionals.
I can set a proper soil moisture threshold to control the pump’s on/off status.I can use the compound condition of light and soil moisture to achieve automatic irrigation.I can understand and use nested loops to implement an intermittent watering pattern.
Engage
2 min.
What do plants need to grow? (Water, sunlight, etc.) Today, we're going to build a smart system that waters plants automatically, but only when they need it!

How do we know the crops need water?
Background
3 min.Soil Moisture Sensor: This is a simple moisture sensor used to detect the water content in soil.

The read analog block is to get a value from the sensor connected to port P0. The sensor outputs low values for dry soil and higher values for wet soil.

A relay is an electrically operated switch that turns on and off the pump to safely drive high-power devices like water pumps.

NOTE: The relay module has a toggle switch to select NO or NC mode. NO stands for Normally Open, which means the wire connected to this contact will normally be open (or off), and current will not flow when the relay is deactivated. And the NC (Normally Closed) works in the opposite manner.
When the relay is switched to NO, the digital output HIGH signal activates the relay and turns on the water pump, while the LOW signal turns the pump off.

Build and Connect
10 min.
![]() | Build together by following the Building Instruction. |
NOTE: Students can install the UNIHIKER K10 on the holder and link to the base using block pins.
Program
25 min.
Challenge 7-1: Basic Automatic Irrigation
![]() | ![]() Instruct students to insert 4 AA batteries into the battery holder, then connect all sensors and actuators to the UNIHIKER K10. NOTE: Switch the relay to NO mode, and power on the battery supply only after uploading the program. Add the required extensions and prepare for programming. |
![]() | Guide students to rebuild the program from an image. This program checks if the soil is dry and turns on the water pump. |
![]() | Run the program and encourage students to answer:Insert the sensor into wet soil and dry soil separately. What is the sensor reading now?What threshold value should we set to represent dry soil?Ask students to adjust this threshold value. |
![]() | ![]() Explain that we should avoid watering plants in the middle of the day when the intense sunlight is because the water can evaporate too quickly. Challenge students to modify the if block with the and block to turn on the pump only if the soil is dry and the sunlight is soft. Sample code: |
Challenge 7-2: Intermittent Watering with Loops
![]() | ![]() Guide students to load the program7-2-1, and add blocks to make the watering repeat an “on-off” cycle three times total. Sample code: |
![]() | ![]() Challenge students to make it repeat a set of actions a specific number of times without writing the same blocks over and over. Sample code: |
NOTE: It is recommended that teachers avoid testing the device with water during class. If the equipment needs to be used in a real watering scenario, ensure all exposed electronic components are properly waterproofed. Refer to the figure below for the recommended application scenarios of the water pump.

Extra Practice
5 min.
Change the time in the wait blocks so the watering cycle moves faster or slower.

Challenge students to create other watering patterns with the digital output HIGH and digital output LOW blocks. For example, create a music fountain on your farm.
Next Class: Lesson 8
Current Tutorial: Click Here




















