Wednesday, November 06, 2013

Tinkering

When we bought our house, the first run of stairs to get up to our front door had a motion sensor light at the top of the stairs. It was pretty much impossible to get this light to turn on until you were a fair way up the stairs. And because the sensitivity of a standard motion sensor drops when it is cold out, during the winter the light didn't turn on until you were nearly at the top of the stairs.

About three years ago, we had a second motion sensor light installed at the midway point on the stairs when we were having some other work done on the stairs. This improved things greatly, but the sensor sensitivity still varied with the seasons. And it was easily confused into turning on repeatedly if the plants on the other side of the stairs were swaying in the wind. (And then, after a couple of years, the sensor failed altogether, so we just kept the mid-stairs light off.)

Really, the problem is that with your typical security light, the sensor is right next to the light, but we wanted the light to be triggered by motion at the bottom of the stairs—several feet away. What we needed was to move the sensor away from the light. But I didn't think that simply moving the sensor, by splicing in a cable, was a good idea, because the wire would carry line-level current, and having a jury-rigged 120 volt power cable running down the wall next to the stairs didn't seem terribly safe.

So I instead decided to build a circuit with an Arduino microcontroller, a motion sensor, and a light sensor (so that I could program the light to go on only at night). If the circuit detected motion (at night), it could trigger a relay that would turn on the light. This would allow the cable between the circuit and the light to be limited to low voltage.

Originally, I assumed the circuit would use the same sort of motion sensor as the original one—one that detected infrared energy (heat). This would still have tuning issues, but I figured that if the sensor was close to the point at which I was trying to detect motion, I could adjust things so that there wouldn't be too many false-positives, and so that seasonal changes weren't a big problem either.

But then I found a cool sensor that detects whether something is close by, and if so how close. It does this by sending out very short bursts of ultrasonic (40 kHz) sound and then waiting to see if any of it is reflected back, and if so how long it took for the reflected sound to come back. This was perfect, because I could program things so that the light would only turn on if an object came within, say, 30 inches of the sensor, thus avoiding the wind problem (because the plants are around 50 inches away). And although the speed of sound varies with temperature, the variation is pretty minor. Given the outdoor temperature range in San Francisco, the maximum distance that the circuit would check might vary by an inch or two—no big deal.

After a bunch of fiddling, here is the circuit I built (it's about 2 inches by 3 inches):

It looks much more complicated than it is—most of the traces you see on the circuit board are unused (I built the circuit on a generic prototyping board). Those two speaker-like things are the ultrasonic transceiver and receiver. The light sensor and the power relay aren't on the board.

Because this circuit was going to be outdoors, I needed to fashion a weatherproof enclosure. This is an "old work" electrical box. I drilled some holes into it to accommodate the ultrasonic sensor, to mount the circuit board, and to mount affix the photocell (the light sensor). The cable (on the upper-left) brings power (about 9 volts) to the circuit, and also has a signal line (5 volts) that goes to the power relay (which is in a crawl space in the house).


The enclosure wasn't weatherproof on its own, so I epoxied the holes, painted the whole thing, and for good measure added some silicone sealant. The ultrasonic transceiver and receiver can't be sealed (that would block the ultrasonic bursts), so I'm hoping they are weatherproof enough to survive some rain. I'll grant that, even painted, this is not the most beautiful of things, but this is going under a mailbox.


I removed the old motion sensor from the light, and used the whole to thread the cable with the low-voltage power and the signal line through to the crawl space. I then sealed the hole with silicone sealant. (Word to the wise: See how the light is tilted a bit? Bad idea. The T3 halogen bulb inside is intended to be horizontal. If it's at a tilt, the higher end gets stressed by heat, and the bulb fails. The light, with a new bulb, is now turned so that the bulb is horizontal.)

Inside the crawl space, I have a power supply for the low-voltage line, and an enclosed relay that is triggered by the signal line.

The finished sensor is mounted under the mailbox, for a bit of protection from the rain. (It's actually a bit lower than in this picture, which I took before I finalized everything.) It's mounted with galvanized wood screws, and there is a silicone mat between the enclosure and the wood.


End result? The light reliably turns on when you get to the second step. Because of its height, it won't be triggered by small animals climbing up the stairs. Because of the type of sensor used, there shouldn't be any noticeable seasonal changes. Now we just have to see whether it survives the rainy season.

No comments:

Post a Comment