Embedded SystemsIntermediatePRJ-065

Smart Public Restroom Monitoring System Using ESP8266

Flags when a restroom needs cleaning and shows the water tank level.

Built and tested by Shahan Fathima K · Industrial Robotics Institute

Circuit diagram of the Smart Public Restroom Monitoring System using ESP8266 NodeMCU
Circuit diagram · ESP8266 NodeMCU
LevelIntermediate
Build time2–3 hours
BoardESP8266 NodeMCU
Parts8 components

What is the Smart Public Restroom Monitoring System?

A monitoring system for public restrooms. A gas sensor measures odour, an ultrasonic sensor checks the water tank level, and a PIR sensor detects usage. The ESP8266 shows "Clean" or "Needs Cleaning" plus the water level on an LCD, and sounds a buzzer to call maintenance staff.

How it works

  1. The MQ-135 gas sensor measures odour; the ultrasonic sensor measures the water tank level.
  2. The PIR sensor detects someone using the restroom.
  3. If the odour reading goes above 400, the LCD shows "Needs Cleaning" and the buzzer sounds.
  4. Otherwise it shows "Clean".
  5. The second line shows the distance to the water surface in cm.

Parts list

ComponentQty
ESP8266 NodeMCU1
PIR Motion Sensor1
Gas Sensor (MQ-135)1
Ultrasonic Sensor (HC-SR04)1
16×2 LCD with I2C Module1
Buzzer1
Jumper WiresAs needed
Power Supply1

Software

  • Arduino IDE
  • LiquidCrystal_I2C library

Wiring and connections

FromConnect to
PIR OUTD1
MQ-135 AOUTA0
Ultrasonic TRIGD2
Ultrasonic ECHOD3
LCD SDAD4
LCD SCLD5
Buzzer +D6
All sensors and LCD VCC / GND5V (VIN) / GND

How to build the Smart Public Restroom Monitoring System

  1. Wire the PIR to D1, the MQ-135 to A0 and the ultrasonic sensor to D2/D3.
  2. Connect the I2C LCD to D4 (SDA) and D5 (SCL), and the buzzer to D6.
  3. Mount the ultrasonic sensor at the top of the water tank, facing down.
  4. Install the LiquidCrystal_I2C library and upload the code.
  5. Let the gas sensor warm up and adjust the 400 threshold for your restroom.

Smart Public Restroom Monitoring System code

Complete, tested Arduino C++ code for this project. Copy it into Arduino IDE and upload it to the ESP8266 NodeMCU.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define pirPin  D1
#define gasPin  A0
#define trigPin D2
#define echoPin D3
#define buzzer  D6

LiquidCrystal_I2C lcd(0x27, 16, 2);

long duration;
int distance;

void setup()
{
  pinMode(pirPin, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  Wire.begin(D4, D5);   // SDA = D4, SCL = D5
  lcd.init();
  lcd.backlight();
  lcd.print("Smart Restroom");
  delay(2000);
  lcd.clear();
}

void loop()
{
  int motion = digitalRead(pirPin);
  int gasLevel = analogRead(gasPin);

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;

  lcd.setCursor(0, 0);
  if (gasLevel > 400)
  {
    lcd.print("Needs Cleaning  ");
    digitalWrite(buzzer, HIGH);
  }
  else
  {
    lcd.print("Clean           ");
    digitalWrite(buzzer, LOW);
  }

  lcd.setCursor(0, 1);
  lcd.print("Water: ");
  lcd.print(distance);
  lcd.print("cm   ");

  delay(1000);
}

Real-world uses

  • Railway and bus stations
  • Malls and offices
  • Schools and colleges
  • Smart city facilities

Frequently asked questions

What is a Smart Public Restroom Monitoring System?

A monitoring system for public restrooms. A gas sensor measures odour, an ultrasonic sensor checks the water tank level, and a PIR sensor detects usage.

What components are needed for the Smart Public Restroom Monitoring System?

You need: ESP8266 NodeMCU (1), PIR Motion Sensor (1), Gas Sensor (MQ-135) (1), Ultrasonic Sensor (HC-SR04) (1), 16×2 LCD with I2C Module (1), Buzzer (1), Jumper Wires, Power Supply (1). Software: Arduino IDE, LiquidCrystal_I2C library.

Is the Smart Public Restroom Monitoring System project good for beginners?

It is rated intermediate and takes about 2–3 hours to build, using the ESP8266 NodeMCU. The guide on this page explains every connection and step.

Where can I get the code for the Smart Public Restroom Monitoring System?

The complete, tested Arduino C++ code is free on this page. Copy it into Arduino IDE and upload it to the board.

Can I buy a kit for the Smart Public Restroom Monitoring System?

Yes. IRI sells a kit with the parts for this project (PRJ-065). Message IRI on WhatsApp at +91 86060 82634 for the kit price and delivery details.

Industrial Robotics Institute
Logo