Step-by-Step Coding Tutorial

Let’s get ready to code your Automatic Irrigation project. To follow the coding tutorial on Makecode, click the Start Coding button below.

Open Coding

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.

Here’s a brief description to help you on your open coding journey:

Objective: Use the moisture sensor to measure the moisture level of the plants soil. Then, use the water pump to water the plant when the moisture level is low. Use the LED light to act as a grow light for the plant.

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. Change the LED to your desired colour and keep it on forever.

The code runs in a forever loop, repeatedly executing the contained instructions. Within this loop, it sets the color of all pixels in an LED ring to a purplish hue. It then checks whether the moisture level read from a moisture sensor is above a threshold of 50. If the moisture level is above the threshold, it displays a happy face icon on the micro:bit’s LED matrix. If the moisture level is not above the threshold, it displays a sad face icon, activates a water pump motor for 500 milliseconds, pauses for 500 milliseconds, and then clears the LED matrix display. This code essentially monitors soil moisture, provides visual feedback through icons and the LED ring, and briefly activates the water pump if moisture is insufficient.