Keypad Solenoid Door Lock Using Arduino

Introduction

Today we will make a keypad solenoid door lock system using Arduino. The solenoid door lock will unlock if the password entered by the keypad is correct. Let’s try to make a keyless door lock together?.

Video

Watch this video to know more about it.

Hardware Preparation

This is the list of items used in the video.

/*
Project: CUnlock the Soenoid Door Lock Using A Keypad and Maker Nano #ArduinoNano
Board: Arduino Nano (Maker Nano)
Connections:
Nano | Relay
GND – GND
5V – VCC
A0 – SIG
Nano | Keypad
11 – pin 1 (most left)
10 – pin 2
9 – pin 3
7 – pin 4
6 – pin 5
5 – pin 6
4 – pin 7
3 – pin 8
Nano | I2C LCD
GND – GND
5V – VCC
SDL – SDL
SCA – SCA
External libraries:
– Keypad by Mark Stanley V3.1.1 (Manager)
*/
#include <Keypad.h>
#define Password_Lenght 5 // Give enough room for 4 chars + NULL char
#define PIEZO 8
#define RELAY A0
#define NOTE_G5 784
#define NOTE_C6 1047
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 2);
int pos = 0; // variable to store the servo position
char Data[Password_Lenght];
char Master[Password_Lenght] = "5698";
byte data_count = 0, master_count = 0;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char keys [ROWS] [COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {6, 5, 4, 3};
byte colPins[COLS] = {11, 10, 9, 7};
Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int OpenMelody[] = {NOTE_G5, NOTE_C6};
int OpenNoteDurations[] = {12, 8};
int CloseMelody[] = {NOTE_C6, NOTE_G5};
int CloseNoteDurations[] = {12, 8};
#define playOpenMelody() playMelody(OpenMelody, OpenNoteDurations, 2)
#define playCloseMelody() playMelody(CloseMelody, CloseNoteDurations, 2)
char inChar;
String inString;
void setup() {
pinMode(PIEZO, OUTPUT);
pinMode(RELAY, OUTPUT);
digitalWrite(RELAY, HIGH);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.print(" ENTER PASSWORD");
}
void loop() {
customKey = myKeypad.getKey();
if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
{
tone(8, NOTE_G5, 100);
Data[data_count] = customKey; // store char into data array
data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
}
if (data_count == Password_Lenght – 1) // if the array index is equal to the number of expected chars, compare data to master
{
if (!strcmp(Data, Master)) // equal to (strcmp(Data, Master) == 0)
{
playOpenMelody();
digitalWrite(RELAY, LOW);
lcd.clear();
lcd.print(" DOOR OPEN");
delay(5000); //time for open the door
lcd.clear();
lcd.print(" DOOR LOCK");
digitalWrite(RELAY, HIGH);
playCloseMelody();
delay(1000);
lcd.clear();
lcd.print(" ENTER PASSWORD");
}
else
{
lcd.clear();
lcd.print(" WRONG PASSWORD");
delay (1000);
lcd.clear();
lcd.print(" ENTER PASSWORD");
playCloseMelody();
}
clearData();
}
}
void clearData()
{
while (data_count != 0)
{ // This can be used for any array size,
Data[data_count–] = 0; //clear array for new data
}
return;
}
void playMelody(int *melody, int *noteDurations, int notesLength)
{
pinMode(PIEZO, OUTPUT);
for (int thisNote = 0; thisNote < notesLength; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(PIEZO, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(PIEZO);
}
}

view raw
keypad_solenoid.ino
hosted with ❤ by GitHub

Reference

  1. Control Solenoid Door Lock using Relay on Arduino

Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.

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

Getting Started with Robotic Operating System (ROS) and JetRacer AI Kit
Barrier Gate with micro:bit and MakeCode
Play MP3 File on Maker Pi Pico Using CircuitPython
Remote Jetson Nano using SSH with Visual Studio Code
3.3V Serial LCD with Raspberry Pi Pico via SPI or I2C
Tutorials of Cytron Technologies Scroll to Top