Introduction :
A combination lock is a type of locking device in which a sequence of symbols, usually numbers, is used to open the lock. The sequence may be entered using a single rotating dial which interacts with several discs or cams, by using a set of several rotating discs with inscribed symbols which directly interact with the locking mechanism, or through an electronic or mechanical keypad. Here we will be using arduino uno along with em lock to make door lock with password.
Code of the project :-
const int buttonPin1 = 1;
const int buttonPin4 = 4;
const int buttonPin3 = 3;
const int buttonPin2 = 2; // the pin that the pushbutton is attached to
const int correctLedPin = 7; // the pin that the LED is attached to
const int wrongLedPin = 6;
const int motorPin = 11;// the pin that the LED is attached to
// variables that are changed by the program
int buttonPushCounter = 0; // counter for the number of button presses
int val = 0;
int bS1 = 0; // current state of the button
int lBS1 = 0; // previous state of the button
int bS2 = 0; // current state of the button
int lBS2 = 0;
int bS3 = 0; // current state of the button
int lBS3 = 0;
int bS4 = 0; // current state of the button
int lBS4 = 0;
// configure the pins to the right mode
void setup() {
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(correctLedPin, OUTPUT);
pinMode(wrongLedPin, OUTPUT);
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
}
// the main loop will constantly check to see if the button has been pressed
// if it has, a counter is incremented, and then some action can be taken
void loop() {
// read the state of the button
static int buttonPushCounter = 0;
bS1 = digitalRead(buttonPin1);
bS2 = digitalRead(buttonPin2);
bS3 = digitalRead(buttonPin3);
bS4 = digitalRead(buttonPin4);
// check to see if it different than the last time we checked
if (bS1 != lBS1) {
// either the button was just pressed or just released
if (bS1 == HIGH) {
// it was just pressed
buttonPushCounter = buttonPushCounter + 1;
Serial.println(buttonPushCounter);
digitalWrite(correctLedPin, HIGH);
delay(100);
digitalWrite(correctLedPin, LOW);
if(val == 0)
{
val = 1;
}
}
}
lBS1 = bS1;
if (bS2 != lBS2) {
// either the button was just pressed or just released
if (bS2 == HIGH) {
// it was just pressed
buttonPushCounter = buttonPushCounter + 1;
Serial.println(buttonPushCounter);
digitalWrite(correctLedPin, HIGH);
delay(100);
digitalWrite(correctLedPin, LOW);
if(val == 1)
{
val = 2;
}
}
}
lBS2 = bS2;
if (bS3 != lBS3) {
// either the button was just pressed or just released
if (bS3 == HIGH) {
// it was just pressed
buttonPushCounter = buttonPushCounter + 1;
Serial.println(buttonPushCounter);
digitalWrite(correctLedPin, HIGH);
delay(100);
digitalWrite(correctLedPin, LOW);
if(val == 2)
{
val = 3;
}
}
}
lBS3 = bS3;
if (bS4 != lBS4) {
// either the button was just pressed or just released
if (bS4 == HIGH) {
// it was just pressed
buttonPushCounter = buttonPushCounter + 1;
Serial.println(buttonPushCounter);
digitalWrite(correctLedPin, HIGH);
delay(100);
digitalWrite(correctLedPin, LOW);
if(val == 3)
{
val = 4;
}
}
}
lBS4 = bS4;
if(val == 4 && buttonPushCounter == 4)
{
digitalWrite(correctLedPin, HIGH);
val = 0;
buttonPushCounter = 0;
analogWrite(motorPin
}
else if(val != 4 && buttonPushCounter == 4)
{
digitalWrite(wrongLedPin, HIGH);
delay(3000);
digitalWrite(wrongLedPin, LOW);
val = 0;
buttonPushCounter = 0;
}
}
Connections of the project :-
one wire from 12 +ive supply supply to relay com terminal and connect one wire from NC terminal of relay to em lock. Connect the -ive of 12v supply directly to -ive of the em lock.
connect the input/signal of relay to pin 13 on arduino and vcc to 5v and gnd to gnd on arduino.
Along with this connect the four switches to the arduino as follows :
Connect the pins of switches to pin digital pin 1,2,3 and 4.
Fingerprint Lock
ReplyDeleteWe are leading the best Smart Lock provider in Singapore with the lowest price. Click here to see all of our exclusive deals
on trending HOZ Digital Lock
how would you connect a servo to it?? (help)
ReplyDelete