The kid is 4 years old. He’s certain there are monsters under the bed. What do you do?
You grab a two peanut cans, some bulk USB cable, a PIR motion sensor, 5 green LEDs, one red LED, an Arduino Mini Pro, and an old 5V phone charger.
The plan is simple. When the motion sensor is scanning, the green lights go into “chase” mode. When motion is detected, the red led is engaged. Green means there is nothing moving under the bed and we are safe. Red means we either have a monster down there or a person set it off.
The Tricky Part
Under absolutely ZERO circumstances can the red LED light up at 4am when no person could have possibly set it off. A confirmed monster will result in the kid needing therapy. These types of engineering constraints are good for us. Tesla Motors has some silly rule that says that under no circumstances should the car jump into oncoming traffic. Constraints like this make us try a little harder. We all need that from time to time. So how do we keep the PIR sensor from going off? The temptation is to cheat. I’d rather just learn to use the tools and components correctly.
1) The sensitivity of the PIR module thing can be adjusted using the potentiometers on the little board. It’s not always hyper-obvious what these things do. I tossed them on a scope. One sets the amount of motion required to trigger a HIGH signal. The other determines how long it will hold that signal HIGH.
2) We need to use capacitors to knock some of the noise out of the signal. This is already done on the modules. It’s not done where the PIR module connects to the Arduino MINI. Noise can and will be picked up along the cable. Shielded cable – a grounded blanket surrounding our signal – will help tremendously. A simple ceramic capacitor in the 100nF ballpark will do, too.
3) Using standard debounce techniques are helpful, too. We can go the hardware route and solve the problem with a capacitor and a resistor and essentially force the incoming HIGH signal from the PIR to charge a capacitor before it gives the Arduino the 5V or we can program the Arduino to require quite a few consecutive HIGH settings before the acknowledgment. The idea is the same. If the signal from the PIR is HIGH for a nanosecond, it was probably noise so we’ll just ask the signal if it’s sure a few times. This is similar to the way doors work. If a person knocks on the door, they don’t strike the door with their knuckles once. They go “Knock Knock Knock”. That probably isn’t the fridge or a raccoon. That’s a human. Same thing here. We are using time to make sure the signal is persistent.