Arduino Nano ESP32 - Solenoid Lock
The Solenoid Lock is also known as the Electric Strike Lock. It can be use to lock/unlock cabinet, drawer, door. This tutorial provides instructions on how to use Arduino Nano ESP32 to control the solenoid lock.
An alternative to the Solenoid Lock is Electromagnetic Lock. You can learn more in Arduino Nano ESP32 - 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
Solenoid Lock includes two wires:
- Positive (+) wire (red): needs to be connected to 12V of DC power supply
- Negative (-) wire (black): needs to be connected to GND of DC power supply
How It Works
- When the Solenoid Lock is powered, the lock tongue (strike) is extended ⇒ the door is locked
- When the Solenoid Lock is NOT powered, the lock tongue (strike) is retracted ⇒ the door is unlocked
※ NOTE THAT:
The solenoid lock usually uses 12V, 24V or 48V power supply. Therefore, we CANNOT connect the solenoid lock directly to Arduino Nano ESP32 pin. We have to connect it to Arduino Nano ESP32 pin via a relay
If we connect the solenoid lock to a relay (normally open mode):
- When relay is open, door is unlocked
- When relay is closed, door is locked
By connecting Arduino Nano ESP32 to the relay, we can program for Arduino Nano ESP32 to control the solenoid lock. Learn more about relay in Arduino Nano ESP32 - Relay tutorial.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
Arduino Nano ESP32 Code
The below code lock/unlock the door every 5 seconds
Detailed Instructions
To get started with Arduino Nano ESP32, follow these steps:
- If you are new to Arduino Nano ESP32, refer to the tutorial on how to set up the environment for Arduino Nano ESP32 in the Arduino IDE.
- Wire the components according to the provided diagram.
- Connect the Arduino Nano ESP32 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano ESP32 board and its corresponding COM port.
- Copy the above code and paste it to Arduino IDE
- Compile and upload code to Arduino Nano ESP32 board by clicking Upload button on Arduino IDE
- See the the lock tongue's state