Don’t let your plants wither and die!
Keep track of when to water your plants with a moisture sensor.
Step 0 – Pre-build Overview
In this project, we are going to create a plant monitoring which the buzzer will sound when there is not enough water. The OLED will continuously display the current moisture level of the soil.
MATERIALS: 1 x BBC micro:bit, 1 x Micro USB cable,
1 x Breakout board, 1 x Mini buzzer, 1 x OLED,
1 x Moisture sensor, 2 x Female-Female wires
- Get to know the buzzer, OLED and moisture sensor
- Make something with a moisture sensor
Step 1 – Components
Insert the micro:bit into the Breakout Board and plug in the micro USB cable, then plug in the OLED as shown in the picture above. You should be able to plug it into any of the three rows
Connect 2 Female-Female jumper wires to the Buzzer. The positive (usually longer) pin on the Buzzer will connect to the yellow pin on the breakout board, while the negative (usually shorter) one connects to the black pin. Plug the other end of the jumper wires to Pin 0.
Plug in the moisture sensor to Pin 1. Make sure the colour of the wire follows the coloured pins on the break out board.
Step 2 – Pre-coding
We will add a package of code to enable us to use our kit components. Click on Advanced in the Code Drawer to see more code section and look at the bottom of the Code Drawer for Add Package.
This will open up a dialog box. Copy and paste the following link into the Add Package… text field: https://pxt.microbit.org/50544-64675-33322-24641. Click on the search icon or press enter, then click on the Tinkercademy button.
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 Projects file menu.
Step 3 – Coding
Click on Tinkercademy inside the Code Drawer to find our custom blocks for the various components in your kit.
You should always initialize the OLED at the begining. 64 and 128 represent the height and width of the OLED respectively.
Microbit reads values from moisture sensor continuously. Since there are only two conditions, we need only one ‘else if’ statement.
When the moisture sensor value is less than 50, this indicates that there is not enough water in the pot. As a result, the buzzer will sound and the OLED will display the message “Water your plant!”. Or else, if the moisture sensor value is larger than 50, the buzzer will not sound and the OLED will display the message “Your plant is in good condition”.
Step 4 – Success!
Voilà! You have created a fish feeding machine!
Looking for more projects to tinker and explore? We're a launch partner for IMDA's Digital Maker Programme, where we've been developing micro:bit kits, apps, and conducting workshops for schools and the public in Singapore. Read more here, and get in touch if you'd like to join our workshops!