• nithya7rns

Password Protected Security System project using Arduino, Keypad, Piezo Buzzer and LEDs on TinkerCAD

A #security system for devices now is not only a facility but a necessity. It helps us store data securely and according to our requirements. There are many methods of security and usually, for digital devices, it starts with a password.


We have security scanners at places, fingerprint print, and face recognition security to our devices. Before all that, let us first design a Password Protected Security System for a device using simple Electronic components in TinkerCad, a #simulation software.


Hardware Requirement


These components are not required while building it in the simulation software. To build the circuit manually, click on the links given below to buy the components required.

  1. Arduino UNO Board.

Develop a stronger concept in Arduino through this article:- What is Arduino?

Arduino UNO

#Arduino board is a microcontroller that is used to accept inputs from sensors connected and provide an output action on the desired device connected to it. The sensor inputs can be from light-detecting sensors, motion sensors (Ultrasonic or IR), temperature sensors, etc. The output from this device can be received through other output devices such as LED, Buzzer, Serial monitor, etc.

Buy Arduino UNO from here.


2. Resistors


1.5k Ohm Resistor

Resistors are passive devices that restrict the flow of current or divide the voltage through the circuit. The input power passes through these resistors and then to the sensors to avoid damage.


Buy Resistors from here.


3. Breadboard

Breadboard

The breadboard is the basic component of any circuit building process. All components, be it input sensors or output display devices are connected to the power supply, microcontroller using wired connections through a breadboard. The holes in the breadboard are in series. There are various sizes like full-sized, half-sized, and mini breadboard.

Buy breadboard from here.

4. LED


LED

Light Emitting Diode is a commonly used light source. It is a semiconductor that emits light when current flows through it.

Buy LED from here.

5. Piezo Buzzer

Piezo Buzzer

It is an electrical component that generates a beep sound on receiving an input. It works on the principle of #piezo crystal.

Buy Piezo buzzer from here.

6. Jumper Wires

Jumper Wires

These are the main components that are used to establish the connections between different devices of the circuit.

Buy Jumper Wires from here.


7. 4x4 Keypad


4x4 Keypad

A 4*4 matrix is used to insert input values into the project. This particular component has a total of 8 terminals, driven out from the 16 buttons present in the module.


Buy 4*4 Keypad from here.


NOTE: The description of the electrical components is given for reference. We don't need the physical components for this project. The circuit simulation is done in the TinkerCad software.


Software Requirement

TinkerCad circuit simulation software.

TinkerCad Logo

It is an online simulation software used for circuit design. It has all the electrical components required to built circuits and runs them.

Visit the TinkerCad website.


Circuit Connections


Circuit Diagram in TinkerCad window

The circuit connections are simple and are as follows.


The input device used here is the 4*4 #keypad. It has 8 terminals and here each terminal is connected to one digital pin of the Arduino board to allow Arduino to receive input from the keypad. Pressing of each key triggers a particular function of each of the 8 terminals and hence the input is received by the Arduino.


The #breadboard is going to house all the external connections done to the Arduino board. So the power supply line and Ground line are specified separately by making a connection from 5V and GND pins from the Arduino board respectively.


We will be using 2 two #LEDs along with a Piezo buzzer as output. One LED can be chosen RED and the other can be chosen GREEN. The Cathode of the LEDs is connected to the ground line through resistors and the Anode is connected to the digital pins of Arduino, D10, and D11 respectively.


The positive terminal of the Piezo #buzzer is connected to another digital pin of Arduino, say D12. The negative terminal of the buzzer is connected to the ground line on the breadboard.


Code

Now let us see the code for the device to work.

#include <Keypad.h>

This is the header file that is used to include #library functions associated with the working of the 4*4 keypad.

const byte row= 4;
const byte col= 4;
const int redLed= 10;
const int greenLed= 11;
const int piezo= 12;

The constant values are declared which are further going to be used throughout the code. Two constants of the type "byte" are declared for rows and columns of the Keypad. Three #integer constants are declared for the output devices used here.


One constant is declared for Red LED to which the value of the digital pin (10) to which it is connected to on Arduino is assigned. The second variable is declared to hold the value of the pin (11) connected to the Green LED. The third integer value holds the pin(12) to which the piezo buzzer is connected.

char numPad[row][col] = {
  {'1', '2', '3'},{'4', '5', '6'},
  {'7', '8', '9'},{'*', '0', '#'}
};

A Matrix by the name "numPad" is declared and defined that will represent the value of each key on the keypad.

byte rowPin[row] = {9, 8, 7, 6}; 
byte colPin[col] = {5, 4, 3, 2}; 

The two arrays of the type "byte" will contain the value of each row and column in the keypad. The declaration of the same is shown above.

String password = "6556";
String vstup = "";

Two strings are declared. The string "password" contains the original password and "vstup" will contain the input from the user which will further be checked with the original password based on the conditions.

Keypad cKeypad = Keypad(makeKeymap(numPad), rowPin, colPin, row, col); 

"Keypad" is the keyword accessible from the header file include above and is also an inbuilt function that will help define the work of each key according to the rows and columns.

void setup()
{
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(piezo, OUTPUT);

The setup( ) function is going to assign the pin modes and initialize the values to the external pins connected. As stated above, the LEDs and the piezo buzzer are #output devices. Hence using the pinMode( ) function it is declared as output.

digitalWrite(redLed,HIGH);
  Serial.begin(9600);
  Serial.print("Enter Passcode: ");
}

The red LED is set to glow at the beginning itself. So, using digitalWrite( ) function, the value is set to HIGH. The #Serial transmission begins, and the baud rate of 9600 is sent through the function Serial. begin( ). Using the function Serial. print( ), the message "Enter passcode:" is printed on the Serial monitor.

void loop()
{
  char cKey= cKeypad.getKey();

The loop( ) function is used to run the lines of the code repeatedly. First, a character "cKey" which is equated to the function getkey( ) to receive the input from the keypad.

if (cKey){
    if(vstup.length() < 4) {
      Serial.print("*");
      vstup += cKey;
    }
  }

If conditions are used in the loop function to continuously check the input character if they match with the password. This 'if' condition takes input from the keypad and if the length of the input is less than four, the output on the serial monitor is going to be #Asterisk symbols. This means the character input will not be shown until four characters are entered.


If a fifth character is entered, the asterisk symbol will not be the output and the respective characters will be shown also meaning that it is not the right password since we have declared a four-character password for our program code. If the original password is changed, then this "if" condition will depend on the length of that password.

if(vstup.length() == 4) {
    delay(1500);

Next, the function uses nested "if" conditions. First, it checks the length of the input password to be equal to 4. If it is equal to 4, there is a delay of 1.5 seconds.

    if(password == vstup) {
      Serial.println("\nEnter");
      digitalWrite(redLed,LOW);
      digitalWrite(greenLed,HIGH);  

After the first condition is true, the next condition checks if the input password is the same as the original password. If this condition turns true, the message "Enter" is printed on the Serial monitor. Then the Red LED is turned OFF and the Green LED is allowed to glow. This indicates that the password entered matches the correct password.

tone(piezo,500);
      delay(100);
      noTone(piezo);
    }

The function tone( ) is used which takes the input of the PIN value to which the Piezo buzzer is connected and the time for which the buzzer is sound. Here the buzzer tones for 0.5 seconds. A delay of 0.1 seconds is given and the buzzer goes OFF. This "if" condition ends here.

else {
      Serial.println("\nWrong Passcode");
      digitalWrite(redLed,HIGH);
      digitalWrite(greenLed,LOW);
      tone(piezo,1000);
      delay(800);
      tone(piezo,1000);
      delay(800);
      noTone(piezo);
    }

If the input password doesn't match the password entered, the program skips to this else condition. Here the message "Wrong passcode" is printed on the Serial monitor. The Red LED then goes HIGH (glows) and the Green LED goes LOW which indicates that the wrong password is entered.


The buzzer tones for a second, a delay of 0.8 seconds is given, and again the buzzer tones for another second, and then a delay of 0.8 seconds is given. Finally, the buzzer goes OFF and the else condition ends here.


Note that the delay given when the correct password is entered and when the wrong password is entered is different to indicate the same.

delay(1500);
     vstup = "";
     Serial.println("Enter Passcode: ");

After all the if-else conditions are checked, a delay of 1.5 seconds is given. The value containing the input password is initialized to an empty string and the message "Enter Passcode" is again printed on the Serial monitor. These lines of code run in a loop until the program exits.

 digitalWrite(redLed,HIGH);
 digitalWrite(greenLed,LOW);
  }
}

The Red LED glows and the Green LED is switched OFF. The else condition and the loop( ) function ends here.


COMPLETE CODE


#include <Keypad.h>

const byte row= 4;
const byte col= 4;
const int redLed= 10;
const int greenLed= 11;
const int piezo= 12;

char numPad[row][col] = {
  {'1', '2', '3'},{'4', '5', '6'},
  {'7', '8', '9'},{'*', '0', '#'}
};

byte rowPin[row] = {9, 8, 7, 6}; 
byte colPin[col] = {5, 4, 3, 2}; 

String password = "6556";
String vstup = "";

Keypad cKeypad = Keypad(makeKeymap(numPad), rowPin, colPin, row, col); 

void setup()
{
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(piezo, OUTPUT);
  digitalWrite(redLed,HIGH);
  Serial.begin(9600);
  Serial.print("Enter Passcode: ");
}

void loop()
{
  char cKey= cKeypad.getKey();
  
  if (cKey){
    if(vstup.length() < 4) {
      Serial.print("*");
      vstup += cKey;
    }
  }

  if(vstup.length() == 4) {
    delay(1500);
    if(password == vstup) {
      Serial.println("\nEnter");
      digitalWrite(redLed,LOW);
      digitalWrite(greenLed,HIGH);
      tone(piezo,500);
      delay(100);
      noTone(piezo);
    } else {
      Serial.println("\nWrong Passcode");
      digitalWrite(redLed,HIGH);
      digitalWrite(greenLed,LOW);
      tone(piezo,1000);
      delay(800);
      tone(piezo,1000);
      delay(800);
      noTone(piezo);
    }
     delay(1500);
     vstup = "";
     Serial.println("Enter Passcode: ");
     digitalWrite(redLed,HIGH);
     digitalWrite(greenLed,LOW);
  }
}

NOTE: The default code present in the TinkerCad window needs to be removed and the program code needs to be written. Download the document and copy-paste the code in Tinkercad to simulate the circuit.


Code for Password Protected Door Lock
.tx
Download TX • 1KB

Working


Circuit connections with Output

Let us first learn how to work on TinkerCad #simulation software. Once on the TinkerCad page, select circuits, and search for the components required. The components are to be dragged and brought to the circuiting screen. The connection needs to be made by selecting the jumper wires. Corresponding colors for the wires can be selected.

Learn more about TinkerCad in detail.


When the input is given from the keypad, the characters/numbers are recognized and the values are taken as input. These inputs are given as digital inputs to Arduino. Based on the conditions in the code, the password is checked.


When the password is entered and if it is less than the length of the original password, the asterisk symbols are printed for security purposes. If the length exceeds the length of the original password, the characters are printed and then the message that the wrong password is entered is printed on the Serial monitor.


The Red LED glows and the buzzer tones for a small amount of time and goes OFF. The code again asks to enter the password. When the entered password matches to be the correct one, the Green LED glows and the buzzer tones for a little longer to indicate that the password is correct.


Watch the below-given project video for the practical explanation of designing the circuit and to know how the simulation #software works.


Project Video By - Navya Tatiparth

Simulation software plays a major role in the building of large circuits as they help analyze the working of the circuit before it can be built practically. It helps us create a #virtual design of the circuit we want to build and avoid damages to the circuit if in case we don't know, beforehand about the correct circuit connections.

For more projects through TinkerCad click here.


Simulation software can help us build more effective and efficient projects as it provides #validation for the circuit we will be building using the actual components. #Design your own circuit, run the code in the software, and validate your project.


SEE ALSO:

  • Facebook
  • YouTube
  • Instagram
  • LinkedIn
LearnElectronics
Contact Us
© Copyright - LearnElectronics 2020.