12. iot:kit case04: An automatic irrigation detection#

12.1. Our goal#

Let’s make an automatic irrigation detection.

12.2. Required materials#

1 x IOT:kit

12.3. Background#

What is the automatic irrigation detection#

automatic irrigation detection An automated irrigation system refers to the operation of the system with no or just a minimum of manual intervention beside the surveillance. Almost every system (drip, sprinkler, surface) can be automated with help of timers, sensors or computers or mechanical appliances. It makes the irrigation process more efficient and workers can concentrate on other important farming tasks. On the other hand, such a system can be expensive and very complex in its design and may needs experts to plan and implement it.

12.4. Hardware connection#

As below picture, let the soil moisture sensor be connected to P1.

Let the water level sensor be connected to P2.

Let the 180° servo be connected to P10.

../../_images/case_04_011.png

12.5. Software#

makecode

12.6. Coding#

Step 1#

Click on “Advanced” in the MakeCode Drawer to see more code sections.

../../_images/iot_bit_11.jpg

We need to add an extension for coding to the IOT. Click on the “Extension” at bottom of coding drawer, then Search for “IOT” and click on the IOT package to add it to your project. (As below picture)

../../_images/iot_bit_12.jpg

Note: If you get a warning telling you some packages will be removed because of incompatibility issues, either follow the prompts or create a new project in the Project file menu.

Step 2#

Snap the servo write block into the on start, write in 0 to turn the servo to 0 deg for shuting the valve.

../../_images/case_04_02.png

Step 3#

Snap the set to block into the forever. Get the value of water level and assignment it to the water level variable and the value of soil moisture value to the soil humidity variable.

../../_images/case_04_031.png

Step 4#

To judge if the water level is lower than 10, if it is, play a bading for adding water.

../../_images/case_04_04.png

Step 5#

To judge if the soil humidity is lower than 30, that is if it is need to watering.

If it lowers than 30, valve opened and watering; if it not lowers than 30, valve shuted.

../../_images/case_04_05.png

Program#

Program link:https://makecode.microbit.org/_dxTF0K1be0w0

If you don’t want to type these code by yourself, you can directly download the whole program from the link below:

Result#

12.7. Think#

12.8. Questions#

12.9. More Information#