Lesson at a glance
maze.education/microbit/lessons/plant-moisture-checker
- Grades
- Grades 6 to 9
- Time
- 45 to 60 minutesThe 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 experienceFor 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 RoboticsFits: Grade 7, Term 2 · Where it fits
Learning intentions
Learners will learn to:
- Build a simple circuit with crocodile clips, using the soil as part of it.
- Read an analogue value from a pin and explain what it measures.
- 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.
Introduction
5 to 10 minutesRetrieval practiceWhat does electricity need in order to flow around a circuit? (A complete path, from the power source through the parts and back again.)
Problem statementIn 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.
- Show a wilting plant and a healthy one. Ask: how can you tell when a plant needs water? Could a computer tell?
- Read the problem statement together. Ask: does damp soil let electricity through? Does dry soil? How could a micro:bit use the difference?
Lesson development
35 to 40 minutes- 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.
- 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.
- 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.
- 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.
- 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.
- 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
Input Processing Output 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 down Show moisture instead of a face The reading, as a number Flowchart
- Start
- Switch P1 on, wait 10 ms, read pin P0 into moisture, then switch P1 off
- Is button A held down?Yes: show moisture as a numberNo: ask the next question
- Is moisture below 500?Yes: show the sad face (dry)No: show the happy face (damp)
- 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. Pass Metal pins in A held? moisture The display shows 1 Dry soil No 180 Sad face 2 Dry soil Yes 175 175 3 Damp soil No 640 Happy face 4 Damp soil No 500 Happy face (500 is not below 500) Consolidation
5 to 10 minutes- Groups share their dry and damp readings. Why are they different from group to group?
- 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.
- 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.
These are the MakeCode steps. The other routes are on the lesson's web page.
Build it in MakeCode blocks
- Start a New Project and make a variable called moisture in Variables.
- Open Advanced, then Pins. In forever, add digital write pin P1 to 1, then pause (ms) 10 from Basic.
- Add set moisture to with analog read pin P0 from Pins, then digital write pin P1 to 0.
- 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.
- In the else if, check moisture < 500 and show icon sad. In the else, show icon happy.
- Add pause (ms) 1000 at the end of forever, then Download.
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.
Purple Mash follows the UK school years, which run about one grade ahead of ours: Year 3 is roughly Grade 2 here, Year 4 roughly Grade 3 and Year 5 roughly Grade 4. 2Simple says its micro:bit lessons can be adapted for other ages, so older learners who are new to the micro:bit can use them too.
These steps are our own. 2Simple's lesson has its own plan, slides and videos, which teachers with a Purple Mash login can use alongside this one.
Our steps in Free Code micro:bit
Block names in Free Code micro:bit are not the same as MakeCode's, so these steps say what each block does. Check the exact names in Purple Mash.
- Log in to Purple Mash and open the lesson from the Computing Scheme of Work, or the micro:bit projects in the Computing area. They use Free Code micro:bit, 2Simple's block coding tool for the micro:bit (2Simple's help pages also call it 2Code micro:bit).
- Open Free Code micro:bit from the Conductivity Tester project, and check in Purple Mash which pins it asks you to clip to.
- In a loop that repeats forever, read the pin and show one picture when the reading is low and another when it is high.
- Push the metal pins into dry soil, then damp soil, and use the readings to choose your threshold.
- Test the program on the on-screen micro:bit (2Simple calls it the micro:bit emulator) before you send it to a board.
- Save your work, open the purple menu at the top and choose Download.Hex. Plug in the micro:bit with a USB cable that carries data and drag the .hex file onto the MICROBIT drive. On an iPad, open the file in the micro:bit app and tap Send to micro:bit.
2Simple says the micro:bit projects can also be coded in Python in Pieces, if your school has it.
Extension: text-based coding, beyond the CAPS
The same program in MicroPython, for the micro:bit Python Editor. It suits Grade 7 to 9 learners who are ready for text-based code. The CAPS itself follows a block-based approach (Coding and Robotics CAPS, Grades 7 to 9, page 24).
# Plant moisture checker: leads clipped to pins P0 and P1, their metal pins in the soil. Hold A to see the reading.
from microbit import *
dry = 500
while True:
pin1.write_digital(1)
sleep(10)
moisture = pin0.read_analog()
pin1.write_digital(0)
if button_a.is_pressed():
display.scroll(moisture)
elif moisture < dry:
display.show(Image.SAD)
else:
display.show(Image.HAPPY)
sleep(1000)Open the Python editor, replace the code that is there with this program (or open the downloaded file), then click Send to micro:bit. MakeCode also has a Python view, which is written a little differently.
Extension or homework
Challenges for learners who finish early, or to take further in a club or as homework.
- Challenge 1
Compare two soils, such as sand and potting soil: water both the same way and see which stays damp longer.
- 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.
- Challenge 3
Make the board play a sound on a micro:bit V2 when the soil is dry.
- 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.
- Draw the circuit and mark where the soil completes it.
- What range of values can analog read pin give?
- How did you choose your threshold?
- Why does the program turn P1 off between readings?
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 for | Beginning | Developing | Accomplished | Exemplary |
|---|---|---|---|---|
| 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
- The reading is the same in dry and damp soil.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.
- The reading jumps about.Push the metal pins in as far as they go and keep them the same distance apart. Wait a second between readings.
- It always looks happy.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, 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, 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, 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.
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.


