Living in a house and sharing a bathroom with several housemates can lead to several problems. Say you sit in the kitchen and feel the urge to go to the bathroom, walk the stairs up to the second floor just to find out that the bathroom is occupied. So the first idea was to install a light in every room that lights up whenever the bathroom is occupied and thus saving a potential useless walk to the loo. Shortly after that the idea was born not only to show when the bathroom is occupied but to somehow log that information together with a timestamp to get more information.
The goal of this project is to get an overwiew of the bathroom usage and to get an idea of the loo usage patterns.
The next picture gives an overview over what is happening:
An electrical switch is attached to the bathroom's door lock. When the door is locked the switch is closed thus igniting the lights in the rooms. This information also flows to a microcontroller that registers and logs the status change together with a timestamp which comes from a radio controlled DCF77 clock module to a file on a USB memory stick. The log file is later read into a MySQL database. A web app then reads from that database, evaluates and reports on the loo usage.
The door lock switch is a pretty simple construction made of several pieces of tinfoil attached to the door locking mechanism.
The logger circuit mainly consists of the following parts: a Schmitt trigger that converts the battery powered door lock status information signal into a well defined TTL signal, a receiver module for receiving the DCF77 atomic clock signal, a microcontroller (an Atmel AT90CAN128 in this caseand an STI100 USB memory stick to serial adapter.
The next picture shows an animated sequence of the loo looger circuit in action:
The firmware is written in AVR C. It consists of a main loop that polls the status of the signal the Schmitt trigger delivers (and also does some simple debouncing on that signal), an ISR for reading and decoding the time signal from the DCF77 clock module and some routines for communication with the USB module over RS232.
You can find the source on Bitbucket