杏吧原创

Electronics projects for beginners: Make an automatic plant waterer

Learn to make a simple automatic watering device that will ensure your plants never go thirsty again

Plant waterer

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鈥檚 conditions are good. Open your code in the editor 鈥 now the variables we created last week will come in handy. Take another 鈥渋f鈥 block with no 鈥渆lse鈥 part, and snap it under the first two. Then slot in a 鈥淺<\> and \<\>鈥 block from the 鈥淟ogic鈥 menu, and two 鈥0 = 0鈥 comparisons. Slot the 鈥0 = 0鈥 blocks either side of 鈥渁nd鈥.

Next, take your variables, DRY and WRONG TEMP, as well as two 鈥渇alse鈥 blocks from the 鈥淟ogic鈥 menu and make a line that says 鈥渋f DRY = false and WRONG TEMP = false鈥. Nestle a 鈥渟how icon鈥 from 鈥淏asic鈥 inside the 鈥渋f鈥 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 鈥淗ow to be a maker鈥, 25 May), and place the transistor so its legs each sit in different rows. Connect the middle leg, called the 鈥済ate鈥, to pin 1 on the micro:bit. On my transistor, when the flat side is facing me, the right leg is the 鈥渄rain鈥 and the left is the 鈥渟ource鈥. Yours will probably be the same, but check the packet to be sure. Connect the drain to the pump鈥檚 ground wire, which should be white, and the source to micro:bit鈥檚 ground. Connect the pump鈥檚 red power wire to micro:bit鈥檚 3v pin.

Now, when the micro:bit sends a 1 to the transistor鈥檚 middle leg, it will complete the circuit, while a 0 will break it. This lets us switch the pump on and off.

Let鈥檚 add to our code to do this. From the 鈥淧ins鈥 menu, grab a 鈥渄igital write pin鈥 and select P1 from the drop-down. Leave the 0 at the end and clip the block into 鈥渙n start鈥. This will make sure that the pump is off to begin with.

Next, under the block that says 鈥渟et DRY to true鈥, add another 鈥渄igital write pin p1鈥, but this time change the 0 to a 1. Underneath that, slot in a 鈥減ause鈥 from 鈥淏asic鈥 and select 2 seconds from the drop-down. Add another 鈥渄igital 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 鈥減ause鈥 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鈥檙e 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

1 Moisture-sensing plant

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

Topics: Electronics / Plants