Arduino UNO Q - Door Sensor - LED
Combine a door sensor with an LED on Arduino UNO Q so the LED turns on automatically when the door opens and off when it closes. Add Bridge and Telegram to control the LED remotely and receive instant door alerts.
In this tutorial, you will learn:
- How to wire a door sensor and LED to the Arduino UNO Q MCU
- How to program the MCU (C/C++ Arduino code) to control an LED with a door sensor
- How to program both the Linux side (Python) and MCU side (C/C++) to monitor door state and control the LED via Bridge
- How to receive Telegram alerts and control the LED remotely when the door opens or closes on Arduino UNO Q
- How to use OpenClaw on Arduino UNO Q with the door sensor and LED

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Buy Note: Use the LED Module for easier wiring. It includes an integrated resistor.
Overview of LED and Door Sensor
If you are unfamiliar with the LED or door sensor, refer to these tutorials first:
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
Door Sensor:
| Door Sensor Pin | Arduino UNO Q MCU |
|---|---|
| Pin 1 | GND |
| Pin 2 | D9 (with INPUT_PULLUP) |
LED:
| LED Pin | Arduino UNO Q MCU |
|---|---|
| Anode (+) | D3 (via 220Ω resistor) |
| Cathode (-) | GND |
How To Program For Door Sensor + LED
- Set up pins:
- Sync LED state with door sensor:
Arduino UNO Q Code
The Arduino UNO Q has two processors working together:
- The STM32 MCU reads the door sensor and controls the LED directly — no delays needed, all logic runs on the MCU
- The Qualcomm MPU runs Debian Linux and handles Wi-Fi, Python, and cloud connectivity
- In this section, only the MCU is programmed — the Linux side stays idle. A later section shows how both processors work together via Bridge.
The LED turns ON when the door opens and OFF when it closes. State is printed to the Serial Monitor every 500ms.
Detailed Instructions
First time with Arduino UNO Q? Follow the Getting Started with Arduino UNO Q tutorial before proceeding.
- Install: Fix the magnet to the door and the reed switch to the door frame.
- Connect: Wire the door sensor and LED to the Arduino UNO Q MCU as shown in the wiring diagram.
- Open Arduino App Lab: Launch Arduino App Lab and wait until it detects your Arduino UNO Q.
- Create a new App: Click the Create New App button.

- Give the App a name, for example: DoorSensorLed
- Click Create to confirm.

- Paste the sketch: Copy the MCU code above and paste it into sketch/sketch.ino. Keep other files as default.
- No library required — uses only built-in digitalRead() and digitalWrite().
- Upload: Click the Run button in Arduino App Lab.

- Open and close the door — watch the LED and Serial Monitor.
App Lab Console Output
Bridge: Linux + MCU
This section shows how to program both processors of the Arduino UNO Q so the Linux side can monitor the door state, control the LED, and detect door events via Bridge:
- The door sensor and LED are connected to the MCU — the MCU monitors state changes in loop() and sets event flags automatically
- The MPU cannot read the door sensor or control the LED directly — it calls Bridge functions to query state or issue commands
- The MPU has Wi-Fi — running full Debian Linux, it can send Telegram alerts and accept remote LED control commands
- Arduino_RouterBridge enables RPC communication between the two processors
- ⚠️ /dev/ttyHS1 (Linux) and Serial1 (MCU) are RESERVED by the router — never open them in user code
In short: MCU monitors door events and controls LED in loop() → MPU reads state and sends commands via Bridge → MPU alerts and remote-controls over Wi-Fi.
MCU Code (Bridge)
Python Code (Bridge)
Detailed Instructions
- Connect: Wire the door sensor and LED to the Arduino UNO Q as shown in the wiring diagram.
- Open Arduino App Lab: Launch Arduino App Lab and wait for the board to be detected.
- Create a new App: Click Create New App, name it DoorSensorLedBridge, then click Create.
- Paste the MCU sketch: Copy the MCU Bridge code above and paste it into sketch/sketch.ino.
- Paste the Python code: Copy the Python Bridge code above and paste it into the Python file in the App.
- Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.

- Search for Arduino_RouterBridge created by Arduino and click the Install button.
- Upload: Click the Run button in Arduino App Lab.

- Open and close the door. Watch LED, MCU console, and Python console all react.
App Lab Console Output
Telegram
Get instant Telegram alerts when the door opens or closes, and control the LED remotely.
MCU sketch: Keep the same MCU sketch from the previous Bridge section.
Python Code (Telegram)
Detailed Instructions
- Replace YOUR_TELEGRAM_BOT_TOKEN with your actual bot token from BotFather.
- Replace YOUR_CHAT_ID with your Telegram chat ID.
- Paste this Python code into your App's Python file (keep the same MCU sketch).
- Click the Run button. Open the door — receive the Telegram alert. Send /ledon to force the LED on remotely.
App Lab Console Output
ArduinoBot
OpenClaw
...OPENCLAW
OpenClaw support for Arduino UNO Q Door Sensor + LED is coming soon.
...OPENCLAW
Project Ideas
You can build many useful projects with the door sensor and LED on Arduino UNO Q:
- Entry Indicator Light: Mount a bright LED near the entrance — it lights up automatically whenever the door opens, giving visitors and occupants a clear visual signal
- Remote Door Monitor: Use Telegram to check whether the door is currently open or closed from anywhere — and remotely turn on the LED as a deterrent if the door is unexpectedly open
- Nightlight Trigger: Activate a relay-controlled nightlight via Bridge when the door opens after sunset — the MPU checks current time on Linux before issuing the set_led on command
- Smart Mailbox: Install a door sensor on a mailbox lid — when mail is delivered (lid opens), the LED lights up and a Telegram notification is sent so you know when to collect mail
- Garage Door Status Panel: Use the door sensor on the garage door and the LED as a status indicator inside the house — the Python side also logs every open/close event with timestamps to a file
Challenge Yourself
Ready to go further with the door sensor and LED on Arduino UNO Q? Try these challenges:
- Easy: Add a second LED in a different color (e.g., green) that is always ON when the door is closed and OFF when open — giving a dual-color open/closed status indicator without any Bridge logic.
- Medium: Implement a Telegram /toggle command that flips the LED state via Bridge regardless of the door state — allowing manual override while still auto-syncing on the next door event.
- Advanced: Build an animated door-open warning: when the door opens, the LED blinks at 2Hz via PWM on the MCU — implement the blink in a separate Bridge function set_led_blink(String) that takes "on" or "off" as argument.