Arduino UNO Q - Solenoid Lock
A solenoid lock (also called an electric strike lock) is powered by 12V DC and controlled through a relay. Arduino UNO Q can lock and unlock a door, cabinet, or drawer automatically — and with Bridge and Telegram, you can control the lock remotely from anywhere.
In this tutorial, you will learn:
- What a solenoid lock is and how it works
- How to wire a solenoid lock and relay to the Arduino UNO Q MCU
- How to program the MCU (C/C++ Arduino code) to control the solenoid lock
- How to program both the Linux side (Python) and MCU side (C/C++) to lock and unlock via Bridge
- How to lock and unlock remotely via Telegram on Arduino UNO Q
- How to use OpenClaw on Arduino UNO Q with the solenoid lock

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 .
Overview of the Solenoid Lock
Pinout
The solenoid lock has two wires:
- Positive (+) red wire: Connect to the 12V DC power supply
- Negative (-) black wire: Connect to the GND of the 12V DC power supply

How It Works
- When the solenoid lock receives power → the lock tongue extends → the door is locked
- When the solenoid lock has no power → the lock tongue retracts → the door is unlocked
※ NOTE THAT:
The solenoid lock requires 12V DC — it must NEVER be connected directly to an Arduino UNO Q pin. Always use a relay as an intermediary. The relay is controlled by the MCU and switches the 12V supply to the solenoid lock.
When the relay is wired in the normally open configuration:
- Relay open (pin LOW) → no power to lock → door unlocked
- Relay closed (pin HIGH) → power to lock → door locked
For the unlock state (HIGH) and lock state (LOW), refer to the code — the mapping depends on your relay module type (active-HIGH or active-LOW).
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
Connect the relay module IN pin to MCU pin D3. Connect the relay's COM and NO terminals between the 12V supply and solenoid lock. Connect the relay's VCC to 5V and GND to GND.
| Relay Pin | Arduino UNO Q MCU |
|---|---|
| GND | GND |
| VCC | 5V |
| IN | D3 |
How To Program For Solenoid Lock
- Set up the relay pin as output:
- Unlock and lock the solenoid:
Arduino UNO Q Code
The Arduino UNO Q has two processors working together:
- The STM32 MCU controls the relay that switches power to the solenoid lock — all timing and state 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.
This code unlocks the solenoid lock for 5 seconds, then locks it again — repeating continuously.
Detailed Instructions
First time with Arduino UNO Q? Follow the Getting Started with Arduino UNO Q tutorial before proceeding.
- Connect: Wire the solenoid lock, relay, and 12V power supply 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: SolenoidLock
- 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 the built-in digitalWrite() function.
- Upload: Click the Run button in Arduino App Lab.

- Observe the solenoid lock alternating between locked and unlocked every 5 seconds.
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 lock and unlock the solenoid lock via Bridge:
- The solenoid lock is connected to the MCU via relay — the MCU controls the relay output pin
- The MPU cannot control the relay directly — it calls Bridge functions to lock or unlock
- The MPU has Wi-Fi — running full Debian Linux, it can accept commands from Telegram or any web service and translate them into lock/unlock actions
- 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: MPU receives lock/unlock commands → calls Bridge → MCU controls relay → solenoid lock activates.
MCU Code (Bridge)
Python Code (Bridge)
Detailed Instructions
- Connect: Wire the solenoid lock, relay, and 12V power supply 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 SolenoidLockBridge, 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.

- Watch the lock cycle: unlock → wait 5 seconds → lock → wait 1 second → repeat.
App Lab Console Output
Telegram
Control the solenoid lock remotely via Telegram — lock and unlock from anywhere with a simple command.
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. Send /unlock from Telegram to open the lock, then /lock to close it again.
App Lab Console Output
ArduinoBot
OpenClaw
...OPENCLAW
OpenClaw support for Arduino UNO Q Solenoid Lock is coming soon.
...OPENCLAW
Project Ideas
You can build many useful projects with the solenoid lock and Arduino UNO Q:
- Telegram-Controlled Door Lock: Control your front door or office lock remotely using Telegram — /unlock to let someone in and /lock to secure it again, with all events logged with timestamps
- Time-Based Auto-Lock: Program the MPU (Linux Python) to automatically lock at 10 PM and unlock at 7 AM every day — using the system clock on the Linux side to trigger Bridge commands
- Keypad Access System: Combine the solenoid lock with a 4x4 keypad on the MCU — unlock when the correct PIN is entered, and send a Telegram alert whenever an incorrect PIN is tried three times in a row
- Access Log System: Log every lock and unlock event to a CSV file on Linux — include timestamp, command source (Telegram or automatic), and generate daily reports sent to Telegram
- Guest Access Manager: Create a time-limited unlock via Telegram — /unlock_5min unlocks the door and relocks it automatically after 5 minutes, with a Telegram confirmation sent when the timer expires
Challenge Yourself
Ready to go further with the solenoid lock on Arduino UNO Q? Try these challenges:
- Easy: Add a Telegram /unlock_10s command that unlocks the lock for exactly 10 seconds using time.sleep(10) on the Python side before calling Bridge.call("lock").
- Medium: Implement a Telegram /schedule command that parses a time argument (e.g., /schedule 23:00) and automatically locks the door at that time using the Linux system clock on the MPU.
- Advanced: Build a multi-user access system: store a list of authorized Telegram user IDs in a Python file — only those users can send /unlock commands, and all unauthorized attempts trigger a Telegram alert to the admin's chat ID.