Guest post #2: Peeping Tom in the toilet with Raspberry Pi
When Jeroen Danckers sent us a blog post with that title he was on to a winner. And let’s face it, who hasn’t dreamed of putting a computer in the toilet connected to a camera that reports back to a web page whether the toilet is occupied or not. I have.
There’s all kind of people running around at our digital agency (Intracto, Belgium). Not only in numbers, but also in all weird forms and shapes. A simple discussion during lunch break about busy toilet usage quickly ends up in high-tech cut ‘n’ paste with webcams, Raspberry Pi and PHP trickery. So now we can check online whether our toilet is taken or not. :)
The trick with the webcam
The system behind our little project has already been the subject of lively discussion amongst our competitor/colleagues of the Belgian web sector. Farfetched solutions like a pressure sensors under the toilet seat or little gnomes in a cage with a switch are sadly not true.
In all its simplicity we put a webcam in our toilet. It luckily doesn’t shoot any compromising images, but measures the light intensity instead. The cam takes a boring shot of the wall in the front hall and then grants a brightness value to each pixel with PHP-GD.
From those -100 or +100 values we calculate the average, which determines if the toilet is taken or not. Almost dark means no toilet action and a lot of light probably means ‘danger zone in action’. Or the cleaning lady is making her rounds.
Technical set-up Toiletcam
We connected a USB-hub to the Raspberry Pi, which functions as a power source. Additionally we connected 2 USB webcams to take the pictures (2 toilets) and a USB-stick on which we installed the OS. Lastly we plugged in a SD-card to boot the Raspberry Pi.
The calculation of the state of the toilet happens like this:
- Linux-application Streamer takes a still with the webcam and saves it.
- Through PHP-GD the light intensity (brightness) of the pixels gets calculated. The average of these values determines the state of the toilet.
- This result gets compared to the local cache. Only if there’s a difference something happens!
- This event gets filed away in a database log.
- The script pauses for one second, to give the poor Raspberry Pi some much earned rest. ;-)
- Switch toilets, rinse and repeat.
In the same time the Raspberry Pi offers a local website that refreshes each 5 seconds through an Ajax-call, pulls the current states of the toilets and shows them in a nice lay-out.
Surprisingly handy innovations on the working floor
Working at Intracto offers quite a few surprises. In the morning you can moan about the busy toilets on your daily sanitary strolls and in the afternoon the colleagues can already be busy working out a solution to ease the pain.
Next up on our list of innovations is the realtime level of the coffeepot! ;-)
Sorry guys, but the coffeepot (or rather teapot) idea has been done. Teabot
There was the “i-pot”: a kettle with a builtin webserver. The idea was that you could keep an eye on your aged parents by watching the use log.
I told my aged dad about this. He said “what if we found rather nice bottle of merlot?”.
An interesting problem, but just maybe an over engineered result. My guess is that most people lock the door, so a simple on/off (in/out) connection might suffice? or as other people have suggested an IR dector, which at the same time could turn on/off the lights? – but I hear lots of people cry . . those are in “rooms” everywhere already!
Can’t understand why a simple light sensor would not be used. I have a light sensor connected via 433MHz board, and a http://nathan.chantrell.net/tinytx-wireless-sensor/ . This would offer far less evil possibilities and probably wouldn’t be breaking any laws, which this likely is.
Tom Van Looy
The reason a light sensor wasn’t used is because the guy who made this just had these 1$ webcams lying around. It worked.
It’s a neat idea, but I’m not sure if most people would be comfortable having a camera inside the bathroom stall, connected to a computer they don’t know much about, even if the camera is not pointing directly at them.
Why not use a simple light sensor instead?
I asked my boss if I could do something like this, but he pooh-poohed the whole idea.
What it really needs is a gas sensor that makes the occupied sign flash red until it’s safe to enter.
clive — post author
The “Why do it this way when you could do it more simply?” thing comes up a lot when people do inventive/crazy/weird/fantastic/beautiful stuff with the Raspberry Pi. I personally think that is completely misses the point. The answer usually is: because it’s fun, interesting, challenging, different, educational, inventive, collaborative, creative etc.
A serious, parsimonious and permanent solution here would just use a door catch sensor similar to that used in airplane toilets. But a blog titled “Microswitch used to indicate position of door lock” just wouldn’t have the same ring ;)
I assume the reason this time was, cause its a web-dev company; That obv. wanted to use the technology they normally use, and cause a simple light-sensor wouldn’t have brought them up here ;-)
Still nice work.
And thereby proving that they choose the wrong technology. The idea is good, the implementation isn’t.
The idea was just a fun, weird thought we had during our lunch break. We had nothing to proof, just the sheer fun of putting something ridiculous together with stuff we had lying around. :)
Actually, we would’ve even abandoned the whole project if it got too serious and efficient. ;)
Actually, I think that the guys who put this together in our office said that simple webcams were more cost effective than using phototransistors. Simple webcams can be bought for as cheap as 1 euro online.
Sadly in the UK a no goer… ignoring the criminal checks and privacy laws with placing a camera in a toilet…
its the total lack Power Sockets in bathrooms that would prevent it happening!
You could do this in the UK, by just running the Pi off of batteries then.
The coffee pot is a solved problem
Perhaps the coffee pot is the main culprit causing the traffic jam in the toilets?
The Raspberry Pi Guy
A good idea! Whilst there are a few ‘issues’ I am sure that they had great fun getting everything up and going…
I will be sending Clive my post after the weekend!
The Raspberry Pi Guy
ok, i have JUST READ THE TITLE, not the article. so…. by the sound of it, seems that you attached a camera to a Pi, and stuck it into the mens toilets. Ahem…
Very soon someone will hack the pi and put live toilet video telecast on the internet and porn sites. Sick ideas.
Yep, just try user ID pi and password raspberry and you’ll have endless fun broadcasting big ol’ behinds across the planet.
By the title, I had initially thought that the camera was actually somewhere below the rim looking up, ala one of those plastic blue-sanitizer dispensing doo-hickies – hmmm, I wonder how many of those have been cameras all this time? :(
As for power and lack of outlets in tile-covered bathrooms, it seems like this would be a prime opportunity to try running a Pi off of “aromatic hydrocarbons”, if you know what I mean :lol:
Aromatic Hydrocarbons – now that’s a class idea!
Yep, that’s a euphemism for toxic waste.
Sorry to burst your bubble guys, but the camera is placed in the front hall of the toilet. :-) Like I mention in my blog.
So even if the camera is able to capture a meaningful image, it would be of someone washing their hands. A camera in the actual toilet would be a no-fly as well with the colleagues! :D
How about actually wiring the coffee pot up to the Pi so that you can tell it to brew more coffee through the web or maybe do it automatically when the pot is empty.
Now I want to buy an extra pot just to try this!
Make sure your memory is flushed.
Why not to use a simple phototransistor?
not sure I want to see what some smelly old geezer is doing in the krapper.
Does anyone have a set up for
monitering the TP level?
The paper work is very important..
With out which the job can’t be
Do you keep a log of the usage? Could be useful if you want to monitor time and motion
Good idea, Justin! There is a log file, so it could be fun to throw together a usage chart after some time.
Our support team has already hooked up the feed to their monitoring screen. It would be an easy one to plot that one out on a real time graph with weekly digests. :)
Sorry Jason! Saturday morning typo of your name!
Too fartfetched for me..
Strangely, yesterday a bought a Raspberry Pi for almost exactly this use as the alternative method was too expensive to apply widely.
For background to this application see http://dx.doi.org/10.4314/wsa.v39i3.3
I will be following the comments for hints of other methods of determining anonymous use patterns, or contact me directly.
It is an interesting use, and a webcam isn’t typically the first device you would expect to use.
It is innovative at least (although still creepy). I am surprised that no-one has questioned if the camera has an audio-feed either.
To be fair, often it makes sense to make use of the things you have available, since it can be better to just get on and do it than to waiting around for parts to be ordered etc and another job end up taking its place.
Any links available to these $1 cameras ?!?, would be useful to get some (although perhaps not for the loo). They would be handy for messing around with 3D imaging etc.
Not exactly $1, but cheap enough! :-)
Does it also calculate how long someone had been visiting said toilet, so the users of the system know how long to wait before vising? wouldn’t want to walk into a ‘gas zone’ now do we???
Yes, the site also mentions when the toilet has been occupied. Sadly no information about ‘who’ entered the toilet though. :)