A toilet smarter than you? Measuring toilet usage with IoT
By: Naomi Yeo
Tags: Raspberry Pi, Singapore, Python, IoT, Toilets

Level of toilet usage ≈ cleanliness

Our solution, which consists of a magnetic and motion sensor, records when a person enters and exits the handicapped toilet, where we deployed our sensors.

Door contact sensor in concept

Door contact sensor installed outside the toilet

Our magnetic door contact sensor (DCS) is placed on the external side and near the top of the toilet door to deter the public from tampering with our DCS. The DCS detects whether the door is open or closed, and is connected to a BBC micro:bit.

Passive infrared sensor in concept

Passive infrared sensor installed just above the toilet door

Our Passive Infrared Sensor (PIR), which is also connected to a Microbit, is placed on the internal side at the top of the toilet door to capture data on any motion when a patron enters or exits the toilet.

Overview of the devices and connections

Our architecture sets up a framework for transmitting data from the sensor nodes to be stored in a cloud database to allow for easily accessible live updates. It connects the two sensors attached to a Microbit each to receiving Microbits via Bluetooth. The receiving Microbits are connected to the Raspberry Pi (RPi), a microcomputer, with wifi connection, which acts as a gateway and transmits sensing data over Google Cloud Platform’s (GCP) Cloud IoT Core using the lightweight messaging protocol, MQTT. On the receiving end, we have also made use of GCP’s Cloud Pub/Sub to subscribe to the topic used for publishing the sensing data. This way, messages received from Cloud Pub/Sub will be automatically inserted into the GCP’s SQL database, Google BigQuery.

In order to detect the usage of the toilet, our group has programmed the RPi to use the following sequence for detection based on the human behaviour for entering the handicapped toilet.

User opens the door: DCS triggered with value 0. User enters the toilet: PIR triggered with value 1. User closes/locks the door: DCS triggered with value 1.

Upon the initiation of this series of actions, the program will then look out for the next series of actions that signify the exit of the user from the toilet, which is as follows.

User moves towards the door: PIR triggered with value 1. User opens the door: DCS triggered with value 0. The door automatically closes / User closes the door: DCS triggered with value 1.

With these two sets of actions, our sensors are able to detect when the user enters and leaves the toilet with lesser false positives. This allows us to record the time of entry and exit of each user, which would not be possible without the combination of data from both sensors. If we had used only the DCS, it would not be able to track whether the user was entering or exiting the toilet. On the other hand, with only the PIR, there would be a lot of false alarms caused by random movements of the user near the sensor. Hence, by using the sensors to complement each other, we can reduce the number of false alarms significantly and greatly increase the accuracy of our data.

Our dashboard visualising toilet usage

Upon triggering the sensors, the dashboard is automatically updated with the latest information such as the occupancy for the current time slot, handicapped toilet current status, as well as the average duration of usage of the toilet. Other useful information also include the average occupants per day and number of occupants for the past month. These insights allow the management to decide on cleaning schedules at particular time slots to enhance user experience.

As detecting bacteria level can be costly and requires a plethora of equipment and sensors, our solution instead looks towards the level of usage of toilets to determine toilet cleanliness. By the rule of probability, toilets would be dirtier since certain spots that are more frequently touched would require more frequent cleaning, and usage of toiletries and poor hygiene habits would adversely impact the level of cleanliness of the toilet.

Through our solution, patrons and stallholders using the toilet are less likely to be exposed to illnesses. Janitors will also clean the toilet only when needed, so the time for regular cleaning can be used for attending to other matters instead. Lastly, the management of the hawker centre can lower operating costs by hiring less janitors to maintain the higher standards of toilet cleanliness since the frequency of cleaning is reduced.