Control Solenoid Door Lock using Relay on Arduino

Do you know how to use a relay?


Hi guys! Do you know how to control a 12VDC solenoid door lock using a relay? With a simple circuit connection, now you can use a solenoid door lock for your project.


Watch this video for more info on How To Control A 12VDC Solenoid Door Lock Using A 5V Relay on Arduino. You’ll also learn the difference between normally open and normally closed relay connections in this video.

Hardware Preparation

This is the hardware connection and the components needed.

Sample Code


#define BUTTON 2 // the number of the pushbutton pin
#define RELAY 3 // the number of the relay pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
// initialize the pushbutton pin as an input:
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(BUTTON);
// check if the pushbutton is pressed.
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(RELAY, HIGH);
} else {
// turn LED off:
digitalWrite(RELAY, LOW);
view raw Solenoid_Relay.ino hosted with ❤ by GitHub

Thank you

Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiries, please post at Cytron Technical Forum.

4 thoughts on “Control Solenoid Door Lock using Relay on Arduino”

  1. Guilherme Silva

    Hello, could you please send or show the whole code? I’m rying to replicate it for my final project and yours is really well made, could you please do that? Thanks in advance!

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

DIY Digital Alarm Clock Using REKA:BIT With Micro:bit
Display Internet Time (NTP) on micro:bit
DIY Interactive Robot Using REKA:BIT With Micro:bit
BLTouch Installation for Ender 3 with 32-bit V4.2.2 Board
Pick and Send Random Meal’s Option and Locations through Telegram Bot Using Grove WiFi 8266 on micro:bit
Tutorials of Cytron Technologies Scroll to Top