Washington, NC Real Estate - A cool site with real estate information in Washington, Bath, and Belhaven, North Carolina. Greenville, NC Real Estate - Another real estate site with information for Greenville and Winterville, NC. Morehead City, NC Real Estate - Another real estate site with information for Atlantic Beach and Emerald Isle, NC. Jacksonville, NC Real Estate - A real estate site with information for Jacksonville, NC and Richlands, NC and homes for sale. |
Occupancy Detection & People CountingOne of the key elements of every home automation system is occupancy detection. Knowing whether or not someone is in a room, or even in the house at all is vital. For years I, like everyone else, used motion detectors around the house to identify when someone enters a room. Then every time it senses motion in the room it would reset a timer. When the timer expires due to no motion in the room for X number of minutes the system would assume the room is unoccupied. Motion detectors for occupancy detection have many disadvantages. For starters, when someone is sitting still for a while no motion is ever reported and you end up with the lights turning off on you in the room. This resulted in having to wave your arms in the air to make the motion detector “see you” again. The next big problem is the delay. My motion detectors take about 2 to 3 seconds to recognize motion in the room. This means that I would end up walking several feet into a dark room before the lights turn on. Using a true “Occupancy Detector” instead of a motion detector cures this problem, but they are so sensitive that they often detect my cat walking on the floor. Because of these drawbacks I began to look for a different method to detect occupancy. I considered several options including facial recognition (way too costly and bulky), sonar (not accurate enough), and floor sensors (not accurate enough either). I eventually came up with a concept idea. What if I could place two infrared beams across each of the door frames in my house so that I could count the number of people that enter and exit each room? The idea sounded crazy, but the more I got to thinking about it the more it made sense. I began to look around on the internet for a pre-made solution and the only thing I could come up with that was even close was a device that is used to count the number of customers that enter and exit a retail store. This thing was not only expensive, but very bulky. Not to mention I have no idea how to get the output to my main controller for counting. Several weeks went by looking for other solutions and I finally decided I was going to have to make the device myself. Now, I am not an electrical engineer. Or a programmer by trade. Everything I know about electronics, home automation, circuits, design, and programming all come from me searching the internet and learning about it myself. You have been warned.
The Idea – the 'Door Node'My idea involves two infrared LEDs on one side of the door frame that shoot two invisible beams of light across the doorway to the other side at 38kHz. On the side opposite of the infrared LEDs there are two infrared receivers that detect when the light is present or not. The wires from both sides of the door frame will connect to the door node that houses the bulk of the electrical components. I want this setup to be as aesthetically pleasing as possible, so since my house has a crawlspace I planned to take the wires on both sides of the door frame straight down through the floor where they will connect to the main device completely hidden out of sight. With the main device mounted in the crawlspace beneath the floor, I will connect it to my RS485 network so that it can communicate back to my main controller. Running power to each of the door nodes would be a tedious task, so I opted to use the power from my RS485 network that I already distribute to other nodes. In the case that I have so many of the door nodes that they draw too much power, I dedicate a new power adapter for every 4 or so door nodes – all running from my wiring closet. The logic for determining when someone crosses a door frame, and what direction they went will be handled by a PIC16 series micro controller. By sensing which of the two beams “breaks” first as someone crosses the door frame, I can detect the direction they travel in. This sounds simple, but in reality a bunch of error checking and problem scenarios have to be implemented. Once a successful pass is determined by the door node, it will communicate back to the main controller the direction that the person traveled in. The main controller then uses logic to keep track of the number of people in each room based on how many enter the house and from what rooms they travel to from there.
Installing the LEDs and SensorsThis was a bit of trial and error at first, but I eventually got the hang of it. I don't have any experience when it comes to construction or wood work, so I was a bit hesitant to attempt this at first. Eventually I gathered up enough courage to wake up one morning and (very carefully) remove the molding from around my office door frame. Most of the doors in my house are three foot wide. I do have some french doors that are considerably wider as well.
As you can see from the picture there is a gap between the actual door frame and the studs holding up the wall. Shims are used between this gap to nail the door frame to the stud so that it can be perfectly leveled and squared. This gap is what allows me to run my wire for the sensors without being seen. My door frames in my house are tapered (not sure if this is a standard) so that the part closest to the molding is thicker and gradually gets thinner as it goes in. This means that the thickness was not the same, and thus my two IR LEDs or the two IR sensors on the other side would not be even. So I took out my handy dremel tool and routed out the extra thickness so that the LEDs or sensors would have an even surface to attach to. Then, using a template I made with Google SketchUp, I drilled two small holes on each side of the door frame exactly 43.5” from the floor so that I had four total holes, two for the IR LEDs on one side, and two for the IR sensors on the other. The drill bit I used for the IR LEDs was 13/64”, and 11/64” for the receivers.
I used my molding trim color paint (white) to paint the inside of the holes I drilled so that they would not be wood-colored and thus less noticeable. While the paint in the holes dried, I drilled a small hole in the floor in the gap between the door frame and the wall stud that the wire for the IR LEDs could run through. I did the same on the other side for the receivers as well.
I used a mixture of hot glue and super glue to mount the sensors inside the door frame. I probably went overboard with the hot glue, but I wanted to make sure those things were not going anywhere once I put the molding back on.
I tested the sensors thoroughly using a breadboard prototype I had created before I put the molding back. My main concern was making sure they all aligned perfectly. After that was confirmed, I pushed the wires in the gap and nailed the molding back on. After some painters caulk to hide the seams and a fresh coat of paint, you can't even tell the molding was ever removed. All that is visible are two small holes on each side of the door frame.
Building the First 'Door Node'I had already been playing with a prototype I made on a breadboard, but I had not gone any further to make it a usable device. I decided on the following physical features for each of the door nodes I wanted to build:
I created my first prototype on perf board and it took me quite a few hours. Needless to say I was pretty happy when I finally got the chance to plug it in and it worked. I don't mind perf boarding when I need to make just one of an item, but when it comes to needing more than that I would rather design a printed circuit board and pay to have them printed. Soldering the components to the PCB board only took me about 20 minutes for each one. You can see the picture below of a completed door node on the new PCB board.
Logic Behind the 'Door Node' – Programming the Micro ControllerAt first the concept of detecting when someone passes through through the door frame and determining which direction they went in based on which of the two infrared beams was “broken” first sounded pretty simple. I found out fast that it was much more complicated than that. Nonetheless I figured it out and ended up with the following features:
Main Controller LogicThis is the exciting part. Now that all of my door frames have door nodes installed on them, I can not only tell when someone enters a room, but I can count how many enter as well. Using this information you can do some pretty amazing things. For example:
Reliability and Error DetectionHonestly, the sensors are more reliable than I thought they would be when I first started this project. I have sensors on all my interior and exterior doors at the moment. The only problem I ever encounter tends to occur when you are holding a strange shaped or translucent object in your hand as you walk through the beams. Occasionally the door node can end up not reporting the pass because ultimately the way the light is reflected back at the sensor made it believe that you went backward at the very end of your journey through the door. It took me a while to figure out how to prevent this, but using some logic I can report back to the main controller when this happens. To prevent me going on about a very complicated answer to this problem, it simply came down to applying some timers and a few flags to detect when this happens. The main controller is responsible for making sure that the rooms never generate new people. I would say right now I am at upwards of 95% reliability, possibly more than that.
Lifetime of the Infrared LEDsI'm not so sure about the lifetime of the IR LEDs I'm using, but to be on the safe side I implemented a few features that allow me to turn the IR LEDs off when they are not in use, and back on again when they are. When I'm not home or if everyone is on a bed/beds, all interior IR LEDs are switched off using a global command from my network. Exterior doors are switched off only when the door they are connected to is shut. As soon as it opens it immediately powers back on (about 10 milliseconds to do this) This also prevents someone from playing with it when I'm not home in an effort to run up the occupancy counts.
|