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!