Detecting motion is a basic function for an environmental monitoring system. There are multiple ways to detect motion, each with advantages and disadvantages.
Nov 18, 2016 UPDATE: I've found some new software using a Pi Camera that includes motion detection. It seems to work quite well. More about that in this post.
Option 1: Passive IR
The first option is to use passive IR sensors. These sensors work by detecting heat emitted in the form of infrared energy from objects as they pass in front of the sensors. A passive IR sensor has two small internal sensors next to each other. They detect the difference in infrared energy detected between the two, interpreting it as motion. A threshold is set on the sensor so that a pin goes high when it detects motion.
There are some strong advantages to these sensors and they should be a staple in your environmental monitoring projects. These sensors can be dirt cheap and can be quite reliable. They can detect motion from across a moderate sized room. The lens over the sensor refracts light in such a way that the sensor's field of vision is broad, allowing it to detect motion not only when the motion is happening directly in front of the sensor, but also when the motion is happening from the side. Especially notable is that this kind of sensor can "see in the dark" because it don't depend on visible light. Finally, they are less creepy than cameras. Having cameras set up around the entire house might be awkward and constitute a security risk themselves. Having an array of sensors that just detect movement of objects that generate infrared energy is less so.
Passive IR sensors do have disadvantages. Their key weakness is that they can't "see" though windows. So if you have an infrared sensor pointed at a glass door, for instance, it will detect people and animals moving between the sensor and the door, but not things on the other side of the door. Also, the sensors I use require a full five volts to work properly. They don't work with three volts. When using these with a 3V microcontroller, you have to find a way to provide the senor a full 5V on the one hand, but still have the signal available to the 3V microcontroller pin on the other. I've accomplished this by tying the sensor's ground to the microcontroller's ground, but tying the positive to the 5V USB power before the power is converted to 3V for the microcontroller. Last, I've noticed that the motion sensors I've used need a period of time to self-calibrate when they first power up. If they "see" a lot of motion when they first powered up, they can miscalibrate and start randomly reporting motion when there is none. This caused considerable frustration when I first started using these sensors because I thought I had wired things up wrong when really I just had to wait a minute for the sensor to self-calibrate. I have also (rarely) had sensors randomly start detecting continuous motion for no reason. Resetting the power followed by a short period of time with no motion addresses both of these issues.
Option 2: Pixel Differences in subsequent images
A second option is to have a camera take two pictures in rapid succession and compare them. If there's enough of a difference, then there must be motion.
This overcomes the key disadvantage of passive IR sensors in that it can see through windows. It works with visible light and doesn't rely on heat. The code in the pi-timolo project uses this method. The core motion detecting code is pretty short and fairly easy to understand. Another advantage of this method is that when you detect motion, a natural next thing to do is to take a picture of that motion. So you are likely to have a camera. If you are going to have a camera sitting there anyway, why not use it?
But this method comes with its disadvantages as well. First, it requires continuous image processing. This means you need a machine that's powerful enough to drive a camera, take pictures continuously, and compare the images. I've found that this works fine on a RaspberryPi, although I need to use multiprocessing to launch the "motion watcher" in another process so that the core script can do other things. On my Pi 2 B, it takes about 40% CPU continuously. That leaves plenty for other work, but it does eat up a lot of CPU time. This also means it eats up a lot of energy. I haven't tested it for battery use yet, but I'm sure it will greatly decrease the battery life of a device that uses it.
Option 3: Infrared Beams
Another option is to use infrared beams and detect when they break. This option requires a transmitter and receiver. The transmitter sends an infrared bean that is seen by the receiver. When someone or something moves between the transmitter and the receiver, the beam is broken and the receiver can report that it no longer sees the beam. When I described this to a friend, she said "isn't that like in action movies when the bank or secret bunker is full of beams that the hero has to defeat." It is. It's also like the safety sensor on most garage doors that detects when someone is walking into the garage so it stops the door from closing. But I like the comparison to action movie secret bunkers better.
An advantage to these is that they can be directed in very specific areas. Passive IR sensors have a broad field of view. An infrared beam can be focused in very specific areas.
But there are disadvantages. First, they require fairly precise calibration. You have to have your beam pointing at the sensors. Second, I haven't really found good ones to cover a long distance, even as long as a typical garage door. These sensors claim to work across about 20". That's far enough to cover a doorway, but not a large room or secret bunker.
Option 4: Ultrasonic Rangefinder
Ultrasonic rangefinders can be used to detect the distance between the sensor and some object in front of it. A typical use for such a sensor might be in a robot with a program directing the robot to "move forward until you are within N inches" of a wall. This is a static measure, but like the camera option above, one could take repeated measures. If the distance between the sensor and the thing in front of it changes significantly, that most like due to motion.
Unlike the infrared beam option, this doesn't require a transmitter and receiver. Also, it works in the dark. But like the camera based motion option above, it is essentially a form of busy waiting - continuously taking and comparing individual measurements. This is much more easily done in a microcontroller than the camera option, because the comparison is easier, but it's likely to require more battery power.
Option 5: Camera with on-bard motion detection
Some cameras have on board motion detection hardware. This is like option 2 except the camera itself is comparing subsequent images rather than passing off the work to a CPU. This is still a form of "busy waiting," but it's not as bad because you don't have the overhead of transmitting the images back to the CPU and the image comparisons are more specialized. This camera has built-in motion detection. I haven't tried it yet, but this is probably worth a look.
Like the other camera option, it can see through glass. It probably uses less power because it can do all it's work on board and does not rely on a separate CPU. Also, because the work is being accomplished on board, your core CPU is available fully for other purposes.
Conclusion
So these are your options. What I've found is that a combination of options 1 and 2 work best. Passive infrared sensors are cheap, effective, and low power so they are a no-brainer for monitoring interior spaces. But especially for those areas where one might need to watch through windows, the camera option where one looks for changes in subsequent images is fairly easy to implement
Nov 18, 2016 UPDATE: I've found some new software using a Pi Camera that includes motion detection. It seems to work quite well. More about that in this post.
Option 1: Passive IR
The first option is to use passive IR sensors. These sensors work by detecting heat emitted in the form of infrared energy from objects as they pass in front of the sensors. A passive IR sensor has two small internal sensors next to each other. They detect the difference in infrared energy detected between the two, interpreting it as motion. A threshold is set on the sensor so that a pin goes high when it detects motion.
There are some strong advantages to these sensors and they should be a staple in your environmental monitoring projects. These sensors can be dirt cheap and can be quite reliable. They can detect motion from across a moderate sized room. The lens over the sensor refracts light in such a way that the sensor's field of vision is broad, allowing it to detect motion not only when the motion is happening directly in front of the sensor, but also when the motion is happening from the side. Especially notable is that this kind of sensor can "see in the dark" because it don't depend on visible light. Finally, they are less creepy than cameras. Having cameras set up around the entire house might be awkward and constitute a security risk themselves. Having an array of sensors that just detect movement of objects that generate infrared energy is less so.
Passive IR sensors do have disadvantages. Their key weakness is that they can't "see" though windows. So if you have an infrared sensor pointed at a glass door, for instance, it will detect people and animals moving between the sensor and the door, but not things on the other side of the door. Also, the sensors I use require a full five volts to work properly. They don't work with three volts. When using these with a 3V microcontroller, you have to find a way to provide the senor a full 5V on the one hand, but still have the signal available to the 3V microcontroller pin on the other. I've accomplished this by tying the sensor's ground to the microcontroller's ground, but tying the positive to the 5V USB power before the power is converted to 3V for the microcontroller. Last, I've noticed that the motion sensors I've used need a period of time to self-calibrate when they first power up. If they "see" a lot of motion when they first powered up, they can miscalibrate and start randomly reporting motion when there is none. This caused considerable frustration when I first started using these sensors because I thought I had wired things up wrong when really I just had to wait a minute for the sensor to self-calibrate. I have also (rarely) had sensors randomly start detecting continuous motion for no reason. Resetting the power followed by a short period of time with no motion addresses both of these issues.
Option 2: Pixel Differences in subsequent images
A second option is to have a camera take two pictures in rapid succession and compare them. If there's enough of a difference, then there must be motion.
This overcomes the key disadvantage of passive IR sensors in that it can see through windows. It works with visible light and doesn't rely on heat. The code in the pi-timolo project uses this method. The core motion detecting code is pretty short and fairly easy to understand. Another advantage of this method is that when you detect motion, a natural next thing to do is to take a picture of that motion. So you are likely to have a camera. If you are going to have a camera sitting there anyway, why not use it?
But this method comes with its disadvantages as well. First, it requires continuous image processing. This means you need a machine that's powerful enough to drive a camera, take pictures continuously, and compare the images. I've found that this works fine on a RaspberryPi, although I need to use multiprocessing to launch the "motion watcher" in another process so that the core script can do other things. On my Pi 2 B, it takes about 40% CPU continuously. That leaves plenty for other work, but it does eat up a lot of CPU time. This also means it eats up a lot of energy. I haven't tested it for battery use yet, but I'm sure it will greatly decrease the battery life of a device that uses it.
Option 3: Infrared Beams
Another option is to use infrared beams and detect when they break. This option requires a transmitter and receiver. The transmitter sends an infrared bean that is seen by the receiver. When someone or something moves between the transmitter and the receiver, the beam is broken and the receiver can report that it no longer sees the beam. When I described this to a friend, she said "isn't that like in action movies when the bank or secret bunker is full of beams that the hero has to defeat." It is. It's also like the safety sensor on most garage doors that detects when someone is walking into the garage so it stops the door from closing. But I like the comparison to action movie secret bunkers better.
An advantage to these is that they can be directed in very specific areas. Passive IR sensors have a broad field of view. An infrared beam can be focused in very specific areas.
But there are disadvantages. First, they require fairly precise calibration. You have to have your beam pointing at the sensors. Second, I haven't really found good ones to cover a long distance, even as long as a typical garage door. These sensors claim to work across about 20". That's far enough to cover a doorway, but not a large room or secret bunker.
Option 4: Ultrasonic Rangefinder
Ultrasonic rangefinders can be used to detect the distance between the sensor and some object in front of it. A typical use for such a sensor might be in a robot with a program directing the robot to "move forward until you are within N inches" of a wall. This is a static measure, but like the camera option above, one could take repeated measures. If the distance between the sensor and the thing in front of it changes significantly, that most like due to motion.
Unlike the infrared beam option, this doesn't require a transmitter and receiver. Also, it works in the dark. But like the camera based motion option above, it is essentially a form of busy waiting - continuously taking and comparing individual measurements. This is much more easily done in a microcontroller than the camera option, because the comparison is easier, but it's likely to require more battery power.
Option 5: Camera with on-bard motion detection
Some cameras have on board motion detection hardware. This is like option 2 except the camera itself is comparing subsequent images rather than passing off the work to a CPU. This is still a form of "busy waiting," but it's not as bad because you don't have the overhead of transmitting the images back to the CPU and the image comparisons are more specialized. This camera has built-in motion detection. I haven't tried it yet, but this is probably worth a look.
Like the other camera option, it can see through glass. It probably uses less power because it can do all it's work on board and does not rely on a separate CPU. Also, because the work is being accomplished on board, your core CPU is available fully for other purposes.
Conclusion
So these are your options. What I've found is that a combination of options 1 and 2 work best. Passive infrared sensors are cheap, effective, and low power so they are a no-brainer for monitoring interior spaces. But especially for those areas where one might need to watch through windows, the camera option where one looks for changes in subsequent images is fairly easy to implement
Comments
Post a Comment