Plant Watering Kit Project

Plant Watering Kit Project

Plant Watering Kit

Microbit Plant Watering Kit

DISCLAIMER: PLANT POT USED FOR DEMONSTRATION PURPOSES ONLY!

So you've gotten bored of watering your plants? You do it every morning and it puts you back to sleep, or maybe you've forgotten to do it so often that your plant died, or maybe you just love the BBC micro:bit?

Well this plant watering kit for bbc microbit then lets combine your favourite two hobbies: forgetting to water the plant and the BBC micro:bit and let electronics and a bit of engineering do that job for you. All you're going to need is one plant watering kit and one neglected plant.


What The Kit Contains

contents of plant watering kit for microbit

Kit contains:

  • 1 × Plastic Tubing

You will also need:

A BBC Microbit - we didnt include one in the kit to keep the price down in case you had a microbit already. If you need to pick one up, you can get it here:

A USB to micro USB cable,

2xAAA batteries,

4xAA batteries,

a computer with an internet connection,

a pen or pencil, a piece of paper and some water,

a medium to large plant pot,

a medium to large size container to hold water...

and finally a plant.

Now that you have everything you need, let's begin!


How the BBC micro:bit works

microbit pinout

The BBC micro:bit is a miniature computer that can be used to control other electronics connected to it's external pins. The BBC micro:bit runs on code written on the computer on the BBC micro:bit website, you can code in python or as we're going to do code in the makecode microbit editor. The BBC micro:bit has 5 big pins and 20 small pins. They're used as shown in the diagram. We will only be using the big pins, when connecting the pins to a crocodile clip make sure that the crocodile clip isn't overlapping with any of the small pins as this can cause issues. 


Step 1 Moisture Sensor


Step 1.1 The hardware

Proto-PIC Plant watering kit guide

Let's start by wiring up the BBC micro:bit to the moisture sensor: 

  1. Attach one end of one of the wires to the GND pin (GrouND) of the BBC micro:bit. 
  2. Attach the other end of that wire to the GND of the moisture sensor (if you don't see GND flip the moisture sensor over on to its other side). 
  3. Get another wire and attach one end to the 3V pin of the BBC micro:bit (it's called 3V because it outputs 3 volts). 
  4. Attach the other end of that wire to the VCC pin (Voltage Common Collector) of the moisture sensor (the VCC is the power input for the moisture sensor). 
  5. Get the final wire and attach it to the 0 pin of the BBC micro:bit. 
  6. Finally attach the other end of that wire to the SIG (SIGnal) of the moisture sensor (this is going to send a signal to the BBC micro:bit to tell it how moist the soil is).

How this works

The BBC micro:bit is powering the moisture sensor (via a lead from the 3V pin on the micro:bit into the VCC on the Moisture Sensor), this power then travels out one prong of the moisture sensor, then through whatever material you place it in then arrives at the other prong. The moisture sensor checks how much voltage gets between both prongs and sends a voltage back through the SIG into the BBC micro:bit’s Pin 0. The soil is acting as a resistor and drains some of the voltage as it travels between prongs. The voltage drop that we see on Pin 0 tells us how moist the soil is. This is because moist soil makes a much better conductor of electricity than dry soil, so the more moist the soil is the more electricity can travel between both prongs so the more voltage gets sent back to Pin 0.


Step 1.2 The code

microbit code

We need to find a way for us to code the BBC micro:bit to work with the now connected moisture sensor placed into the pot soil.

  1. Attach the BBC micro:bit to your computer with a USB cable (you should see an orange LED light up on the BBC micro:bit).
  2. In your second favourite browser go to the https://makecode.microbit.org/ website.
  3. Click on New Project.
  4. Inside the 'Basic' tab you should find the 'show string' block drag it inside the 'forever' block. 
  5. Inside Advanced you'll find the 'Pins' tab inside that you want to drag out the 'analog read pin' block.
  6. Then drag the 'analog read pin' block inside the 'show string' block where it says "Hello!".
  7. Make sure that P0 is set as the pin for the 'analog read pin' block.
  8. Click Download, this will compile and download a hex file containing the code you just made.
  9. Place the hex file inside the Drive labelled "MICROBIT".

How this works

The ‘forever’ block is a loop that goes on endlessly. The ‘show string’ block will make the BBC micro:bit show a series of characters on screen, it will scroll through each character one by one until the entire word/phrase/number has been displayed. The ‘analog read pin’ block asks to read the voltage of pin 0, analog read means it will be outputting as a number between 0 and 1023 depending on how high the voltage is. 

So this code will read the voltage of pin 0, display a number between 0 and 1023 on the screen and after it has displayed this number it will repeat, forever.

How this code will help

The moisture sensor gives off a voltage based on how wet the area is between the two prongs, this code takes in that data and feeds us back numbers between 0 and 1023. The low numbers mean drier and the high numbers mean wetter. This allows us to see what numbers the BBC micro:bit is working with.


Step 1.3 The data

Proto-PIC Plant watering kit guide

Let's gather some data to be used for deciding the threshold number, that is the number at which we would like to start watering the plant, since lower numbers mean drier soil, we want to pick a number, that below which, we would like to start watering the plant.

  1.  First unplug the BBC micro:bit from the computer and plug the AAA battery pack into it.
  2. You should be seeing a small single digit number on the BBC micro:bit screen (because the two prongs of the moisture sensor are not inside any material).
  3. Now place the two prongs of the moisture sensor in some water, you should see the number be a three digit number roughly around in the high 800 and 900 range.
  4. Wait until the plant pot soil is dry.
  5. With pencil and paper nearby, insert the two prongs into the plant pot soil.
  6. Write down the heading "dry" and the number for dry soil reinsert the two prongs elsewhere in the plant pot and repeat this for 5 measurements.
  7. Water the plant, and write down the heading "wet" and the numbers for wet soil reinsert the two prongs elsewhere and repeat this for 5 more measurements.

Why gather the data

We need this data, because the BBC micro:bit code will be using the numbers fed into it by the moisture sensor to decide when to water the plant. We don’t know what the numbers the BBC micro:bit outputs mean in relation to the wetness of the soil until we have gathered some data.


Step 2 Pump


Step 2.1 The code

Proto-PIC Plant watering kit guide

Now that we have our data let's code the final product.

  1. Plug the BBC micro:bit back into the computer (it's alright if you have to unplug the moisture sensor) and get on the https://makecode.microbit.org/ website.
  2. Click on New Project.
  3. There are a lot of blocks involved in this code so lets start by getting them all out, under the basic tab, take out two 'pause (ms)' blocks and take out a 'show string' block.
  4. Under the logic tab take out one 'if true then' block and then take out a '<' comparison block.
  5. Lastly under advanced in the pins tab take out two 'analog read pin' blocks and two 'digital write pin' blocks.
  6. Place the 'show string' block inside the 'forever' block and take one of the 'analog read pin' blocks (make sure it's set to pin P0) and place it inside of the 'show string' block.
  7. Take the 'if true then'  block and place it underneath the 'show string' block take the '<' comparison block and place it inside the 'true' part of 'if true then' block then take the 'analog read pin' block (again make sure it's set to pin P0) and place it on the left hand side of the '<' comparison block.
  8. Place a 'digital write pin' block inside the 'if true then' block then put a 'pause (ms)' block underneath that, and then another 'digital write pin' block.
  9. Set the first 'digital write pin' block so that it's changing P1 to 1, then set the second so that it's changing P1 to 0.
  10. Finally underneath the 'if true then' block place the final 'pause (ms)' block.

How this works

The ‘show string’ block is reading the moisture sensor from pin 0 and outputting it to the screen just like before. The ‘if true then’ block will only run the code inside it if the if statement is true, the ‘<‘ comparison block is checking to see if the ‘analog read pin’ block is below a threshold value if it’s then the if statement is true and the code inside the ‘if true then’ block runs. Then pin one is digitally written as a 1 which means that roughly 3.3V is being outputted by the BBC micro:bit through that pin. Then the ‘pause (ms)’ block pauses because as pin 1 is on, the water will be pumping into the plant pot, then we turn it off again by digitally writing it as a 0. Then we pause again to allow the water to soak in and to conserve power. Finally the ‘forever’ block loops.

In short pin 0 is read and displayed on screen, if pin 0 is below a threshold value then we turn on pin 1, pause for a bit, and then turn pin 1 off again, finally we pause again before we loop, forever.


Step 2.2 The data meets the code

Proto-PIC Plant watering kit guide

You have your data and your code before you can upload it to the BBC micro:bit we need to use our data, to adjust the code for your situation. You know the numbers for when your plant pot's soil is wet, and you know the numbers for when your plant pot's soil is dry. So let's adjust the code for our plants.

  1. Pick a number between your wet numbers and dry numbers as your threshold number, this is the number at which we will water the plant (pick a number between them but definitely closer to the dry side).
  2. Input this number on the right side of the '<' condition block.
  3. Now decide for how many seconds you want to be pumping water into this plant pot (if you have a bigger plant pot maybe 3-5 seconds of water, for a smaller plant perhaps 1-3 seconds of water) then input this number into the 'pause (ms)' block below the first 'digital write pin' block, notice that the ms part stands for milliseconds because the BBC micro:bit doesn't accept seconds in it's 'pause (ms)' blocks the numbers have to be in milliseconds. To do this multiply the number of seconds by 1000 e.g. 3 seconds = 3000 milliseconds.
  4. Finally decide how often you would want this program to check if your plant needs water, (the less it checks the less power it consumes), you have to input the time in milliseconds (e.g. 30 minutes = 1800 seconds = 1800000 milliseconds or 1 hour = 60 minutes = 3600 seconds = 3600000 milliseconds or 2 hours = 120 minutes = 7200 seconds = 7200000 milliseconds).
  5. Enter that number into the 'pause (ms)' block below the 'while true do' block.
  6. Finally click Download and move that hex file into the drive labelled MICROBIT.

Don't be afraid to adjust your values if they're wrong.

Proto-PIC Plant watering kit guide

Now that the code is done let's build the final product.

  1. Unplug the BBC micro:bit from the computer (reattach the moisture sensor if you had to take it off before).
  2. Attach one end of the wires to the GND of the BBC micro:bit (you can attach it onto the side if you don't have enough space, because all those extra pins are also ground pins).
  3. Attach the other end of that wire to the GND of the Proto-Pic Transistor.
  4. Attach the final wire to pin 1 of the BBC micro:bit.
  5. Attach the other end to the SIG part of the Proto-Pic Transistor.
  6. Plug the transistor into the AA battery pack.
  7. Place the pump in a container full of water and direct the pipe into the pot of your plant.
  8. Plug the BBC micro:bit into the AAA battery pack and remember to turn on the AA battery pack. 

How this works

The moisture sensor works as before. When the code detects that the moisture reading is too low, the BBC micro:bit will send a voltage through pin 1 into the SIG pin of the Proto-Pic transistor this will flip the transistor on, allowing the current to flow through the AA battery pack into the pump which will pump water into the plant pot. then the BBC micro:bit will stop sending the voltage which will flip the transistor off, stopping current flow from the AA battery pack, stopping the pump.

If you've done everything correct then your plant pot should have water pumped into it every so often. Don't be afraid to mess around with the timings and threshold number if you think your plant is drowning or not getting enough water. This is what the final product will look like:

Proto-PIC Plant watering kit guide

Congratulations you've learnt a lot about the BBC micro:bit, our transistor and our moisture sensor. Now you no longer have to water the plant, but don't forget to water the container.


FAQ Toggle Content Extension tasks

Check to see if you’re threshold is too high or low, maybe you’re pumping water for too long. Maybe you should wait longer between checking to see if you should water your plant. 

You might have one of those pots with a saucer that keeps excess water and slowly feeds it back to the plant, have a think about whether the moisture sensor could hang in there instead of in the soil, think about if you would have to change the threshold value if you did do that. 

Try coding in an extra bit of text that says “checking soil moisture” before the initial reading so that you can catch when it’s checking the soil moisture. 

You could try and see if you can code it in such a way that you will always be seeing what the sensor is reading while at the same time doing the regular code. 

Maybe you could code it so that when it pumps water it is also recording how much water has been pumped and stops running once a certain water pumping threshold has been reached.

9th Aug 2020

Recent Posts