Skip to the notes
robocupjunior.org.nz

Junior Robotics Notes

an independent NZ guide to classroom robotics

N-08Programming

Build a soil-moisture sensor for the vege garden

A micro:bit or Arduino project that tells you when the vege patch actually needs water, plus why the cheapest probes don't last.

Watering the garden is a surprisingly good robotics problem. The question "does this bed need water?" has a measurable answer, the sensor is cheap, and the result is something the whole household can see: healthier plants and less wasted water. This project works with a micro:bit or an Arduino-style board and suits students from about Year 6 upward with some adult help.

How soil-moisture sensing works

Wet soil conducts electricity better than dry soil, and it also changes how the soil behaves as part of an electrical field. The two common kinds of hobby sensor use these effects differently:

  • Resistive probes are two bare metal prongs. The board passes a small current between them and measures how easily it flows. They are very cheap, but the exposed metal corrodes quickly in damp soil, especially if current flows all the time.
  • Capacitive sensors have their electrodes sealed under a coating and measure the soil's effect on an electrical field instead. They cost a little more but last far longer outdoors.

For a project that will live in a garden bed, a capacitive sensor is usually worth the extra few dollars.

What you need

  • A micro:bit (with an edge-connector breakout) or an Arduino-style board
  • A capacitive soil-moisture sensor with an analog output
  • Jumper wires, and a battery pack suitable for your board
  • A small waterproof box or a clean plastic container with a lid
Sensor wiring: power, ground and signal from the probe to the board board capacitive probe soil 3V power ground signal → analog pin
Fig. 1: three wires. Check your sensor's voltage range matches your board before connecting.

Building it

  1. Wire the sensor to power, ground and an analog input pin. Check the sensor's supply voltage: the micro:bit runs at 3 volts, and some sensors are designed for 5-volt boards.
  2. Read and print the raw value with the probe in the air, in a cup of dry soil and in a cup of freshly watered soil. Write the three numbers down.
  3. Pick a "needs water" threshold between the dry and wet readings. Many capacitive sensors read lower when the soil is wetter, which catches people out, so check your numbers.
  4. Show the result: a happy or sad face on the micro:bit, or an LED on the Arduino.
  5. Only take readings occasionally. Checking every few minutes, rather than constantly, saves battery and is plenty for a garden.

Making the readings mean something

Raw numbers vary between sensors, soils and even how deep the probe goes, so treat the first week as calibration. Note the reading each morning, and whether the plants looked thirsty. After a few days you'll know which number means "water today" for that particular bed.

Push the probe in to the same depth each time and keep the electronics above the soil line. Water and circuit boards don't mix, so the box should stay sealed and the cables should enter from underneath so rain runs off.

Going further

  • Log the data. Record readings over a week and graph them. Students can see the soil dry out through a hot afternoon and recover after watering.
  • Compare beds. Use two sensors to compare a mulched bed with a bare one. The difference is usually striking and makes a good science-fair question.
  • Add a radio alert. With two micro:bits, the garden one can send a radio message to an indoor one that beeps when watering is needed.
  • Think about automatic watering, carefully. Driving a small pump or valve is possible, but it involves water, power and an adult. Start with alerts and let a person decide.

Why this is good learning

This project covers sensing, calibration, thresholds, power management and weatherproofing, all in one small build. It also ties nicely into science topics about soil, plants and the water cycle, and it gives students a reason to go outside and check their own data.

Testing the sensor honestly

Before trusting the gadget, test it against a simple method. Push a finger a few centimetres into the soil next to the probe at the same time each day and record whether it feels dry, damp or wet. After a week, compare the finger test with the sensor readings. If they agree most of the time, the threshold is about right; if not, adjust it. This kind of check is called validation, and it's what separates a reliable instrument from a gadget that just shows numbers.

Different plants need different amounts of water, too. Leafy greens and seedlings tend to need more frequent watering than established herbs, so a single threshold for the whole garden may not suit every bed. Students can set separate thresholds for separate sensors and see whether the plants respond.

Sources: Arduino analog input guide; micro:bit project library.