BBC Microbit: Plant Watering System

I’ve had my Microbit for some time now. Not being either a student or teacher at School, I opted to pay a premium for one of these from Ebay sellers and recently found the time to try my first project with one.

This project is ongoing but originally started with an idea and code from the following site:

Microbit website

The project uses a microbit as a controller to monitor the moisture level in soil and when it becomes too dry, it will use a small water pump to water a plant until the soil is moist enough.

When we all returned from our summer holidays, the solitary office plant had badly withered through a lack of TLC so was the obvious test subject for this project (see the pictures above). Our mission was to revive it using a physical computing project:

Here it is in action

Step 1

Go to and click Create code, then select Microsoft Block Editor, New project.


Then use the code editor to enter the following code:


Connect your BBC Microbit to your computer and it show as a storage drive. Click compile and then you will have the opportunity to save the resultant hex file onto the Microbit.  Once this is done, remove the USB lead from the Microbit. Connect the leads as per the instructions below and when ready to run the script, you simple press the A button.

The script waits for the button A to be pressed to start.

It reads the water sensor attached to Pin 0 and displays the sensor output on the LED’s. I added some code here to display the sensor output so that I could fine tune the point at which the soil was dry and I wanted the pump to be triggered. This took a few attempts at measuring dry and damp soil to establish a suitable number.

If the soil is too dry, it displays a W for watering, turns on the pump attached to Pin 1 for 2 seconds and then P for pauses for 10 seconds to let the water soak in.

This pause to allow time for the water to act is a key concept in terms of control engineering.

If the soil is damp enough, it shows G for good.

This is wrapped up in the while loop that is checking that button B has not been pressed. Once it is pressed, it drops out the sense/water loop, displays a S for stop and is then idle, pending another press of button A

The water sensor analogue data lead is attached to Pin 0 (The sensor I have used has analogue and digital outputs. Use the datasheet to locate the analogue output to connect to the Microbit) and the pump trigger lead is attached to Pin 1 (light green lead). The pump black lead needs to go on to 0V on the micro:bit. The battery pack positive (red) lead goes to the pump red lead and the battery pack 0V (black) lead goes to the 0V on the micro:bit so there is a common ground for all the circuitry.

As per the original post on the Microbit learning website, I also want to expand the script and project to include a light and temperature sensor so that watering does not take place on a bright sunny day with high temperatures where the water would quickly evaporate and not be very effective. Many gardeners water plants early in the morning and in the evening to avoid these issues, so I want the project to mirror this.

Parts List

BBC Microbit with Micro USB cable

Pack of crocodile leads

Water Pump

Plastic cup

BBC Microbit Battery box

Moisture Sensor YL-69

You can purchase these parts from although the sensor I bought from ebay as it was cheaper.




Published by


Lecturer in IT at East Berkshire College. Assessor & Verifier Technology Evangelist Hacker Tinkerer Collector of all things Retro Cyclist Kayaker Adventurer

2 thoughts on “BBC Microbit: Plant Watering System”

    1. Hi Billy, Thanks for the message. I had a look at the link you sent and can confirm I have never heard of this organisation or given them permission to use my images to help sell their products. I’ll send them a message asking them to remove the image. Regards, Paul


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s