So... I've been thinking about home automation and have run into a question/problem that it seems everyone strikes at some point - how to reliably detect the presence or absence of a person in a room.
The most commonly suggested answer seems to be to use a PIR to detect motion. The obvious caveat is that it detects motion rather than presence, and so you'll need to wave at the sensor periodically, in which case frankly I'd prefer to just flick the switch on the way into the room.
One solution is to use a webcam or similar, and do tracking that way (probably with the aid of a filter to look for infrared only). That's feasible, but it requires a heck of a lot more processing than the Arduino could handle, and as I see it, much more processing than should be necessary.
What I'm really after is a middle ground, a system with maybe 10 or 12 static infrared sensors, monitoring different areas of the room and assessing against expected background values. The software side of the equation doesn't bother me, if I can get sensor values accurate enough I'm confident I can work out the kinks of background thresholding.
In terms of hardware though, I'm really scratching to figure out whether such sensors are available/economical. I'm thinking you'd need a lens working similarly to those on PIR sensors, but isolating readings arriving from different angles, sending them to the different sensors. You'd also need sensors that are sensitive enough at room temperature to notice the difference made by a human presence.
So, I put it to you - is such a thing feasible? Any suggestions or comments are welcome. I don't mind being told I'm wrong, it'll likely save me time and effort finding out I'm wrong later.
RFID is an interesting suggestion, and has a lot of advantages, but I'm not sure it'd be practical in the home automation scenario. I'd rather not have to issue tags to all my visitors, or remember to pick up my tag on the way to the bathroom in the middle of the night...
Wow, I don't think I ever would have thought about resonant frequencies as an option. I've done a bit of Googling but still have no idea how you would measure that with something like the Arduino - care to elaborate a bit?
I think you need to step back, and ask yourself WHY you want to know. If you were designing a space station, and the system wasn't going to bother putting air in an "empty" room, you'd have to build a pretty reliable detector. If you just want to turn off lights when a room is empty, having to wave at the detector once in a while isn't such a terrible thing, is it?
The nature of the rooms is important too. If you always leave the door of the bathroom open when not in use, close it when it is in use, a simple reed switch and magnet are all you need.
Maybe I should flesh out the thinking here a little. First things first, I'm not designing a space station ;). 100% reliability is not what I'm after, though obviously if that is possible then it would be nice.
However, my feelings about home automation are that, ultimately, it should result in things being... automated. It's all very well for me to be able to turn on the lights from work, but that's still essentially a manual operation. And while it's not terrible to have to wave at a sensor periodically, it's not terrible to flick a switch on the way into a room either. It just seems unnecessary.
If I'm walking down the hallway of my house, it should be able to recognise that and turn on the lights for where I am going, and turn off the lights whereever noone remains. If I'm in a room in the evening and the light level drops, the room should notice, close the blinds and turn on the lights for me. I just don't want to have to *think* about it.
Obviously that over-simplifies the whole thing, but I really think if there's a cheap effective way to detect whether people are in a room, it would go a long way towards getting all that happening.
Let me ask a more specific question (though feel free to expand on the broader issues):
Would something like an IR phototransistor be likely to give me enough sensitivity to detect a difference when a person is/isn't present in an area of the room (assuming I could direct the incoming IR towards it using a simple lens)?
Also, you're confusing short wavelength IR (phototransistor territory) with long wavelength IR (body heat, PIR/bolometer territory).
And everything else that Richard Crowley said.
I would probably use reed sensors at the doors to each room, because that would be the easiest way for me to implement it.
Depending on where the arduino is located versus the sensors, you could just code it so that using a PIR would trigger whatever ON but would never shut it off until you hit the reset button the arduino. Basically it would only have 2 states, OFF and ON, and OFF would be its default on start up.
I still think PIRs are the way to go... as long as having to wave ONCE IN A WHILE isn't a deal breaker. I suspect that a little care over the siting of the PIR, and maybe more than one, and maybe a system that isn't too quick to turn off the lights, could be put together which would give generally satisfactory results.
(I hope you didn't infer that I saw waving at the sensor as being needed as a "routine" measure.)
But none of the above stops me from enjoying all the OTHER ideas floating about.
Ultrasonic devices on the ceiling, pointing downwards, in doorways, "seeing" people come and go might well be part of the answer? You light want one each side of each doorway, so you would know if the passing person was entering or leaving. Of course if you have teenagers with boy/girl friends in the house who go around, sometimes entwined, sometimes(?) as separate units, it is going to mess up the "objects passing through doorway" counts....
... people with budgets 1000000x bigger than yours, and laboratories full of PhDs have not come up with a solution for this.
I thought that may well be the case. Still, no harm in bouncing a few ideas around.
Also, you're confusing short wavelength IR (phototransistor territory) with long wavelength IR (body heat, PIR/bolometer territory).
Ahh ok, thanks for clarifying this one. They all just say 'IR' so I assumed they were measuring much the same thing. Now that I think about it, that wouldn't really make sense at all for a lot of IR applications.
It does sound like a PIR system may still be the way to go, it's just a matter of making the system work for you. I guess one of the things that turned me off that style of thing is that at my university they had a PIR system that could turn lights off but not on. This meant that you'd be sitting quietly in a room and all of a sudden it would be pitch black, resulting in 30 seconds of stumbling around stubbing your toes on things to find the light switch. ;D
Clearly there are better compromises to be made...
Some form of door monitoring (reed sensors, ultrasonic) seems to be a popular suggestion, and it makes sense for a lot of scenarios. I need to think on all this a bit more. I'm enjoying the discussions though, the more ideas into the mix the better as far as I'm concerned.
Not sure if this is practical for your situation, but I've enjoyed the way my laser tripwire has worked for me. I've only got one door into my room and have got it keeping the state of how many persons are in the room by a double laser setup that can read in which order they're tripped to determine whether they're coming or going. Right now I've got it hooked to play/pause music, but I may make it work lights eventually. Home automation has always been a neat idea for me, so I'm also working on figuring out about the same problems. :
Are those Wiimote "camera" sensors any good at detecting people?
No they are not sensitive enough and the wavelength they work at is too small. Silicon based sensors don't have the right characteristics for pyro type sensors.
They are only good for seeing LEDs. (too limited a resolution to do anything useful with shape)
What a wonderful coincidence, I'm working on exactly the same project at the moment I've thought about face/human detection via IR-Webcam but let drop this idea due to too high costs and poor results if the person is far away from the camera. RFID is also not my choice since the system should work even if there are many people at my house without giving them an rfid chip at entry So i decided to do the old fashioned way: IR light barrier. i will install 2 light barriers in every door and hook them up to an arduino (in my case an arduino uno), so i can monitor 18 light barriers which is 9 doors. with multiplexing there is room for more, but its sufficient for me since i've have exactly 9 doors at my home and with that, cables from the doors to the arduino aren't too long.
Back to the light barrier: First i ordered some photodiodes specially for IR-Detection. Turned out that they are absolutely rubbish (way too sensitive for daylight), now i'm using the same IR-LEDs that i use as an emitter as a detector. they respond just a little to daylight or light from the lamps and 3 of them combined as detector wired up in series and 2 of them as emitter work just perfectly fine on the digitalPorts for distances in the range of 1m between detector and emitter.
Before i forget to write it down: i use vishay IR-LED TSHF5471 which i got from ebay for 0,07? a piece.
So my idea is to have 2 arduino boards. one just looking on the light barriers and sending the data to the other board via serial com.
the other board receives the time point of each light barrier if the status changed and recalculates the number of persons in a room if a pair of light barriers is interrupted and released in a certain pattern.
Then this board will switch the light on using the circuit from mitchsoft.de (german) using an optocoupler, a capacitor and some resistors. There is also the possibility to build a dimmer (easy with optocoupler).
What i have to do now is wire it up, buy a second arduino and integrate some light detectors so that the arduino doesn't turn the light on if not necessary. i think i'll use again LEDs and hook them up to the analogIn.
I have calculated the costs for this project to be around 72? for my flat (9 rooms, approx. 80m²) and roughly 200? for my parents having 3 floors with 20 rooms. price can be lower with a cheaper arduino (in germany they are available for around 26?) if i assemble them myself for example. seems good for me for my first project with the arduino
When my project is completed i will publish the result and code somehow (blog / youtube /...) If you are interested you can write me an email.
Sorry for my spelling/grammar mistakes by the way, i'm from germany and in a hurry
Log the data. And then produce animations of "body flow" around the rooms over time? Bit of fun?
The logging is not just for the fun of the animation, but will also be useful in working on de-bugging the code. A way to do "a stock check" from time to time might be worth building in, too... i.e. a way to say "Computer: How many people in Room A", and to correct its idea, "by hand" when necessary.
===
Further idea...
If the simple IR beams prove too unreliable, you can adopt the "answer" used by IR remote controls. The sensors will be quite a bit more expensive, and the IR beam sources a little more expensive... although one source could probably illuminate two sensors.
(About $3, made up with a nice little pdb. Should be possible to buy just the sensor more cheaply.)
The "trick" they use? The source sends out a "flickering" (high frequency) beam, and the detector ignores all IR except IR "flickering" at the right frequency.
(Richard was writing what appears below at the same time as I was writing the above! (We were both saying the same thing, in case that isn't clear!!))
@tkbyd: well i had the moving profiles idea too, but my girlfriend doesn't like it. manual correction of the number of persons in a room is not yet implemented properly and i still need the hardware to do so. but it's defenitively planned.
@Richard Crowley: well thats unfortunately not a simple way since i want to hook the IR-detectors up to the digitalPorts. then just 1 for "detected" and 0 for "not detected" is perfect and it's fast (absolutely necessary for multiple light barriers). my solution now cost ca 0,38? per light barrier instead of 0,75? with a "real photosensor" for which i would have needed additional components. so i'm happy with "cheap & easy"
additional information: the voltage i measure with my 3 IR-LEDs without pointing an emitter on it lies around 1,9V and with light from a 1m distance its approximately 2,8V. This could be better but is sufficient for digitalRead
[1st edit] and @Richard again: wow, i didn't know that, thanks for the info!
[2nd edit] @ Richard: the problem of "fast or not" isn't the response time of one light barrier. It is that you have to be very careful to detect each and every time a person crosses a barrier. Thats perfectly easy with interrupts, unfortunately there are only 2 pins which support it, so one have to "scan" the status of each light barrier one after another very fast to not miss one beeing interrupted with a for-loop. Therefore not only the actions done by the microprocessor if anything important is detected has to be as quick as possible, also the detection itself has to be nearly instantly. Every time a light barrier changes it state has to be detected and this information will then be send to another arduino. that second arduino ist primarily not needed if you have only a few rooms because there are enough pins. but if the microprocessor is then busy calculating other stuff as dimming the light in a room, it may miss a person crossing a light barrier. with two arduinos that information just lands in the Serial buffer (each information has length 5 byte, even could be reduced to 3 byte, so a total of 20(33) pieces of information can be buffered)
the information is always in the form x00ux with x as start and stop signal and 00 as the number of light barrier u for the state of the light barrier. the x's actually can be dropped. these are remainders of another code in which i had the option for many controllers sending to the main arduino. then (without further control mechanisms) 2 signals could mix together and end up messy.