6. Case 05: Indoor Flower Watering Device#

6.1. Introduction#


  • Most plants can make us healthier, for example, one pot of green dill is equivalent to an air purifier in a room of 8-10 square meters, which can effectively absorb harmful gases such as formaldehyde, benzene and trichloroethylene in the air. Thus, we can make a simple watering device to help us take care of plants.

6.2. Function#


  • Judge if the plant needs to be watered by detecting the moisture value, if the value is too low, program to drive the servo to open the water valve for watering.

6.4. Picture#


../../_images/microbit-Smart-Health-Kit-case-01-02.png

6.5. Hardware Connection#


Connect the soil moisture sensor to P1 and the servo to P2 on sensor:bit.

../../_images/microbit-Smart-Health-Kit-case-01-03.png

6.6. Software Programming#


Click “Advanced” in the MakeCode to see more choices.

../../_images/microbit-Smart-Health-Kit-case-01-04.png

For programming, we need to add a package: click “Extensions” at the bottom of the MakeCode drawer and search with “smarthome” in the dialogue box to download it.

../../_images/microbit-Smart-Health-Kit-case-01-05.png

For programming, we need to add a package: click “Extensions” at the bottom of the MakeCode drawer and search with “servo” in the dialogue box to download it.

../../_images/microbit-Smart-Health-Kit-case-01-06.png

Notice: If you met a tip indicating that some codebases would be deleted due to incompatibility, you may continue as the tips say or create a new project in the menu.

6.7. Program#


Connect the soil moisture sensor to P1 and save the returned value as the variable “soil_moisture”.

../../_images/microbit-Smart-Health-Kit-case-05-07.png

Judge if the variable “soil_moisture” is below 50.

../../_images/microbit-Smart-Health-Kit-case-05-08.png

If yes, it means the soil moisture value is too low, program to drive the servo connecting to P2 to drive to 90° to open the water valve for watering; or set the servo to drive to 0° to close the valve.

../../_images/microbit-Smart-Health-Kit-case-05-09.png

Link: https://makecode.microbit.org/_YhD7u8igkWMo

6.8. Result#


  • If the soil moisture value is below 50, program to water the plants automatically.