Educator's Note: You can find a completed version of the code for this project here. For tips on troubleshooting with micro:bit Makecode, please refer to the Knowledge Base here. Coding Description: The code utilizes a continuous loop to monitor soil moisture levels using a moisture sensor. Depending on specific moisture thresholds, it provides visual feedback through LED colors and icons on the micro:bit's display. If the moisture level is past a threshold of 50, a happy face icon is shown; otherwise, a sad face icon is displayed, and a water pump motor is activated for 500 milliseconds before clearing the screen. The code then checks multiple moisture thresholds (80, 60, 40, and 20), progressively lighting up LED ring pixels in red as moisture surpasses each threshold, visually indicating the moisture levels in the soil. This code effectively provides real-time soil moisture monitoring and feedback using icons, LEDs, and a pump motor.
Let’s get ready to code your Automatic Irrigation project. To follow the coding tutorial on Makecode, click the button below.
Objective
Code the moisture sensor to measure the moisture level of the plant’s soil at all times. Then, code the water pump to water the plant when the moisture level is low. Use the LED light to check for moisture levels at 20, 40, 60, and 80 percent, monitoring moisture level to avoid over watering.
Coding Description
Use an if statement to determine the moisture level of the soil, and if the moisture level is below a certain amount, run the pump motor for a certain amount of time.
This code is like a smart program that uses a moisture sensor to measure the dirt’s wetness. If the dirt is wetter than a certain amount (50), it shows a happy face. If it’s not moist enough, it shows a sad face and turns on a water pump for a little bit to make the dirt wetter; then it clears the picture.
The code also looks at different wetness levels (like 80, 60, 40, and 20) and lights up little lights in a circle in red colour, one by one, as the dirt gets wetter. This way, you can see how moist the soil is by looking at the lights.
If you’d like to try coding your Automated Watering System without following a tutorial, you can code openly in the traditional Makecode workspace by clicking the link below.