Advanced Arduino project: Security terminal

Arduino_keypad_project

Here is another useful Arduino project. We will build a terminal which opens when you enter right security code. You will have to enter the right password into keypad and the green led will activate. If the code is wrong, then Arduino will activate red LED. After the project is finished, we can upgrade it and program the Arduino to open electronic lock or something similar.

For this project, we wil need a few things. First we will need Arduino board or some clone (that is why is called Arduino project :) ). We will also need red 5mm LED, green 5mm LED, two 270ohm 0.5W metal film resistor and 0.1 inch header strip and keypad. We will create this project on breadboard so we’ll need that as well.

All these electronic components you can find at electronickits.com, or your local electronic parts dealer.

If you understand how the keypad works, you won’t have the problem creating the schematics by yourself. Keypads are usually arranged in a grid so when we press one of the keys, it connects a row and column. The switches are placed at the intersection of row and column wires. With this system, we only need to use 7 digital pins instead of twelve (1 for each key).

Arduino Keypad SChematics

Because of this keypad system, we will have a bit more work on coding. Don’t worry, we will show you the codeing part, you can even download some library from the person who created operating keypad for Arduino.

here is the code:

#include <Keypad.h>
char* secretCode = “1234″;
int position = 0;
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
{’1′,’2′,’3′},
{’4′,’5′,’6′},
{’7′,’8′,’9′},
{‘*’,’0′,’#'}
};
byte rowPins[rows] = {2, 7, 6, 4};
byte colPins[cols] = {3, 1, 5};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
int redPin = 9;
int greenPin = 8;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
setLocked(true);
}
void loop()
{
char key = keypad.getKey();
if (key == ‘*’ || key == ‘#’)
{
position = 0;
setLocked(true);
}
if (key == secretCode[position])
{
position ++;
}
if (position == 4)
{
setLocked(false);
}
delay(100);
}
void setLocked(int locked);

{
if (locked)
{
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
}
else
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
}
}

This code is not very complicated. The loop checks which key is pressed. If we press # or *, loop will set the variable to zero. If we press any other key (any of the numbers), it will check did we pressed expected key and move the loop to the next one. Program will operate that way for all chars. If the code is right, Arduino will turn on the green LED, and if not, red LED will be on.

We did not mention, in the beginning of the program you define your secret code which Arduino compares to the one you enter when testing the project. And we finished another Arduino project. Thanks for staying with us!

ElectronicKits.com
Responses are currently closed, but you can trackback from your own site.

Comments are closed.