Skip to main content

Lock using 4 Push button switch with arduino



Introduction :

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.


Comments

  1. Fingerprint Lock
    We 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

    ReplyDelete
  2. how would you connect a servo to it?? (help)

    ReplyDelete

Post a Comment

Popular posts from this blog

Voice Recording Module ISD1820 with Arduino

1 Introduction  Voice Record Module is base on ISD1820, which a multiple‐message record/playback device. It can offers true single‐chip voice recording, no‐volatile storage, and playback capability for 8 to 20 seconds. The sample is 3.2k and the total 20s for the Recorder. This module use is very easy which you could direct control by push button on board or by Microcontroller such as Arduino, STM32, ChipKit etc. Frome these, you can easy control record , playback and repeat and so on. 2 Feature  - Push‐button interface, playback can be edge or level activated - Automatic power‐dwon mode - On‐chip 8Ω speaker driver - Signal 3V Power Supply - Can be controlled both manually or by MCU - Sample rate and duration changable by replacing a single resistor - Record up to 20 seconds of audio - Dimensions: 37 x 54 mm If you want change record duration, an external resistor is necessary to select the record duration and sampling frequency, which can range from ...

Home Automation Using Arduino (Relay Module)

Inroduction to Home Automation Home automation  or  domotics  is  building automation  for a home, called a  smart home  or  smart house . It involves the control and automation of lighting, heating (such as  smart thermostats ), ventilation, air conditioning ( HVAC ), and security, as well as  home appliances  such as washer/dryers, ovens or refrigerators/freezers.  Wi-Fi  is often used for remote monitoring and control. Home devices, when remotely monitored and controlled via the Internet, are an important constituent of the  Internet of Things . Modern systems generally consist of switches and sensors connected to a central hub sometimes called a "gateway" from which the system is controlled with a  user interface that is interacted either with a wall-mounted terminal, mobile phone software,  tablet computer  or a web interface, often but not always via Internet cloud services.     ...