Skip to the notes
robocupjunior.org.nz

Junior Robotics Notes

an independent NZ guide to classroom robotics

N-09Programming

A motion-sensor camera for the garden

Build a PIR-triggered camera to watch garden wildlife, spot wasp flight paths and visiting pests, and know when to call in a professional.

Setting up a camera that takes a picture whenever something moves in the garden is a brilliant student project. It combines a sensor, a trigger and a bit of programming, and the results are genuinely exciting: birds at the feeder, a hedgehog at night, a cat that visits far more often than anyone realised. It can also help a household understand what pests are around, including wasps and rodents.

How motion sensing works

Most hobby motion sensors are passive infrared (PIR) sensors. Warm bodies give off infrared radiation, and a PIR sensor detects changes in the infrared it sees across its field of view. When a warm animal moves past, the sensor's output switches on. It doesn't see shapes, and it doesn't react to cold objects moving, which is why a branch blowing in the wind usually won't trigger it, though sun-warmed surfaces sometimes do.

Because insects are small and close to air temperature, a PIR sensor generally won't notice a single wasp. For insects you need a different approach, such as timed photos or video, described below.

Two ways to build it

Option 1: Raspberry Pi with a camera module

A Raspberry Pi is a small computer that can run Python and connect to a camera module. Wire a PIR sensor to one of its input pins, and a short Python program can take a photo each time the sensor triggers, saving it with the date and time in the filename. The Raspberry Pi Foundation's free project guides include step-by-step builds along these lines.

Option 2: Micro:bit as a trigger

A micro:bit can't take photos itself, but it can read a PIR sensor and log the time of every trigger. That alone is useful: a graph of "movement events by hour" shows when the garden is busiest, without any images to store or worry about.

Setting it up

  1. Test indoors first. Walk past the sensor at different distances to see its range and how long it stays triggered.
  2. Choose a spot with a clear view of a likely path: a fence line, a feeder, a gap under a hedge.
  3. Protect the electronics in a weatherproof box, with the camera looking out through a clear window and the PIR sensor exposed or behind a suitable cover.
  4. Avoid direct sun on the sensor's view, which causes false triggers as surfaces heat up.
  5. Respect privacy. Point the camera at your own garden only, not neighbours' windows, the street or footpaths.

Watching for wasps and pests

New Zealand has some of the highest densities of German and common wasps in the world. These introduced wasps harm native birds and insects and are a hazard to people. A camera can help with one practical question: where are the wasps coming from?

In late summer, wasps fly fairly direct routes between a food source and their nest. A camera set to take a short video every few minutes near a spot where wasps gather (rather than relying on PIR) can show which direction they leave in. Over a few days, that can narrow down where a nest might be.

Do not go looking for the nest, and never disturb one. Wasp nests can contain thousands of insects that defend the nest aggressively. If you find or suspect a nest on your property, keep children and pets away, and contact a professional pest controller, such as a wasp nest removal service, or follow the Department of Conservation's guidance on wasp control. Students should observe from a distance only.

The same camera can reveal night-time visitors such as rats or possums. That information is useful to pass on to whoever handles pest control at your place, and it makes for some memorable night-vision footage.

Making sense of the results

  • Count visits by species and by hour, and graph them.
  • Compare a week with the feeder out against a week without.
  • Note the weather each day and see whether it changes visitor numbers.

This is citizen science in miniature: a question, a measuring tool, careful records and an honest look at what the data does and doesn't show.

Managing all those photos

A motion camera can take hundreds of pictures a day, many of them of swaying shadows or the family dog. Plan how you'll handle them before the first run. Name each file with the date and time, store them in a folder per day, and set aside ten minutes every couple of days to sort them. Older students can write a short script that counts photos per hour automatically, which turns a pile of images into a useful table.

Sources: Department of Conservation: wasps; Raspberry Pi Foundation projects.