Sign in

A toilet smarter than you? Measuring toilet usage with IoT

In a recent study, a poll on 97% of Singapore’s coffee shop and hawker centre workers found that the state of the toilets needed to be improved. Almost 6,000 customers surveyed said that they were unwilling to use the toilets at coffee shops and hawker centres. Given that Singapore’s hawker centres are one of the two most frequented dining establishments in Singapore, poor public toilet hygiene has always been of great concern. Bacteria and viruses are easily spread in public toilets. Beyond health risks posed by an unsanitary toilet environment, dirty public toilets can lead to poor perceptions of general hygiene of the entire hawker centre by Singaporean patrons and tourists.

In June 2020, NEA introduced a Toilet Improvement Programme. In short, it involves:

  1. Infrastructural changes to better manage public hygiene
  2. Incorporation of new technologies and improved business processes to facilitate efficient maintenance and operations
  3. Upgrading works for toilets that encourage users to keep the toilet clean

Additionally, failure to meet the standards for toilet cleanliness can also rack up a fine from the now more stringent penalty regime.

In line with NEA’s SG Clean’s efforts to raise public cleanliness standards, the need for a simple, cheap and accurate monitoring system that can help to study and produce further insights on toilet cleanliness emerges.

We were given the opportunity to carry out our research in Berseh Food Centre (BFC), where we first found out about its current measures. At BFC, apart from a feedback system, sensors have been installed to measure odour levels of mainly ammonia, which is found in urine, and hydrogen sulfide, in faeces. When activated, the sensors send a signal to the janitor to carry out a cleaning in the toilet. However, based on our onsite research, we found that the sensors were seldom, if at all, activated as cleaners are already scheduled to clean the toilets 4 times a day. This then poses the question of whether manpower is being used efficiently, if the janitor is to clean the toilet even when it is not registered as dirty. Furthermore, does the “silence” of the sensors necessarily mean that the toilet is clean?

We felt that the existing solution does not accurately represent toilet cleanliness. Hence, we had hoped to collect insights that help BFC achieve a higher standard of cleanliness, in line with the criteria laid out by the Restroom Association’s Happy Toilet Programme. With use of IoT sensors to determine the correlation between increased toilet usage and overall cleanliness (visual and non-visual) of the toilet, we aimed to provide a more holistic and cost-effective approach to measuring public toilet cleanliness, not only in BFC, but in hawker centres nationwide. Along with it, we hoped this approach produced insights that empower the management of BFC to deploy janitors only when needed to improve the overall cleanliness of toilets and make other more well-informed decisions in the future.

On a macro scale, we also concluded that there is a need to analyse more comprehensive data and get deeper insights on public toilet cleanliness. To do so, we needed to explore improved methods, preferably automated, that are scalable and easy to implement in public toilets across Singapore. By doing so, we hope that we can help NEA generate insights to progress towards maintaining cleaner public toilets in the long run.

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.

  1. User opens the door: DCS triggered with value 0.
  2. User enters the toilet: PIR triggered with value 1.
  3. 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.

  1. User moves towards the door: PIR triggered with value 1.
  2. User opens the door: DCS triggered with value 0.
  3. 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.

While a concept may work in the perfect situation, the world is, more often than not, not perfect.

Our initial algorithm targeted only the most common toilet usage behaviour, but we soon realised in the design phase that we also had to account for other usage behaviours to minimise false positives. For example, if a patron opens the door without entering the toilet, our sensors should not register it as toilet usage. Likewise, if a patron opens the door and uses the sink without closing the door, our sensors should register the toilet usage.

Given our limited time, we considered three scenarios.

  1. The ‘normal’ way: User goes in and locks the door, and closes the door after exiting
  2. Non-usage: User opens the door but does not enter
  3. Open-door usage: User opens the door and washes hands while stopping the door from closing

Our attempts to perfect the last scenario were unfruitful. Hence, we decided to use a timer as the next best solution, by setting a certain duration the sensor waits before it registers the toilet usage.

On another note, we realised that all solutions have some constraints and that it is impossible to have a perfect sensor that captures all scenarios.

A major constraint faced was the budget allocated. As our research was hardware-intensive, not to mention considerations for storage and anti-theft measures, we kept to the budget of $180 by opting for cheaper sensors. However, this meant affecting the accuracy of captured data to some extent.

To maximise the use of our budget, we chose to work on the handicapped toilet. Being the only toilet on the upper floor of BFC, it is used by both patrons and stallholders. This meant that it served as the data for the entire level’s toilet usage! Restricting ourselves to this one toilet facilitated the accuracy as we could focus on managing the quality of data with our few sensors, rather than handling a complex system of sensors, given the magnitude of our project.

We also had to purchase a portable Wi-Fi router and power adapter due to the poor Wi-Fi connectivity at the hawker centre, adding to the strain on our already-tight budget. Furthermore, the toilet walls were too thick for Wi-Fi signals to penetrate. This resulted in an unstable connection that sometimes affected the data-publishing from the RPi to the cloud, causing data inconsistencies and losses at times.

The additional usage of power brought about another challenge: limited power outlets were available in the handicapped toilet. We initially tried using the power outlets outside the toilet, but the wires posed as a hazard, and connectivity was poor. Thus, we looked for other power sources (i.e. power banks, batteries) for our sensors. The DCS was battery-powered, but the PIR’s high power consumption required a constant supply of electricity. To satisfy this constraint, we borrowed an extension outlet for more ports to power both the RPi and PIR in the toilet.

However, given a one-week deployment period, we were unfortunately unable to collect sufficient data to derive the actionable insights for the janitors.

Despite that, we hope that in the future, by complementing our sensors with other sensors, predictive analytics can be conducted to generate actionable insights like informing janitors on when to clean. This can help to lay out the key groundwork for creating smart toilets and expanding it to other public toilets in Singapore in the long run.

Learning from feedback

The feedback from the sponsors was generally positive. One sponsor feedbacked that occupancy rate was not the only way to measure toilet cleanliness, and suggested experimenting with other methods. Another feedback suggested looking into other sensors to complement the DCS and PIR by detecting abnormalities in the toilet to obtain even more accurate readings on toilet cleanliness. Our sponsors were also concerned with the costs incurred if use of these sensors was expanded. However, our team felt that it is still viable as the main bulk of the costs went to the setup of the infrastructure. Adding sensor nodes during expansion would therefore not be costly.

With all that said, more time and budget is still needed to enhance this solution that is in its infancy as it is still wanting in its consideration for the variety of use cases out there.

This article is jointly written by Chew Wei Bin, Kevin Sia, Naomi Yeo, Roy Tan and Sabrina Ow.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store