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:

Arduino UNO R4 Solenoid Lock

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Arduino UNO R4 Minima (Alternatively)
1×USB Cable Type-C
1×Solenoid Lock
1×Relay
1×12V Power Adapter
1×DC Power Jack
1×(Optional) 9V Power Adapter for Arduino UNO R4
1×(Recommended) Screw Terminal Block Shield for Arduino Uno
1×(Optional) Transparent Acrylic Enclosure For Arduino Uno

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. We appreciate your support.

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.
Solenoid Lock Pinout

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

The wiring diagram between Arduino UNO R4 solenoid lock

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.

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-solenoid-lock */ #define RELAY_PIN 3 // The Arduino UNO R4 pin connected to the IN pin of relay // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin as an output. pinMode(RELAY_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(RELAY_PIN, HIGH); // uhlock the door delay(5000); digitalWrite(RELAY_PIN, LOW); // lock the door delay(5000); }

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

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!