Quick, cheap and dirty Pi motion detection

From UmbraXenu
Jump to: navigation, search

Passive Infra-Red detectors or PIRs are a popular and easy method of motion detection. They are simple, cheap and ideal for most projects.

There are many easy tutorials on using PIR detectors with the Pi, like this one, but what do you do when you want it now, there are no local parts places, and ordering can balloon in cost with shipping/tax and involves waiting?

Reduction to a problem already solved

Swiss+Tech unit in packaging.
Swiss+Tech board topside.
Swiss+Tech board underside.

Enter the discount stores: Dollarama, Dollar Store, Poundland, etc. These stores are everywhere and great low-priced graveyards of small electronics that can be re-purposed to other projects. I've picked all kinds of stuff in these places: webcams, Bluetooth buttons, USB battery packs, etc, for pocket change. (See bigclivedotcom's YouTube channel. If you're curious about something, check his channel, because he's probably already taken one of them apart.)

There will probably be a variety of motion detection items: outdoor floodlights, etc. For this, I chose a Swiss+Tech salt shaker-sized motion-detection nightlight for a few dollars. (The company is in Ohio, the units are made in China, but it's Swiss+Tech, hmm.)

The unit takes 3 AAA batteries, has a switch on the side to turn it on. When it detects movement, it lights up for 45 seconds then switches off. I don't know if I need the nightlight, but why not? (I can already navigate by all the LEDs in my room, even with the blue ones taped over.) The case will be useful, so that I can place it wherever I need it and run a cable back to the Pi. With some sealant, the case might be weather-proofable.

A Deconstruction of Falling Parts

On the back, there's a screw for the battery cover, which fits snuggly. The case is held together by three snap-fit tabs on each side. I had no luck wedging a very fine straight-tip screwdriver into the front/back seam to pop it open. In the end, I used pliers to break a piece off the back and pop it open from the inside. I can run a cable out through the hole, so it's not a big loss. Now that I know where the tabs are, I might have more luck with the second unit.

The circuit is an old school single layer PC board with the PIR detector, IC, 2 white LEDs, 2 transistors, various full size resistors and capacitors. A nice touch is that the components are labeled with their value rather a part number. It's quite easy to work with without a microscope and soldering micro-waldo. The AAA batteries and power switch run to connections on the board. The board was mounted on four plastic posts, with the tops melted to hold it in place.

The circuit (more or less)

The brains of the circuit is the BISS0001 IC chip[1], which seems to be common for PIR modules. In this video, Big Clive (dot Com) looks at a typical circuit and how to tweak it. Odds are, whichever unit you use, it will have that chip.
The #evp parser function was deprecated in EmbedVideo 2.0. Please convert your parser function tag to #ev.

Battery-powered devices have to be forgiving for power voltages, and according to the BISS0001 datasheet, the supply voltage can be 3~5V. In testing, it runs fine with both 5V and 3.3V from the Pi. At 3.3V the LEDs are dimmer, but that could be fixed by changing the current-limiting resistor. Running at 3.3V means that the detection output from the unit can go straight to a Pi input without a buffer or voltage divider. (With a long cable run dropping the voltage, 5V could be used, but don't forget and switch to a short cable later.)

With later testing from 3.3V, the module is locked into continuous detection. That seems new. I'll probably use 5V and check the output before connection to a Pi input. With the current jumper cables, Vdd on the board is 4.86V.

The detection output (BISS0001 pin 2) runs through a resistor to the transistor driving the LEDs. Pin 2 seems to be the point that I want to tap for a Pi input. I could also cut it there and run a Pi output to the LED driver to give the Pi control of the LED light. Connecting the two wires without the Pi would restore the original function.

With Vdd at 4.86V, there seems to be a fairly low voltage output from pin 2 in triggered state. Connecting the LED drive line drops it even further. It should be within RPi input range, but time to check the datasheet to see what pin 2 should providing.

Tx, the time on after motion is detected, is about 45 seconds.

Ti, the time after the detection switches off, and before it can be triggered again, is quite short.

You have to know your limitations

PIR detectors are subject to false triggers, especially outdoor or indoor daylight conditions. Wind moving plants, changing cloud shadows or sudden cats can set them off. Do everyone a favor and take that into account before setting off the sirens or releasing the laser shark-cat roombas.

Further

Detecting motion is fine, but how to tell good motion from bad motion (other than with safe words)?

  • Something you are
    • Eventually fingerprint readers will make it to the discount bin.
    • Are you a day person? Detection at 3pm is good. Detection at 3am is bad.
  • Something you know
    • Passwords and keyboards are so retro.
    • Use a mic and speech recognition, and actual safe words. "Pawn to Queen's level 3"
  • Something you have
    • Got smart phone? When my phone is in range of the house wifi, its MAC is assigned to a particular IP address. A simple ping on the LAN from the Pi will tell if I'm home. (The MAC can be spoofed, but without the WPA2 passphrase, no luck. Probably.)
    • Perhaps a re-purposed Bluetooth camera button?
    • A key and lock switch? Crude, but it just might work.

Notes