Skip to main content

10.4

Major VersionM

by Pete Prodoehl

Introduction

Note: This version of the guide was created for use with the Bit Board V1 and a Resistive Moisture Sensor. We have an updated guide in progress that works with the Bit Board V2 and a Capacitive Moisture Sensor.

Use a micro:bit with a Bit Board to check if your plant needs water, and then water it using a pump.

Video Overview

Featured Document

  1. A Moisture Sensor is capable of reading the conductivity between two legs of a probe inserted into soil or other material that contains moisture. Basically, a small electrical charge travels from one leg of the probe to the other and the resistance is what is measured.
    • A Moisture Sensor is capable of reading the conductivity between two legs of a probe inserted into soil or other material that contains moisture.

    • Basically, a small electrical charge travels from one leg of the probe to the other and the resistance is what is measured.

    • The control board that the probe plugs into can output a voltage which can then be read by an analog pin on a microcontroller.

    • After reading the sensor the micro:bit will show a value between 0 and 1023. In the case of this sensor, 1023 is maximum resistance (or no current flowing) and 0 is no resistance (or maximum current flowing).

    • For our use, 1023 would mean the probe is inserted into dry soil. Not good for a plant! If we get a reading less than 400 it means our soil is pretty wet.

  2. The Moisture Sensor consists of two parts, the YL-38 control board, and the YL-69 probe. The probe connects to the control board with two F/F Jumper Wires, and then the control board connects to the Bit Board with three F/F Jumper wires. We use a + (positive) and - (negative) pin on the Bit Board to power the control board, and then connect the AO pin on the control board to Pin 1 on the Bit Board so we can read the analog value coming from the sensor.
    • The Moisture Sensor consists of two parts, the YL-38 control board, and the YL-69 probe. The probe connects to the control board with two F/F Jumper Wires, and then the control board connects to the Bit Board with three F/F Jumper wires.

    • We use a + (positive) and - (negative) pin on the Bit Board to power the control board, and then connect the AO pin on the control board to Pin 1 on the Bit Board so we can read the analog value coming from the sensor.

    • The + (positive) pin can plug into any + pin in the positive column, and the - (negative) pin can plug into any - pin in the negative column.

    • You don't need to align the pins in a row. The wire from the AO pin must go to Pin 1, but the positive and negative can go to any positive and negative pin, respectively.

  3. Connect a USB cable to the micro:bit and then plug it into your computer.
    • Connect a USB cable to the micro:bit and then plug it into your computer.

    • We'll be using makecode.microbit.org to program our board. It uses a simple drag and drop block interface.

    • We're going to load the following code for our Moisture Sensor Reading program: https://makecode.microbit.org/_CCpgM4Eat...

    • The code is very simple. It's going to turn on the LED matrix on the micro:bit, and then read and show the value it gets from the Moisture Sensor by scrolling it across the LEDs on the micro:bit

    • Once you've got your Moisture Sensor connected and you load the code you should see a number scroll across the LED matrix. It will probably be “1023” if you haven’t inserted the probe into anything.

    • If you do not see 1023 scroll across the LED matrix, check your wiring. Make sure everything is plugged into the correct place.

  4. We can provide power to the micro:bit and Bit Board by using a USB cable (which we used for programming the micro:bit in a previous step) or by using a 2 AAA Battery Pack.
    • We can provide power to the micro:bit and Bit Board by using a USB cable (which we used for programming the micro:bit in a previous step) or by using a 2 AAA Battery Pack.

    • The USB cable provides 5 volt power from a computer or USB wall adapter or battery pack, and the voltage regulator on the micro;bit drops the 5 volts down to 3.3 volts to provide power.

    • A battery pack with two AAA batteries provides just over 3 volts when using two fresh alkaline batteries. This also helps if you want your project to be a bit more portable.

  5. Now that we are seeing readings from the Moisture Sensor, we should insert the probe into some soil! Grab your favorite houseplant and push the probe into the soil. You should start to see a new value scroll across the LED matrix on the micro:bit (unless the soil is too dry!) Grab your favorite houseplant and push the probe into the soil. You should start to see a new value scroll across the LED matrix on the micro:bit (unless the soil is too dry!)
    • Now that we are seeing readings from the Moisture Sensor, we should insert the probe into some soil!

    • Grab your favorite houseplant and push the probe into the soil. You should start to see a new value scroll across the LED matrix on the micro:bit (unless the soil is too dry!)

  6. For this step it may take a bit of trial and error to get it just right. If your soil is too dry (based on what your plant needs) add some water. You should see the value displayed on the LED matrix get lower. Warning! Water and electronics do not mix! While the Moisture Sensor is meant to be in wet soil, water should not touch other parts of your electronics. Be careful around the probe wires, the control board, and your micro:bit
    • For this step it may take a bit of trial and error to get it just right. If your soil is too dry (based on what your plant needs) add some water. You should see the value displayed on the LED matrix get lower.

    • Warning! Water and electronics do not mix! While the Moisture Sensor is meant to be in wet soil, water should not touch other parts of your electronics. Be careful around the probe wires, the control board, and your micro:bit

    • Once you have your plant soil to a state that you consider wet enough, make note of the number. For our plant it was around 700.

  7. Now that we've seen the Moisture Sensor in action, let's try some new code! We're going to load the following code for our Moisture Sensor Alarm program:  https://makecode.microbit.org/_RXkYgP7L6...
    • Now that we've seen the Moisture Sensor in action, let's try some new code!

    • We're going to load the following code for our Moisture Sensor Alarm program: https://makecode.microbit.org/_RXkYgP7L6...

    • For this version we have two variables to consider: dryPlant and reminderTime

    • The dryPlant variable will be set higher than the number we determined in our calibration step. Since we found 700 to be a good amount of moisture for the soil, we'll use 800 for our threshold.

    • The reminderTime variable will set how often we see the sad face on the LED matrix and hear a beep.

    • And yes! We are going to add an alarm as well. See the next step!

  8. We're going to add a Crazy Circuits Piezo Speaker to our circuit, using some 1/8" Maker Tape. Connect the Piezo Speaker between Pin 8 and GND. (Make note of the polarity!) Now when the soil is too dry (based on the number you assigned to dryPlant you will see a sad face, and hear a beep. This will happen every 10 seconds (or whatever interval you set for the reminderTime variable.)
    • We're going to add a Crazy Circuits Piezo Speaker to our circuit, using some 1/8" Maker Tape.

    • Connect the Piezo Speaker between Pin 8 and GND. (Make note of the polarity!)

    • Now when the soil is too dry (based on the number you assigned to dryPlant you will see a sad face, and hear a beep. This will happen every 10 seconds (or whatever interval you set for the reminderTime variable.)

  9. While these Moisture Sensors are cheap (we got a 5 pack for less than $8) they use resistive measurement, which means that eventually one of the probe legs will corrode to the point that it will no longer work. We've got a good workaround though, using Maker Tape! We used 1/8" Maker Tape and just wrapped a piece around each of the probe legs. Since Maker Tape is conductive on both sides and all the way through, it will conduct and protect at the same time. If you see the Maker Tape start to wear out or corrode, it's a simple process to peel it off, remove any residue, make sure the probe is nice and dry, and then put a new piece in place.
    • While these Moisture Sensors are cheap (we got a 5 pack for less than $8) they use resistive measurement, which means that eventually one of the probe legs will corrode to the point that it will no longer work. We've got a good workaround though, using Maker Tape!

    • We used 1/8" Maker Tape and just wrapped a piece around each of the probe legs. Since Maker Tape is conductive on both sides and all the way through, it will conduct and protect at the same time.

    • If you see the Maker Tape start to wear out or corrode, it's a simple process to peel it off, remove any residue, make sure the probe is nice and dry, and then put a new piece in place.

    • Make sure you do your calibrations after you attach the tape, as it may slightly affect the reading from the sensor.

  10. We found a DC powered water pump that was meant to run on 12 volts, but it worked fine on 9 volts so we could easily use a 9 volt battery. Make sure your pump can run using your desired power source, or get a power source that will properly run your pump.
    • We found a DC powered water pump that was meant to run on 12 volts, but it worked fine on 9 volts so we could easily use a 9 volt battery.

    • Make sure your pump can run using your desired power source, or get a power source that will properly run your pump.

    • Test the pump by putting both hoses into a cup of water and pull one up, and then the other, until you can confirm it is pumping water.

    • You may want to make note of which hose is the input and which is the output. (Though you can easily swap them if you get it wrong .)

    • Also, a bit of good luck... With some standard LEGO bricks we made simple mounts to hold the motor and the 9 volt battery in place on our baseplate.

  11. Since we've already got a functional system using the Moisture Sensor that can check when the soil is too dry all we need to do is add in our pump and change the code. Once you've finished testing things you may want to secure the water hose in place so it can't come out and spray water in unexpected places. (A bit of tape should do the trick!)
    • Since we've already got a functional system using the Moisture Sensor that can check when the soil is too dry all we need to do is add in our pump and change the code.

    • Once you've finished testing things you may want to secure the water hose in place so it can't come out and spray water in unexpected places. (A bit of tape should do the trick!)

  12. You'll need something to store and draw water from. We had a red plastic cup on hand and a bit more good luck - easily built a LEGO holder on our baseplate that fit it perfectly. Warning! Water and electronics do not mix! Water should not come into contact with your electronics. Be careful around the probe wires, the control board, the motor, batteries, and your micro:bit If you want a bit of added safety use a water bottle and add a good amount of tape around the opening at the top.
    • You'll need something to store and draw water from. We had a red plastic cup on hand and a bit more good luck - easily built a LEGO holder on our baseplate that fit it perfectly.

    • Warning! Water and electronics do not mix! Water should not come into contact with your electronics. Be careful around the probe wires, the control board, the motor, batteries, and your micro:bit

    • If you want a bit of added safety use a water bottle and add a good amount of tape around the opening at the top.

  13. Since we can't control a DC motor directly from the micro:bit we're going to use the Bit Board's built-in relay, which is basically a "smart switch" we can turn on and off using code. The relay is turned on (and completes the circuit) by turning on Pin 16 of the micro:bit - Basically the same way you would turn on an LED is how you turn on the relay. We've got an entire guide on the Bit Board Relay and how it works. It's worth a read if you've never used a relay before.
    • Since we can't control a DC motor directly from the micro:bit we're going to use the Bit Board's built-in relay, which is basically a "smart switch" we can turn on and off using code.

    • The relay is turned on (and completes the circuit) by turning on Pin 16 of the micro:bit - Basically the same way you would turn on an LED is how you turn on the relay.

    • We've got an entire guide on the Bit Board Relay and how it works. It's worth a read if you've never used a relay before.

    • Note: If you don't have a Screw Terminal Chip handy you can always use Maker Tape to connecting wires. Check out the guide on using Tape to Wire Connections to see how it's done.

  14. Now that we've got our water pump added let's load some new code that will use it!
    • Now that we've got our water pump added let's load some new code that will use it!

    • We're going to load the following code for our Plant Watering System program: https://makecode.microbit.org/_LqCDaFXRq...

    • We have a few new variables. The first is waterTime which will set how long the pump runs for. This will affect how much water is added to the soil. You'll need to adjust this for your specific needs.

    • The next one is restTime which will set how long the system waits before checking for water again. This gives the system a break so it doesn't add too much water.

    • You don't want to over-water your plant! Chances are it may only need water once a day at the most. You can probably set the restTime to a high number.

    • Remember, the pause command works with seconds, so if you wanted 1 hour it would be 3600 seconds, 12 hours would be 43200 seconds, and one day (24 hours) would be 86400.

    • If you set the restTime to 86400 they you would make sure your plant never gets watered more than once per day.

  15. Hopefully you've already tested the Moisture Sensor in the first part of this guide, and you've also tested your water pump. Now that you've got it all together, test it again! If you want to "trick" your probe into thinking the soil is dry just pull it out of the soil and the value should go high enough to cause the pump to run.
    • Hopefully you've already tested the Moisture Sensor in the first part of this guide, and you've also tested your water pump. Now that you've got it all together, test it again!

    • If you want to "trick" your probe into thinking the soil is dry just pull it out of the soil and the value should go high enough to cause the pump to run.

    • Remember! You will need to experiment to determine how much water your plant needs, how often you should check the soil, etc. Gather information and make decisions based on what you've learned.

  16. Like many of our projects, we are working with a cause and effect, and we're using a sensor to collect data and do something based on that input.
    • Like many of our projects, we are working with a cause and effect, and we're using a sensor to collect data and do something based on that input.

    • Feel free to change the code to do other things or alter the behavior of the system. Maybe you want to use two Moisture Sensors for a larger pot so you can average the readings.

    • Maybe the numbers don't matter to you and you just want to see a happy face when the soil is wet enough. Make changes and make this project your own!

Finish Line

Pete Prodoehl

Member since: 03/04/2020

281 Reputation

278 Guides authored

0 Comments

Add Comment

View Statistics:

Past 24 Hours: 1

Past 7 Days: 5

Past 30 Days: 28

All Time: 1,109