ARDUINO WITH KEYPAD

In this tutorial you will get to know that how you can use keypad with ardunio to create
security system with arduino and keypad.




Material required
Arduino
Keypad
Green LED
Red LED
Resistor (470 ohm)
BREADBOARD
Jumper wires


Connections
  • Connect Arduino 2-9 pins to KEYPAD
  • Connect Arduino pin 12 to +ve of green LED
  • Connect Arduino pin 11 to +ve of red LED
  • Connect Arduino GND pin to -ve of both LED's


CODE OF THE PROJECT :-

#include <Keypad.h>
 int green=11;
 int red=12;
 String password="2004";
 String tempPassword="";
 const byte ROWS = 4;
 const byteCOLS =4;
 char keypressed;
 char keyMap[ROWS][COLS] = {
 {'1','2','3','A'},
 {'4','5','6','B'},
 {'7','8','9','C'},
 {'*','0','#','D'} 
 };

 byte rowPins[ROWS] = {2, 3, 4, 5};
 byte colPins[COLS] = {6, 7, 8, 9};
 Keypad myKeypad = Keypad( makeKeymap(keymap), rowPins,colPins,ROWS,COLS)

 void setup()
 {
  pinMode(green,OUTPUT);
  pinMode(red,OUTPUT);
  
 }
void loop()
{
  keypressed = myKeypad.getKey();
  if(keypressed)

 if (keypressed != NO_KEY)
 {
  if (keypressed== '0' || keypressed == '1' || keypressed == '2' ||keypressed == '3' ||
      keypressed== '4' || keypressed == '5' || keypressed == '6' ||keypressed == '7' ||
      keypressed== '8' || keypressed == '9' )

{
  tempPassword += keypressed;
}
if(keypressed == '*')
{
  if(tempPassword == password)
  digitalWrite(green,HIGH);
  else
  digitalWrite(red,HIGH);
}

if( keypressed == '#')
{


    tempPassword="";
    digitalWrite(green,LOW);
    digitalWrite(red,LOW);
}
}

}

Popular posts from this blog

ARDUINO WITH PCA9685