Hey guys,
Note: See pictures attached below.
I've come to the conclusion that I really, really want to have room based occupancy detection AND counting. Motion detectors are just not fast enough or accurate enough for me and my setup. I want to know when someone enters a room, leaves a room, and how many enter/leave. This way I can keep lights on and allow lights/music to "follow" someone around the house - instantly. No waving of hands in the air, no inaccurate counting. So over the past few weeks I have been experimenting with creating my own room counting interface based off a PIC16 micro controller. It works much like a retail store people counter by using infrared beams in the doorway. Total cost per doorway: around $10. Here is the setup:
Most of my doorways are exactly 3 foot wide.
At one side of the doorway I have placed an IR LED that is pulsing infrared light at 38kHz. On the other side there are two IR receivers that are calibrated to receive only a 38kHz frequency, side-by-side. When there is no presence in the doorway, the IR beam is detected by both of the sensors. When someone walks through the doorway, one of the IR receivers will be blocked before the other, thus, using some pretty simple logic, I can determine the direction of the person as they travel through the doorway by figuring out which of the two beams was 'broken' first. Then, once an entry or exit has been established by the counter, the 'node' would communicate back to my main controller and in return more complex logic would executed to determine what needs to happen based on other room counts, etc. For this I have a whole-house RS485 network that I already use for other nodes to communicate on anyway. (Bed occupancy sensor, temperature sensors, very small motion sensors, pipe temperature sensors, joist sensors, humidity sensors, rain gauge, etc.)
As I'm sure you are probably already thinking, there are plenty of things that can go wrong by me counting the breaks in the beams. I've been testing my code out over the past few weeks and here are the things that I have implemented to get pretty much 99% reliability.
- What about when someone swings their arms as they walk in? I have the sensors mounted about 44 inches above the floor. This eliminates most of the problems that would occur from this. Now, if you have something in your arms that sticks out, most likely it will block both beams the entire time that you and the thing you carry cross through the doorway. In order to prevent the counter from seeing some object that is ob-longed shaped and their torso as another, I made it so that the both beams have to be broken for a minimum amount of time (in milliseconds) or the count will be canceled. The thickness of the average torso from the side allows me to guarantee that both beams will be broken for this minimum amount of time given that they walk at a normal pace. Now, if someone were to sprint through the doorway, it won't count them. But walking at a fast pace all the way down to barely moving will be counted correctly.
- What about when someone enters the doorway and stands there? I built some more logic into the counter that would check which beam was returned to normal first so that I could detect, even after someone stood in the doorway for a long time, which direction they ultimately decided to go in. If someone walks in the doorway and stands there, then backs up, no update is ever transmitted. However, if the same thing happens and someone does decide to continue through the doorway, then the update is transmitted. Again, it's all based off of what beam is restored first.
- What if someone walks in right behind me? Unless you are literally holding on to each other with no space between your torsos, the beams will be restored as soon as the first person passes. I have a very small time threshold that must be met for both beams to be clear before the next person can walk in in order to prevent baggy clothing from setting off the sensor. I've tested this with 4 people virtually walking in a conga line and no problems whatsoever.
- What about walking side-by-side? I don't have this problem as my doors are only 3ft wide for the most part and I don't know of a time where I would walk side-by-side with someone through the doorway. The french doors are a different story. For these, it just won't be as accurate if you have multiple people who walk in and out side by side. For the times that I do have an inaccurate update, the logic in the main controller should be able to tell if there was a slip up based off of what rooms are connected and how many people walk into each of these rooms.
- What is someone waves their hand over the sensor to run up the count? This could happen, but they would have to do it slow enough for both beams to be broken for the minimum amount of time I specified. If someone waves their hand over it the counter just ignores it.
- What about TV remotes? TV remotes do operate on the same frequency of IR that I am using, however, because of the minimum time required for both beams to be broken, they don't cause a problem. They transmit way to quick (even holding down a button) for the signal to meet the time threshold.
- What about sunlight? This I'm not so sure about. I've been testing this on three of my inside doorways and I have not had a problem. I don't know what effect the sun will have on this if I use it on an external door or one right next to a bright window. My guess is it won't be much at all.
With all that out of the way, I have been testing 3 doorways for weeks using masking tape on the sensors to hold them up and it works great. But, here is where I run into my problem. How in the world do I make this aesthetically pleasing?
My plan is to have a small project box (3"x3"x3") below each doorway in the crawlspace where the RS485 network will hookup to it and the micro controller is housed. I distribute power over my network as well, so each control box will only need 1 cat5 cable going to it. That's no problem and easily done compared to my other projects. My problem lies with installing the sensors in the door frame. They are small - the IR LED is literally only the size of a small normal LED. The receivers are both square and 3/16th of an inch each, so two side by side are 3/8ths of an inch wide by 3/16th of an inch tall. They do have leads that come out the bottom and can be bent back. (see pictures) It will take a 22 or 24 awg 4-conductor wire for the receiver run and a 22 or 24 awg 2-conductor wire for the LED transmitter run. So the cables will be small, that's not an issue. The issue is how in the world do I mount these things to make them look good and run the wires behind the door frame to the crawlspace below where they will hookup to the control box. Here is what I have come up with so far:
- Pull the door frame off, drill holes in it and attach the receivers and transmitter in recessed holes and run the wire down through the floor in the wall to the crawl space. Very work intensive and honestly beyond my expertise ) If I went this route I would probably have to have a contractor help me. But it would probably look the best.
- Route or trench out a small channel all the way from the sensors to the floor on each side where I will then take it directly below to the crawl space. Then putty over, sand, and paint the channel so it can't be seen.
- Use super-thin, flat wire that you can find online and paint over it. This will be hard to attach the sensors on the end though and it's VERY expensive.
- Drill holes in the doorway and fish the wires down. This will work for some of them, but for the doorways that are right near an adjoining wall, this is nearly impossible for one of the two sides due to the 2x4s.
I know this is a long post, but I truly believe this is an awesome solution to my problem after trying it out the past few weeks. If I could have this implemented in all my doorways, it would make things so much more efficient and fast. Any advice anyone has or suggestions, good or bad, would be great.
Note: See pictures attached below.
I've come to the conclusion that I really, really want to have room based occupancy detection AND counting. Motion detectors are just not fast enough or accurate enough for me and my setup. I want to know when someone enters a room, leaves a room, and how many enter/leave. This way I can keep lights on and allow lights/music to "follow" someone around the house - instantly. No waving of hands in the air, no inaccurate counting. So over the past few weeks I have been experimenting with creating my own room counting interface based off a PIC16 micro controller. It works much like a retail store people counter by using infrared beams in the doorway. Total cost per doorway: around $10. Here is the setup:
Most of my doorways are exactly 3 foot wide.
At one side of the doorway I have placed an IR LED that is pulsing infrared light at 38kHz. On the other side there are two IR receivers that are calibrated to receive only a 38kHz frequency, side-by-side. When there is no presence in the doorway, the IR beam is detected by both of the sensors. When someone walks through the doorway, one of the IR receivers will be blocked before the other, thus, using some pretty simple logic, I can determine the direction of the person as they travel through the doorway by figuring out which of the two beams was 'broken' first. Then, once an entry or exit has been established by the counter, the 'node' would communicate back to my main controller and in return more complex logic would executed to determine what needs to happen based on other room counts, etc. For this I have a whole-house RS485 network that I already use for other nodes to communicate on anyway. (Bed occupancy sensor, temperature sensors, very small motion sensors, pipe temperature sensors, joist sensors, humidity sensors, rain gauge, etc.)
As I'm sure you are probably already thinking, there are plenty of things that can go wrong by me counting the breaks in the beams. I've been testing my code out over the past few weeks and here are the things that I have implemented to get pretty much 99% reliability.
- What about when someone swings their arms as they walk in? I have the sensors mounted about 44 inches above the floor. This eliminates most of the problems that would occur from this. Now, if you have something in your arms that sticks out, most likely it will block both beams the entire time that you and the thing you carry cross through the doorway. In order to prevent the counter from seeing some object that is ob-longed shaped and their torso as another, I made it so that the both beams have to be broken for a minimum amount of time (in milliseconds) or the count will be canceled. The thickness of the average torso from the side allows me to guarantee that both beams will be broken for this minimum amount of time given that they walk at a normal pace. Now, if someone were to sprint through the doorway, it won't count them. But walking at a fast pace all the way down to barely moving will be counted correctly.
- What about when someone enters the doorway and stands there? I built some more logic into the counter that would check which beam was returned to normal first so that I could detect, even after someone stood in the doorway for a long time, which direction they ultimately decided to go in. If someone walks in the doorway and stands there, then backs up, no update is ever transmitted. However, if the same thing happens and someone does decide to continue through the doorway, then the update is transmitted. Again, it's all based off of what beam is restored first.
- What if someone walks in right behind me? Unless you are literally holding on to each other with no space between your torsos, the beams will be restored as soon as the first person passes. I have a very small time threshold that must be met for both beams to be clear before the next person can walk in in order to prevent baggy clothing from setting off the sensor. I've tested this with 4 people virtually walking in a conga line and no problems whatsoever.
- What about walking side-by-side? I don't have this problem as my doors are only 3ft wide for the most part and I don't know of a time where I would walk side-by-side with someone through the doorway. The french doors are a different story. For these, it just won't be as accurate if you have multiple people who walk in and out side by side. For the times that I do have an inaccurate update, the logic in the main controller should be able to tell if there was a slip up based off of what rooms are connected and how many people walk into each of these rooms.
- What is someone waves their hand over the sensor to run up the count? This could happen, but they would have to do it slow enough for both beams to be broken for the minimum amount of time I specified. If someone waves their hand over it the counter just ignores it.
- What about TV remotes? TV remotes do operate on the same frequency of IR that I am using, however, because of the minimum time required for both beams to be broken, they don't cause a problem. They transmit way to quick (even holding down a button) for the signal to meet the time threshold.
- What about sunlight? This I'm not so sure about. I've been testing this on three of my inside doorways and I have not had a problem. I don't know what effect the sun will have on this if I use it on an external door or one right next to a bright window. My guess is it won't be much at all.
With all that out of the way, I have been testing 3 doorways for weeks using masking tape on the sensors to hold them up and it works great. But, here is where I run into my problem. How in the world do I make this aesthetically pleasing?
My plan is to have a small project box (3"x3"x3") below each doorway in the crawlspace where the RS485 network will hookup to it and the micro controller is housed. I distribute power over my network as well, so each control box will only need 1 cat5 cable going to it. That's no problem and easily done compared to my other projects. My problem lies with installing the sensors in the door frame. They are small - the IR LED is literally only the size of a small normal LED. The receivers are both square and 3/16th of an inch each, so two side by side are 3/8ths of an inch wide by 3/16th of an inch tall. They do have leads that come out the bottom and can be bent back. (see pictures) It will take a 22 or 24 awg 4-conductor wire for the receiver run and a 22 or 24 awg 2-conductor wire for the LED transmitter run. So the cables will be small, that's not an issue. The issue is how in the world do I mount these things to make them look good and run the wires behind the door frame to the crawlspace below where they will hookup to the control box. Here is what I have come up with so far:
- Pull the door frame off, drill holes in it and attach the receivers and transmitter in recessed holes and run the wire down through the floor in the wall to the crawl space. Very work intensive and honestly beyond my expertise ) If I went this route I would probably have to have a contractor help me. But it would probably look the best.
- Route or trench out a small channel all the way from the sensors to the floor on each side where I will then take it directly below to the crawl space. Then putty over, sand, and paint the channel so it can't be seen.
- Use super-thin, flat wire that you can find online and paint over it. This will be hard to attach the sensors on the end though and it's VERY expensive.
- Drill holes in the doorway and fish the wires down. This will work for some of them, but for the doorways that are right near an adjoining wall, this is nearly impossible for one of the two sides due to the 2x4s.
I know this is a long post, but I truly believe this is an awesome solution to my problem after trying it out the past few weeks. If I could have this implemented in all my doorways, it would make things so much more efficient and fast. Any advice anyone has or suggestions, good or bad, would be great.