
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.
Advertisement
In last week鈥檚 program, you have an 鈥渋f鈥 block that reads the moisture sensor鈥檚 input from pin p0 and compares it with the threshold moisture level. To start, replace the sad face with a 鈥渟how string鈥 from 鈥淏asic鈥, and in this type: 鈥淚鈥檓 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 鈥淰ariables鈥 menu, click 鈥渃reate new鈥 and type 鈥淒RY鈥 in the box. Then, grab 鈥渟et DRY to鈥, which will have appeared in the menu, and clip into this a 鈥渢rue鈥 block from the 鈥淟ogic鈥 menu. Place the whole thing under 鈥渟how string鈥. Under 鈥渆lse鈥, replace the happy face with another 鈥渟et DRY to鈥, but this time clip in 鈥渇alse鈥.
Now we want to know if the plant鈥檚 temperature goes below 20掳C. Place another 鈥渋f鈥 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 鈥淟ogic鈥. Find a 鈥渢emperature鈥 block from 鈥淚nput鈥 and clip this in the left of your comparison, then type 20 on the right. Slot this comparison in place of 鈥渢rue鈥 in the first part of your 鈥渋f鈥 block. Under this line, add a 鈥渟how string鈥 block like before, but with a message like 鈥淚鈥檓 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 鈥淲RONG TEMP鈥 then grab a 鈥渟et WRONG TEMP to鈥 block and clip into it 鈥渢rue鈥 from the Logic menu. Slot the whole thing under your 鈥渟how string鈥 block.
In the second part of your 鈥渋f鈥 block, write a comparison as above, but make it say 鈥渢emperature \< 30鈥. Add a string saying 鈥淚鈥檓 too hot鈥, and a block to 鈥渟et WRONG TEMP鈥 to 鈥渢rue鈥 underneath.
Finally, in the 鈥渆lse鈥 section, clip in 鈥渟et 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鈥檛 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
听
听