
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ā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
Ģż
Ģż