Arduino UNO R4 - Solenoid Lock
This tutorial instructs you how to use Arduino UNO R4 and the solenoid lock to lock/unlock your door, cabinet, or drawer. In detail, We will learn:
- How to connect the solenoid lock to an Arduino UNO R4.
- How to program the Arduino UNO R4 to control the solenoid lock.
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
The solenoid lock, also called the electric strike lock, is used to lock or unlock items like cabinets, drawers, and doors.
Pinout
The solenoid lock has two wires:
- Connect the positive (+) red wire to the 12V DC power supply.
- Connect the negative (-) black bit to the ground (GND) of the DC power supply.
How It Works
- When the solenoid lock has power, the lock tongue (strike) moves out ⇒ the door is locked.
- When the solenoid lock has no power, the lock tongue (strike) pulls back ⇒ the door is unlocked.
※ NOTE THAT:
The solenoid lock typically needs a 12V, 24V, or 48V power supply. We MUST NOT connect the solenoid lock directly to the Arduino UNO R4 pin. Instead, connect it through a relay to the Arduino UNO R4 pin.
If we connect the solenoid lock to a relay in the normally open setting:
- If the relay is open, the door is unlocked.
- If the relay is closed, the door is locked.
You can connect an Arduino UNO R4 to a relay to program it to control a solenoid lock. Find out more about using a relay with Arduino UNO R4 in our tutorial Arduino UNO R4 - Relay Tutorial.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
Arduino UNO R4 Code
This code will lock and unlock the door every 5 seconds.
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Connect the solenoid lock to the Arduino Uno R4 according to the provided diagram.
- Connect the Arduino Uno R4 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Copy the code and open it with Arduino IDE
- Click the Upload button in Arduino IDE to upload the code to Arduino UNO R4
- Check the position of the lock tongue