Āé¶¹“«Ć½

Electronics projects for beginners: Get your plants talking to you

Well-loved plants are happy plants. Here’s how to wire yours up to a BBC micro:bit so they can tell you when they are too hot, dry or cold

David Stock for <i>Āé¶¹“«Ć½</i>

LAST week, our plants learned to tell us they are thirsty. Now we are going to expand their repertoire.

Spider plants are happiest at between 20 and 30°C. That range suits me too, so it may seem that my spider plant Marvin is fine. But his microclimate may vary, or you might have a plant, an orchid for instance, that is more sensitive. Micro:bits have a temperature sensor built in, so we can use this to enable a plant to tell us in words when it is too hot or cold, as well as too dry.

In last week’s program, you have an ā€œifā€ block that reads the moisture sensor’s input from pin p0 and compares it with the threshold moisture level. To start, replace the sad face with a ā€œshow stringā€ from ā€œBasicā€, and in this type: ā€œI’m thirstyā€. This will show on the micro:bit screen when the water level drops.

Next, create a variable. We need to include this so that next week we can tell whether Marvin is happy or sad. This week, we are giving him only sad messages.

Go to the ā€œVariablesā€ menu, click ā€œcreate newā€ and type ā€œDRYā€ in the box. Then, grab ā€œset DRY toā€, which will have appeared in the menu, and clip into this a ā€œtrueā€ block from the ā€œLogicā€ menu. Place the whole thing under ā€œshow stringā€. Under ā€œelseā€, replace the happy face with another ā€œset DRY toā€, but this time clip in ā€œfalseā€.

Now we want to know if the plant’s temperature goes below 20°C. Place another ā€œifā€ block underneath the first, and click the plus at the bottom to add an extra if/else section. Next, grab a ā€œ0\>0ā€ comparison from ā€œLogicā€. Find a ā€œtemperatureā€ block from ā€œInputā€ and clip this in the left of your comparison, then type 20 on the right. Slot this comparison in place of ā€œtrueā€ in the first part of your ā€œifā€ block. Under this line, add a ā€œshow stringā€ block like before, but with a message like ā€œI’m too coldā€.

Next, another variable. This one enables us to keep track of when the temperature is either too hot or too cold. Call this one ā€œWRONG TEMPā€ then grab a ā€œset WRONG TEMP toā€ block and clip into it ā€œtrueā€ from the Logic menu. Slot the whole thing under your ā€œshow stringā€ block.

In the second part of your ā€œifā€ block, write a comparison as above, but make it say ā€œtemperature \< 30ā€. Add a string saying ā€œI’m too hotā€, and a block to ā€œset WRONG TEMPā€ to ā€œtrueā€ underneath.

Finally, in the ā€œelseā€ section, clip in ā€œset WRONG TEMP to falseā€. If you get stuck, you can check out online.

Download your code, and connect up the sensor, micro:bit and battery. You will notice that your plant does nothing but complain – we haven’t yet given it a way to say it is satisfied. That comes next week, along with an automatic watering device.

To download a printable version of this page click here


What you need

You should have everything

For next week

jumper wires

Next in the series

1 Moisture-sensing plant

2 Moisture and temperature-sensing plant

3 Plant auto-waterer Your plants will never dry out again

4 Tweeting wildlife cam

5 Pest scarer

6 BBQ thermometer

7 Rain alarm

8 Mini weather station

9 Remote controlled pest-proof bird feeder part 1

10 Remote controlled pest-proof bird feeder part 2

Ģż

Ģż

Topics: Electronics / Plants