Here’s one way to set up a self-watering system for a potted plant.
For this version you’ll need:
- 1 micro:bit
- 1 sensor:bit
- 1 sensor:bit compatible relay
- 1 sensor:bit compatible water pump
- 1 soil moisture sensor (this tutorial uses the DF robot capacitive soil moisture sensor)
I recommend starting by connecting your soil moisture sensor and figuring out the following:
- What value does the soil moisture sensor show when you place it in dry soil?
- What value does the soil moisture sensor show when you place it in wet soil?
- What type of soil moisture do the plants you’re growing prefer? If it’s “well-drained”, for example, figure out what number the soil moisture sensor shows when the sensor is placed in well-drained soil
Write these values down or save them somewhere on your computer because we’ll use them to write the code for this self-watering system.
Next, connect the water pump to the sensor:bit and test it out to make sure it’s working.
I like to write tiny programs like the one below to test out my electronics before I finalize my code. This program lets me turn the water pump on and off with the micro:bit buttons.
https://makecode.microbit.org/_YAdgz8beRArg
Once I have the soil moisture values and I’m sure the water pump works. I’ll make sure that all of my electronics are plugged in and then upload my code (posted below). This program reads the soil moisture level and if it’ less than 540 (the wet soil value) it will turn the water pump off, if it’s above 700 (the dry soil value) it will turn the water pump on, then the program pauses for a minute to allow the water to be absorbed into the soil before repeating the loop.
note: for this soil moisture sensor, the higher the sensor reading the drier the soil is. This is a little different than the way other soil moisture sensors work.
https://makecode.microbit.org/_5WLfC7adMVzK



