Introduction: MicroPython Program: Is the Toilet Occupied?

Our office is a large group office with limited bathroom space."I" often find that I have no room to go to the bathroom, so I have to wait so long that I feel embarrassed.

The experiment used MakePython ESP8266 to set up a detection server that anyone could access via an IP address to check for toilet seats, avoiding awkward wait times.

Step 1: Supplies


    • MakePython ESP8266
    • Infrared sensor
    • Breadboard
    • Jump line
    • USB cable
    • Scotch tape

    MakePython ESP8266 is an ESP8266 board with an integrated SSD1306 OLED display, you can get it from this link:

    Infrared sensor: When the module detects the front obstacle signal, the green indicator light on the circuit board lights up the level, while the OUT port continues to output low-level signals. The detection distance of the module is 2 ~ 30cm, and the detection Angle is 35°. The detection distance can be adjusted by the potentiometer. when the potentiometer is adjusted clockwise, the detection distance increases; Counterclockwise potentiometer, the detection distance is reduced;


    uPyCraft V1.1

    Click this link to download uPyCraft IDE for Windows:

    Step 2: Wiring

    • The VCC pin of the infrared module is connected to 3V3 of MakePython ESP8266, GND is connected to GND, and OUT is connected to IO14 of the board.

    • Connect MakePython ESP8266 to PC using a USB cable, Open device manager (Simply search for "device" in the Windows search box). When expanded, the port section should display something like the above. Make a note of the port number, such as COM18 in my case. If no port appears, try downloading the USB drive:

    Step 3: UPyCraft Direction for Use

    Download the Get Started MicroPython ESP8266 file, which is detailed in the MicroPython Development Tools section of the file, which will help you download and install the uPyCraft IDE and use it. It also includes an introduction to MakePython ESP8266.

    Or you can get the file from this link:

    Step 4: The Code Download

    Download the file and open it, you need to modify the following points:

    • SSID: need to change to your local network name
    • PASSWORD: need to change to your local network password
    • If the OUT Pin of the infrared module receives a change from the MakePython ESP8266, change the number in the Pin() to the Pin you used to receive it.

    When you're done, to click Save and DownAndRun. "download ok" will be displayed when the download is successful, you can see an IP address (mine:


    Step 5: Installation

    Place the infrared module next to the door for easy detection of people and secure it with sellotape. When someone is using the toilet, the module sends the test results to the server via WiFi, so we can access the server via an IP address to check if the toilet is occupied, instead of waiting by the toilet.

    Step 6: Open a Browser

    Open the browser on your PC, type in the IP address you just got (, and click Enter to confirm.

    Step 7: Testing

    Click the "detect" button, you can check whether the toilet is occupied. When the toilet is occupied, the page will show that it is occupied, otherwise, it will show that there is no one, so you can easily go to the toilet without waiting outside.

    Step 8: Idea

    After the experiment, I had some ideas, in some shopping malls, there are toilets on every floor, but there are often long lines for women's toilets for women's clothes, while men's toilets are empty. Make use of Makepython with Lora connection to detect the mobile phone traffic at the door of each bathroom, judge the number of people, and conduct diversion as expected; I will try it later, if you're interested, follow or join me.