Smart Door System

Infrared sensor at the top of a bedroom door, wired along the frame to a small board

April 2024

I wanted my computer to go quiet when someone opens my bedroom door. So there's an infrared sensor at the top of the door frame: when the door opens, the volume drops, and when it closes, it goes back to where it was.

The sensor is held on with electrical tape. A three-wire servo cable runs along the frame to an ESP32 mounted by the hinge: red to 3V3, brown to ground, and orange (the signal) to GPIO4. The ESP32 runs off a USB wall adapter and tells the computer over Wi-Fi whenever the door changes.

Code

There are two parts. The sketch on the ESP32 sends DOOR OPEN or DOOR CLOSED, and repeats it every 2 seconds. A Python script on the computer listens and changes the volume. Because of the repeats, the script can tell when the board has been unplugged and put the volume back instead of leaving it low.

I lost my first version of the code, so this is a newer one, and I haven't tried it on the door yet. The Wi-Fi name and password go at the top of the sketch.

door_sensor/door_sensor.inoDownload

← Back to hardware projects