
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