Plant moisture checker

Two crocodile clip leads and a pot plant: the micro:bit measures how damp the soil is and asks for water when it is dry.

Go to the code ↓

Lesson at a glance

45 to 60 minutes · Grades 6 to 9

maze.education/microbit/lessons/plant-moisture-checker

Grades
Grades 6 to 9
Time
45 to 60 minutes
The CAPS gives Coding and Robotics 2 hours a week (Coding and Robotics CAPS, Grades 4 to 6, page 22; Grades 7 to 9, page 22).
Level
Some experience
For classes that have used the micro:bit and MakeCode once or twice.
Board
Any micro:bit
Code with
MakeCode and Purple Mash blocks, with Python as an extension
CAPS
Natural Sciences and Technology, Technology, Natural Sciences, Coding and Robotics
Fits: Grade 7, Term 2 · Where it fits

Learning intentions

Learners will learn to:

  1. Build a simple circuit with crocodile clips, using the soil as part of it.
  2. Read an analogue value from a pin and explain what it measures.
  3. Calibrate a sensor with dry and wet soil, and choose a threshold.

Success criteria

Each learner can say:

  • I can build the circuit with two crocodile clip leads and show where the soil completes it.
  • I can read the value on pin P0 and explain that it shows how easily electricity passes through the soil.
  • I can calibrate the checker in dry and damp soil and choose a threshold between the two readings.
  • Grades 7 to 9: I can trace moisture and the display through four passes of the loop.

Competencies

From the Coding and Robotics CAPS places this lesson cites.

  • R.5Design a simple artefact based on a set of design instructions
  • R.6Mimic the operations of a robot

Key words

circuit
A complete path that electricity can flow around.
conductor
A material that lets electricity flow through it easily.
analogue
A value that can be anything in a range. The micro:bit reads pins from 0 to 1023.
calibrate
To measure known conditions (here, dry and wet soil) so readings mean something.
threshold
The value where a decision changes, such as dry below 500.
flowchart
A diagram of the steps and decisions in a process, read from the top.
trace table
A table that follows the value of each variable, step by step, as a program runs.

What you need

  • One micro:bit per group, with a USB cable and a battery holder
  • One pack of crocodile clip leads per group: four leads, each with a clip at one end and a metal pin at the other (this lesson uses two)
  • Two small pots of soil per group, one dry and one damp (or one pot plant), and a computer with Chrome or Edge

From our shop: BBC micro:bit V2 Go, Kitronik crocodile clip leads (4 pack), micro:bit Battery Box (Switched)

Safety

  • Never clip the 3V pin to the GND pin: that is a short circuit, and it drains the batteries and makes them hot. Use the crocodile clips only with the micro:bit's own batteries, never with mains electricity.
  • Wipe the metal pins clean and dry after the lesson, and wash hands after handling soil.
  • Water the plant only with the micro:bit and battery holder well away from the pot. Only the metal pins of the leads go in the soil.

The lesson plan

One lesson of 45 to 60 minutes in three parts: introduction, lesson development and consolidation. The CAPS gives Coding and Robotics 2 hours a week, so it fits one of the week's lessons. Times are a guide.

  1. Introduction

    5 to 10 minutes
    Retrieval practice

    What does electricity need in order to flow around a circuit? (A complete path, from the power source through the parts and back again.)

    Problem statement

    In a drought or under water restrictions, the school's vegetable garden should get water only when the soil really needs it, and dry soil on top can hide damp soil underneath. Build a moisture checker that measures the soil and tells you when a plant needs water.

    1. Show a wilting plant and a healthy one. Ask: how can you tell when a plant needs water? Could a computer tell?
    2. Read the problem statement together. Ask: does damp soil let electricity through? Does dry soil? How could a micro:bit use the difference?
  2. Lesson development

    35 to 40 minutes
    1. Unplugged first. Draw the circuit together: pin P1, a lead, its metal pin, the soil, the second metal pin, the second lead, pin P0. Mark where the soil completes the path.
    2. Plan on paper first. Groups fill in an IPO table for the checker and draw it as a flowchart with two decisions in order: is A held down? Is moisture below the threshold? Grades 7 to 9 add a trace table for four passes of the loop.
    3. Predict. Before anything is connected, ask: will the reading on P0 be higher in dry soil or in damp soil? Groups write a guess for each, from 0 to 1023.
    4. Build in blocks. Clip one crocodile lead to pin P0 and one to pin P1, and push the metal pins on the other ends into the soil, about 3 cm apart. Two learners share the computer at a time: the driver builds the program from the Blocks tab, and the navigator checks each block against the flowchart. Swap roles halfway, at the if then else block. Download it.
    5. Test and debug. Calibrate: hold A to see the reading in dry soil, then in damp soil, and record both. Did they match your prediction? Readings differ between boards and soils, so trust your own numbers. Choose a threshold between the two, change 500 to your number and download again. The micro:bit should look sad in dry soil and happy in damp soil. If the reading is the same in both, check the clips and the metal pins.
    6. Check the threshold: if you have a dry pot and a damp pot, move the metal pins between them a few times and see that the face changes each time. With one pot plant, test it before and after watering, with the micro:bit well away from the pot.

    Plan on paper: a model answer

    In groups, fill in an IPO table and draw the checker as a flowchart. Grades 7 to 9 also trace four passes of the loop.

    IPO table
    InputProcessingOutput
    The soil between the two metal pins (the reading on pin P0, from 0 to 1023)Switch P1 on, wait 10 ms, read P0 into moisture, then switch P1 off. Is moisture below the threshold (500)?Below 500 (dry): a sad face. 500 or more (damp): a happy face
    Button A, held downShow moisture instead of a faceThe reading, as a number
    Flowchart
    1. Start
    2. Switch P1 on, wait 10 ms, read pin P0 into moisture, then switch P1 off
    3. Is button A held down?Yes: show moisture as a numberNo: ask the next question
    4. Is moisture below 500?Yes: show the sad face (dry)No: show the happy face (damp)
    5. Wait 1 second, then measure again, forever
    Trace table
    Grades 7 to 9: four passes of the loop with a threshold of 500. The readings are examples; your board and soil will give their own.
    PassMetal pins inA held?moistureThe display shows
    1Dry soilNo180Sad face
    2Dry soilYes175175
    3Damp soilNo640Happy face
    4Damp soilNo500Happy face (500 is not below 500)
  3. Consolidation

    5 to 10 minutes
    1. Groups share their dry and damp readings. Why are they different from group to group?
    2. Ask: why does the program switch P1 on only for the moment it measures? It saves the batteries, and the metal pins in the damp soil wear away more slowly.
    3. Back to the problem: could your checker tell the garden club when to water during restrictions? Where else could it help at school: the vegetable patch, the plants in the foyer? Learners check themselves against the success criteria.

Build it, step by step

Pairs build the program in blocks, following the numbered steps, with the same program as text beside them to check against or paste. Test in the simulator before sending it to a board.

Wiring diagram: two crocodile clip leads are clipped to pin 0 and pin 1 on the micro:bit's bottom edge, and the metal pins at their other ends are pushed into a pot of soil about 3 cm apart. Pins 2, 3V and GND are not used.
Clip one lead to pin 0 and one to pin 1, and push the metal pins on the other ends into the soil. The soil between the metal pins completes the circuit.

These are the MakeCode steps. The other routes are on the lesson's web page.

Build it in MakeCode blocks

  1. Start a New Project and make a variable called moisture in Variables.
  2. Open Advanced, then Pins. In forever, add digital write pin P1 to 1, then pause (ms) 10 from Basic.
  3. Add set moisture to with analog read pin P0 from Pins, then digital write pin P1 to 0.
  4. From Logic, add an if then else and click its plus sign once to add an else if. In the if, put button A is pressed from Input, with show number moisture inside.
  5. In the else if, check moisture < 500 and show icon sad. In the else, show icon happy.
  6. Add pause (ms) 1000 at the end of forever, then Download.
The same blocks as text (to paste into MakeCode)
let moisture = 0
basic.forever(function () {
    pins.digitalWritePin(DigitalPin.P1, 1)
    basic.pause(10)
    moisture = pins.analogReadPin(AnalogReadWritePin.P0)
    pins.digitalWritePin(DigitalPin.P1, 0)
    if (input.buttonIsPressed(Button.A)) {
        basic.showNumber(moisture)
    } else if (moisture < 500) {
        basic.showIcon(IconNames.Sad)
    } else {
        basic.showIcon(IconNames.Happy)
    }
    basic.pause(1000)
})

To use the text instead: open MakeCode, start a new project, click JavaScript at the top, replace what is there with this code, then click Blocks to see it as blocks.

To send it to the board, click Download. In Chrome or Edge, MakeCode can connect to the micro:bit by USB so the program goes straight onto it. Otherwise a .hex file downloads: drag it onto the MICROBIT drive.

Extension or homework

Challenges for learners who finish early, or to take further in a club or as homework.

  1. Challenge 1

    Compare two soils, such as sand and potting soil: water both the same way and see which stays damp longer.

  2. Challenge 2

    Send the reading by radio to a board on the teacher's desk, so you know when the plant needs water without walking over.

  3. Challenge 3

    Make the board play a sound on a micro:bit V2 when the soil is dry.

  4. Challenge 4

    Add a warning light, as in the Grade 7 CAPS soil moisture artefact: make all 25 of the micro:bit's own lights flash when the soil is dry.

Support and extension

Support

For learners who need more help

  • Set up the leads for each group, so learners focus on reading and recording.
  • Give the threshold of 500 to start with, and adjust it together.

Extension

For learners who are ready for more

  • Add a middle band: if the reading is between dry and wet, show a meh face.
  • Measure every hour for a day with the data logger (see the Data logger lesson) and graph how fast the soil dries.

Informal assessment

Ask these as learners work. Informal assessment happens every day and is not recorded.

  1. Draw the circuit and mark where the soil completes it.
  2. What range of values can analog read pin give?
  3. How did you choose your threshold?
  4. Why does the program turn P1 off between readings?
Exit question

Your dry reading is 210 and your damp reading is 690. Choose a threshold and explain your choice.

Observation checklist

Watch pairs as they plan, build and test. Write each pair's initials under the level you see.

Watch forBeginningDevelopingAccomplishedExemplary
Connects the leads firmly to P0 and P1, with their metal pins apart in the soil.
Draws the flowchart with both decisions in the right order.
Predicts which soil gives the higher reading, then checks it.
Calibrates in dry and damp soil and chooses a threshold between the readings.
Explains what the reading on P0 measures.
Beginning:
not yet, even with help
Developing:
with help
Accomplished:
on their own
Exemplary:
on their own, and explains it or takes it further

The four levels are the CAPS rubric levels (Coding and Robotics CAPS, Grades 4 to 6, page 176; Grades 7 to 9, page 163). The short descriptions are ours.

This lesson is not a formal task, but it is good practice for the term's practical task in Grades 4 to 6 (Coding and Robotics CAPS, Grades 4 to 6, page 170), and for the mini-PATs in Grades 7 to 9 (Coding and Robotics CAPS, Grades 7 to 9, page 157).

Common mistakes and fixes

  • Problem: The reading is the same in dry and damp soil.Fix: Check each clip is firmly on its micro:bit pin, that both metal pins are in the soil, and that they are not touching each other.
  • Problem: The reading jumps about.Fix: Push the metal pins in as far as they go and keep them the same distance apart. Wait a second between readings.
  • Problem: It always looks happy.Fix: Your threshold is lower than the dry reading. Calibrate again and choose a number between the two.

Where it sits in CAPS

  • Coding and RoboticsFitsGrade 7, Term 2: a soil moisture artefact with two simple probes and a micro:bit, which shows a message when the soil is dry.Source: Coding and Robotics CAPS, Grades 7 to 9 (opens in a new tab), Grade 7, Term 2, Robotics, R.5 Design a simple product (artefact) based on a set of design specifications, with R.6, page 70: The learners design a simple soil moisture sensor artefact using a plant and two simple probes (e.g., nails, screws) and an LED + MicroBit.
  • Coding and RoboticsFitsGrade 9, Term 2: reading an analogue input from 0 to 1023, the CAPS's second version of the soil moisture artefact.Source: Coding and Robotics CAPS, Grades 7 to 9 (opens in a new tab), Grade 9, Term 2, Robotics, R.5 Design a simple artefact based on a set of design instructions, with R.6, page 138: the learners are introduced to the concept of Analogue input (values 0 to 1023)
  • TechnologyGrade 9 Technology: a moisture detector as an input device that completes a circuit.Source: CAPS Technology, Grades 7 to 9 (opens in a new tab), Grade 9, Term 3: Electrical / Electronic Systems (sensors as input devices): Touch or moisture detector
  • Natural SciencesFits Natural Sciences: plants need water, and damp soil conducts electricity better than dry soil.

Coding and Robotics quotes come from the Department of Basic Education's final CAPS, with the page number of the 2024 printed edition (the Department's October 2025 library copies number their pages differently). Schools may teach a topic in another term: the CAPS leaves the order to each school's annual teaching plan.

Ready to teach it?

Get a micro:bit for every learner or pair, and let us train your staff to run lessons like this one.

More lessons

All lessons →
  • Grades 6 to 9

    Grades 6 to 945 to 60 minLevel: Some experience

    Reaction timer

    Wait for the dot, then press A as fast as you can: learners time their reactions in milliseconds and analyse the class's data.

    Subjects: Mathematics · Coding and Robotics

    Code with: MakeCodePython

  • Grades 6 to 9

    Grades 6 to 945 to 60 minLevel: Confident coders

    Traffic lights

    Learners program a robot (a South African traffic light) with a pedestrian button, and plan the system as a flowchart first.

    Subjects: Natural Sciences and Technology · Technology · Coding and Robotics

    Code with: MakeCodePython

  • Grades 6 to 9

    Grades 6 to 945 to 60 minLevel: Confident coders

    Catch the drop

    A drop falls from the top, the player moves a basket with A and B: learners code a small game with sprites, coordinates and a score.

    Subjects: Coding and Robotics · Mathematics

    Code with: MakeCodePython

micro:bit is a trade mark of the Micro:bit Educational Foundation, and BBC is a trade mark of the British Broadcasting Corporation. Maze Education is an independent reseller of genuine BBC micro:bit products. Our teacher training and our other products and services are our own, and are not endorsed by the Foundation or the BBC.

WhatsApp