Languages

Low-cost photo motion detector

We were shopping the other day at St-Ouen's flea market and we bought two very effective motion detectors for 12 euros (yes, 12 euros for both of 'em!!!).

We opened them and found out they are actually pretty simple circuits. The plastic semi-transparent window in front is actually a decoy, which makes them look like infrared-based professional motion detectors. The truth is, the only active component seems to be nothing more than a photoresistor (!), most of the circuit being for playing different tones when a presence is detected.

We found them pretty effective, they have a range of about 3-4 meters and pretty much never miss detecting a movement. They are also robust, so mere variations in the light environment does not affect them.

So we tried to reproduce the behavior using a 50kOhm photoresistor, a 50kOhm resistor (to bring the resistor's output between 0 and 5V) and an ATTiny. The program consists of detecting strong variations between two readings of the photoresistor:

int value;
int last_value;

unsigned int motion() {
  int motion;
  value = analogRead(); // reads the value of photoresistor [0-1023]
  motion = value - last_value;
  if (motion < 0)
    motion = -motion;
  last_value = value;
  return (unsigned int) motion;
}

A full code sample is available in attachment to this post.

It is basically working, however for now it doesn't work very well when the day gets darker, nor when we move too slowly. It is also hard to find the right threshold we need (to avoid detecting because of mere variations in the environment).

We still need to do some research in order to reach the efficiency of the detectors that we bought.

AttachmentSize
simple_photomotion.c2.19 KB