Solenoid Lock Interfacing With Arduino

Hey geeks, welcome back to Techatronic. In this article, we are going to discuss the interfacing of a Solenoid Lock with Arduino. Do you want to know more about the Arduino UNO microcontroller board, if so you can click to read? We use a Relay module for turning the solenoid lock on and off. If you are not aware of the interfacing of the Relay module with Arduino then check it first. Also, you can check out more such amazing projects on Arduino. We have an E-book on Arduino which contains 10+ projects on Arduino with detailed circuit diagrams and codes. After completing the circuit please upload the given code.

What is a Solenoid Lock

Basically, it is an Electromagnetic lock that works on the principle that a current-carrying coil produces a magnetic field near it. Inside the Solenoid valve, there is a coil of insulated copper wire which is wound in the shape of a hollow cylinder. There is an armature inside the coil which moves freely. When we pass the electric current to the coil it generates a magnetic field near it. The movement of the armature depends on the magnetic field generated by the insulated copper coil. A solenoid lock looks like this.

solenoid lock

How Does it Work?

The solenoid lock is controlled by Arduino, it generates the signals so the lock turns on and off after the delay of a second. The lock is not directly connected with the Arduino instead of it we use a relay module. You can found these types of locks on the doors, safes, and cupboards nowadays. As the lock works with electricity so in case of power failure the lock can’t be opened or closed. You can use different sensors with it to make a high-security lock system. The solenoid lock needs a 12-volts DC supply for its functioning so you have to provide it. Unlike manual locks, a solenoid lock is more secure and you don’t need any key to open it as it works on electricity.

Components Required

  • Arduino UNO
  • Solenoid Lock
  • DC 12-v supply
  • USB cable for uploading the code
  • Jumper wires

Circuit Diagram for the Project


You have to make the connections according to the circuit diagram given above. Connect the 5-volts pin of the Arduino to the VCC pin of the Relay module. Join the GND pin of the Arduino to the GND pin of the Relay module. Attach the Relay IN pin of the Relay module with the digital-12 pin of the Arduino as shown above. You have to connect the positive wire of the DC power supply to the other side of the Relay module and the negative wire to the solenoid lock as shown. Connect the positive wire of the solenoid lock with the Relay module. Now upload the code to the Arduino.

Code for the Project

NOTE: Please upload the code given below to the Arduino as it is.

  void setup()   
  pinMode(12,OUTPUT); // RELAY PIN   
  digitalWrite(12,HIGH); // Normally ON Only For Chanies Relay Module   
  void loop()    
  digitalWrite(12,LOW); // RELAY ON   
  digitalWrite(12,HIGH); // RELAY OFF   

We hope that you understand the project well. If you are facing any errors do tell us in the comments section below. Please view more Tutorials on Arduino and Raspberry Pi.