
YOU have gone seven days with a moody plant after we left it complaining last week. Now we can give it both the means and a reason to be happy.
First, tweak your code to show a smiley face when the plantās conditions are good. Open your code in the editor ā now the variables we created last week will come in handy. Take another āifā block with no āelseā part, and snap it under the first two. Then slot in a ā\<\> and \<\>ā block from the āLogicā menu, and two ā0 = 0ā comparisons. Slot the ā0 = 0ā blocks either side of āandā.
Advertisement
Next, take your variables, DRY and WRONG TEMP, as well as two āfalseā blocks from the āLogicā menu and make a line that says āif DRY = false and WRONG TEMP = falseā. Nestle a āshow iconā from āBasicā inside the āifā block and select the smiling face.
Now it is time to build an automatic waterer to stop your plant drying out. For this we need a transistor. A transistor can act like an electronic switch. It has three legs, two of which are connected or not depending on the current going into the third.
Grab your breadboard (for a refresher, see āHow to be a makerā, 25 May), and place the transistor so its legs each sit in different rows. Connect the middle leg, called the āgateā, to pin 1 on the micro:bit. On my transistor, when the flat side is facing me, the right leg is the ādrainā and the left is the āsourceā. Yours will probably be the same, but check the packet to be sure. Connect the drain to the pumpās ground wire, which should be white, and the source to micro:bitās ground. Connect the pumpās red power wire to micro:bitās 3v pin.
Now, when the micro:bit sends a 1 to the transistorās middle leg, it will complete the circuit, while a 0 will break it. This lets us switch the pump on and off.
Letās add to our code to do this. From the āPinsā menu, grab a ādigital write pinā and select P1 from the drop-down. Leave the 0 at the end and clip the block into āon startā. This will make sure that the pump is off to begin with.
Next, under the block that says āset DRY to trueā, add another ādigital write pin p1ā, but this time change the 0 to a 1. Underneath that, slot in a āpauseā from āBasicā and select 2 seconds from the drop-down. Add another ādigital write pin p1ā underneath, leaving the 0 in the box. This will switch on the pump for 2 seconds then off again when the soil is dry. Add one final āpauseā below, typing in 10,000. This makes the system wait 10 seconds for the water to percolate. Once again, if you get stuck, online.
Finally, put the pump in a bowl of water and attach a length of tube between it and the plant pot. And youāre done! Now you can go on holiday and return to a happy houseplant.
To download a printable version of this page click here
New stuff you need
For next week
Old smartphone
Phone stand
Next in the series
2 Moisture and temperature-sensing plant
3 Plant auto-waterer
4 Tweeting wildlife camA motion-controlled animal spotter
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
Email: maker@newscientist.com