Kōkiri Learn

Background reading · Technology

Sensors, decisions and smart traps

How sensors turn the world into numbers, how code decides what to do, and how New Zealand conservation groups use smart traps.

A computer cannot see the dark, feel the soil or hear a trap snap shut. It only understands numbers. A sensor is the translator: it turns something in the real world into an electrical signal that the computer can read as a number.

Two kinds of signal

  • Digital: only two states, on or off, like a button that is pressed or not pressed. - Analogue: a range of values, like a light sensor that gives 0 in total darkness and 255 in bright sun. On a micro:bit, the pins read analogue values from 0 to 1023.
  • The trigger level

    Your code has to decide what number counts as 'dark' or 'dry'. That number is the trigger level, or threshold. Pick it too high and you get false alarms. Pick it too low and the system misses real events. The only way to choose well is to measure first: record the readings in both conditions and pick a number in between.

    If this, then that

    Code makes decisions with conditions: 'if the soil reading is below 300, show a sad face and beep, else show a happy face'. Put the check inside a forever loop so it keeps checking. This is the process part of your system.

    From decision to movement

    When an electronic circuit controls a mechanical part, like a motor that opens a gate, it is called an electro-mechanical system. A servo motor is handy because your code can tell it to turn to an exact angle, like 90 degrees, and hold it there. Milking sheds, automatic doors and robot vacuum cleaners are all electro-mechanical.

    Smart traps in Aotearoa

    Community groups all over the country are trapping rats, stoats and possums to protect native birds, working towards Predator Free 2050. Checking hundreds of traps on foot takes a lot of time. Some groups now fit sensors to their traps. When a trap goes off, the sensor sends a radio message to a hub, which passes it on over the internet, so volunteers can go straight to the traps that need resetting. The same ideas are in your micro:bit trap alert, just on a smaller scale.

    Reliability matters. A smart trap that cries wolf wastes a volunteer's day. A night light that fails leaves someone in the dark. That is why engineers test systems many times and count the failures before anyone depends on them.

    Sources and further reading

    Written for Kōkiri Learn students in our own words. Check facts against the sources.

    Used in: Smart Circuits: Electronics and Control