Our current roster in APSL is formed by 35 persons, 32 of them are always in our offices (remember, we are a remote company!). But we have a big issue: only two toilets for 32 persons, the same as when we were 14 people. The team scaled, not so the toilet, and this causes so many visits to the toilets and the annoying result that both are occupied.
For this reason we decided to put any kind of device to check if the toilet is free and how long is being used. Many of the members of our company had experience hacking Arduinos and other IoT stuff but we decided to move an step forward. Since we are a company who loves Python we always dreamed to experiment with Micropython and this was the excellent project.
Some of the workmates who attended to PyConES went to a talk about Micropython and discovered that there is a thing named ESP8266 NodeMCU which is a small wireless micro-board which can be programmed in Micropython and it is very cheap (you can find it any Chinese marketplace from prices below 3€). The ESP8266 it's very popular in the IoT enviroment because it provides a wireless device out of the box. In fact the microcontroller is the wireless chipset itself! Take a look how simple it is to send a data via POST with Micropython.
How do we know if the toilet is in use? Since our toilets are only suitable for one person if there is light in the room it means that there it's occupied by somebody. Easy, isn't it? So we need a light sensor: a LDR. Those are a cheap and simple components to detect light. Its output resistance value depends of the amount of light that they receive. We followed this basic approach to connect the LDR to the board.
Once we calibrate the sensor values and test the circuit in a protoboard we build the same schema in a PCB to use in it the real environment.
Then we needed a case to protect the board and place it in a good place of the bathroom. So we downloaded a PCB case printable 3D model in thingverse and modified to fit the dimensions of the PCB and the NodeMCU. We printed the case thanks our friend Marcos.
Finally we assembled all the pieces and placed one of them in each toilet. As it needs power we simply connected a micro-usb adapter to the board.
On the other hand, we need to show the status of the toilet in a website to easily view if the toilet is free or not. So we built a simple Django app with the brand new websockets frameworks Channels. With a few lines the site renders almost in real-time when somebody enters and leaves a toilet.
So we also built and API where the ESP8266 sends a POST requests to the Django server when detects if the status changes. Also, we put a fancy favicon in the website to see how many toilets are occupied.
As you can see, it also displays you the total time of the bathrooms is being using and the last usage of time every bathroom (this could be useful for many reasons). The systems is prepared to add more toilets dynamically.
We also provided an section where you can view interesting stats: