Our goal


Required materials


Background


What is the automatic irrigation detection


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.

Software


makecode

Coding


Step 1

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.

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.

Step 4

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

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.

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


Think


Questions


More Information