Arduino Nano 33 IoT - Solenoid Lock
The Solenoid Lock, also called the Electric Strike Lock, is a device that locks or unlocks cabinets, drawers, or doors. This guide shows you how to use an Arduino Nano 33 IoT to control the solenoid lock.
Another option for a solenoid lock is the electromagnetic lock. You can find more information in the Arduino Nano 33 IoT Electromagnetic Lock tutorial.

Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of Solenoid Lock
Pinout
The solenoid lock has two wires:
- Red wire (+): Connect to the 12V output of the DC power supply.
- Black wire (-): Connect to the ground (GND) of the DC power supply.

How It Works
- When the solenoid lock receives power, the metal piece moves out, and the door becomes locked.
- When the solenoid lock does not receive power, the metal piece moves in, and the door becomes unlocked.
※ NOTE THAT:
The solenoid lock normally works with a 12V, 24V, or 48V power supply. This means you should not connect the solenoid lock directly to an Arduino Nano 33 IoT pin. Instead, you need to use a relay to make the connection.
If we attach the solenoid lock to a relay that stays open by default:
- When the relay is turned off, the door is unlocked.
- When the relay is turned on, the door is locked.
Connect the Arduino Nano 33 IoT to the relay, and then you can write a program to control the solenoid lock. Learn more about the relay in the Arduino Nano 33 IoT - Relay tutorial.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
Arduino Nano 33 IoT Code
The code below locks and unlocks the door every five seconds.
Detailed Instructions
If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:
- Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
- Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
- Copy the code above and paste it into the Arduino IDE.
- Click the Upload button in the Arduino IDE to compile the code and send it to the Arduino Nano 33 IoT board.
- Check the status of the lock tongue.