0% found this document useful (0 votes)
55 views11 pages

Code NG Security Box

This document contains code for an Arduino-powered security box with a keypad and LCD screen. The code defines variables and arrays to store the user state, password attempts, and input values. It includes functions for initializing components, receiving input, validating passwords, displaying menus and messages, and controlling a servo motor to lock/unlock the box. The main loop runs through a state machine to process input and transition between authentication, menu, and access control states.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views11 pages

Code NG Security Box

This document contains code for an Arduino-powered security box with a keypad and LCD screen. The code defines variables and arrays to store the user state, password attempts, and input values. It includes functions for initializing components, receiving input, validating passwords, displaying menus and messages, and controlling a servo motor to lock/unlock the box. The main loop runs through a state machine to process input and transition between authentication, menu, and access control states.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

GIZDUINO SECURITY BOX - CODE

#include <Servo.h>
Servo servo;

#include <Keypad.h>

int tries = 0;
#include <LiquidCrystal.h>

int programstate = 1;

LiquidCrystal lcd(14, 15, 16, 17, 18,


19);

int passwordstate;

const byte myRows = 4;


const byte myCols = 3;
char keys[myRows][myCols] = {

int arrayreset;
char inputArray[4];
char resetarray[4];
char Main[4] = {

{
'1', '2', '3'
}
,

'5', '6', '7', '8'};

char Open[1] = {
'4', '5', '6'

'1'};
char Lock[1] = {

'1'};

char Reset[1] = {
'7', '8', '9'

'3'};

{
'*', '0', '#'
}

char Exit[1] = {
'4'};

};

char Adminc[1] = {
'1'};

byte rowPins[myRows] = {
7, 6, 5, 4};

int input = 0;
int colcounter = 6;

int adminmenuquestion;
int guessmenuquestion;
int askcodequestion;
int closetheboxquestion;
int palitcodequestion;
int
pilikakungadminoguessquestion;

'2'};
char Change[1] = {

int beep;

'1', '2', '3', '4'};


char Guest[4] = {

int userstate = 0;

char Guestc[1] = {
'2'};

byte colPins[myCols] = {

char x1;
char x2;
char x3;
char x4;
char x5;
char x6;
char x7;
char x8;
char key;

10, 9, 8 };
void setup() {

const int backlight = 2;

lcd.begin(16, 2);

const int resetcon = 3;

Serial.begin(9600);
pinMode(resetcon,OUTPUT);

const int buzzer = 12;

Page

Keypad kpd = Keypad(


makeKeymap(keys), rowPins,
colPins, myRows, myCols );

GIZDUINO SECURITY BOX - CODE


digitalWrite(resetcon,HIGH);

servo.attach(11);
x1 = x1;
x2 = x2;
x3 = x3;
x4 = x4;
x5 = x5;
x6 = x6;
x7 = x7;
x8 = x8;
passwordstate = passwordstate;
userstate = userstate;
beep = beep;
}

break;
case 3:

if (tries==3){
programstate = 11;

break;

if (arrayreset == 1) {
defaultarray();
arrayreset = 0;
}
switch (programstate) {
case 1:

break;
case 13:

case 4:
menunimadam();

tanongmokaykuyajobertangbagon
gguesspassword();

break;
case 5:

break;
case 14:

menuniinday();

palitpasswordguesste();

break;
case 6:

break;
case 15:

openkonaitey();

pilikakungadminoguess();

break;

tanongmokaykuyajobertkungsasar
a();
break;
case 8:

tanongmokaykuyajobertangbagon
gadminpassword();

tignankokungmahaba();

case 7:

void loop() {

case 12:

break;
default:
butascode();
}
switch (beep){
case 1:

closekonaitey();

tamacodebeep();

break;

break;

case 9:

case 2:

palitpasswordadminte();

malicodebeep();

break;

break;

case 10:

case 3:

ulitdaw();
tanongmokaykuyajobertangpassw
ord();
break;
case 2:

break;

dutdotbeep();
default:

case 11:
malika();

tahimikka();
}

pinMode(backlight,OUTPUT);

tanongmokaykuyajobertangmgab
agongpassword();

Page

pinMode(buzzer, OUTPUT);

break;

GIZDUINO SECURITY BOX - CODE


Serial.print("passwordstate");

lcd.clear();

inputArray[1] == Main[1] &&

Serial.println(passwordstate);

lcd.home();

inputArray[2] == Main[2] &&

Serial.print("userstate");

lcd.print("TYPE LOCK CODE");

inputArray[3] == Main[3]) {

Serial.println(userstate);

askcodequestion = 1;

arrayreset = 1;

Serial.print("tries");

userstate = 0;

colcounter=6;

Serial.println(tries);

userstate = 1;

Serial.print("input");

key = kpd.getKey();

input = 0;

Serial.println(input);

if (key){

programstate = 3;

beep = 3;

inputArray[input] = key;

if (inputArray[0] == Guest[0] &&

void butascode(){

input++;

inputArray[1] == Guest[1] &&

Serial.println("BUTAS ANG
CODE!");

lcd.setCursor(colcounter,1);

inputArray[2] == Guest[2] &&

lcd.print(key);

inputArray[3] == Guest[3]) {

colcounter++;

arrayreset = 1;

if (key == '*') {

colcounter=6;

lcd.clear();

userstate = 2;

lcd.home();

input = 0;

lcd.print("TYPE LOCK CODE");

programstate = 3;

lcd.clear();
lcd.home();
lcd.print("BUTAS ANG CODE");
}

void defaultarray(){
inputArray[0] = resetarray[0];
inputArray[1] = resetarray[1];
inputArray[2] = resetarray[2];

colcounter=6;

input = 0;

arrayreset = 1;

colcounter=6;

if (key == '#') {

input = 0;

inputArray[3] = resetarray[3];
}

lcd.clear();

askcodequestion = 0;

lcd.home();

programstate = 3;

lcd.print("TYPE LOCK CODE");


void
tanongmokaykuyajobertangpassw
ord(){

colcounter=6;

if(askcodequestion == 0){

}
if (input == 4) {
if (inputArray[0] == Main[0] &&

void
tanongmokaykuyajobertangbagon
gadminpassword(){
if(askcodequestion == 0){
lcd.clear();

Page

input = 0;

if (passwordstate==1){
programstate = 2;

GIZDUINO SECURITY BOX - CODE


lcd.home();

inputArray[3] == x4) {

askcodequestion = 1;

lcd.print("TYPE LOCK CODE");

arrayreset = 1;

askcodequestion = 1;

colcounter=6;

key = kpd.getKey();

userstate = 1;

if (key){

key = kpd.getKey();

input = 0;

beep = 3;

if (key){

programstate = 3;

inputArray[input] = key;

beep = 3;

input++;

inputArray[input] = key;

if (inputArray[0] == Guest[0] &&

lcd.setCursor(colcounter,1);

input++;

inputArray[1] == Guest[1] &&

lcd.print(key);

lcd.setCursor(colcounter,1);

inputArray[2] == Guest[2] &&

colcounter++;

lcd.print(key);

inputArray[3] == Guest[3]) {

if (key == '*') {

colcounter++;

arrayreset = 1;

lcd.clear();

if (key == '*') {

colcounter=6;

lcd.home();

lcd.clear();

userstate = 2;

lcd.print("TYPE LOCK CODE");

lcd.home();

input = 0;

colcounter=6;

lcd.print("TYPE LOCK CODE");

programstate = 3;

input = 0;

colcounter=6;

input = 0;

arrayreset = 1;

if (key == '#') {

colcounter=6;

lcd.clear();

if (key == '#') {

input = 0;

lcd.home();

lcd.clear();

askcodequestion = 0;

lcd.print("TYPE LOCK CODE");

lcd.home();

programstate = 3;

colcounter=6;

lcd.print("TYPE LOCK CODE");

input = 0;

}
void
tanongmokaykuyajobertangbagon
gguesspassword(){

}
if (input == 4) {
if (inputArray[0] == x1 &&
inputArray[1] == x2 &&
inputArray[2] == x3 &&

if(askcodequestion == 0){
lcd.clear();
lcd.home();
lcd.print("TYPE LOCK CODE");

if (input == 4) {
if (inputArray[0] == Main[0] &&
inputArray[1] == Main[1] &&
inputArray[2] == Main[2] &&
inputArray[3] == Main[3]) {
arrayreset = 1;

input = 0;

Page

colcounter=6;

GIZDUINO SECURITY BOX - CODE


colcounter=6;

key = kpd.getKey();

input = 0;

userstate = 1;

if (key){

programstate = 3;

input = 0;

beep = 3;

programstate = 3;

inputArray[input] = key;

if (inputArray[0] == x5 &&

input++;

inputArray[1] == x6 &&

if (inputArray[0] == x5 &&

lcd.setCursor(colcounter,1);

inputArray[2] == x7 &&

inputArray[1] == x6 &&

lcd.print(key);

inputArray[3] == x8) {

inputArray[2] == x7 &&

colcounter++;

arrayreset = 1;

inputArray[3] == x8) {

if (key == '*') {

colcounter=6;

arrayreset = 1;

lcd.clear();

userstate = 2;

colcounter=6;

lcd.home();

input = 0;

userstate = 2;

lcd.print("TYPE LOCK CODE");

programstate = 3;

input = 0;

colcounter=6;

programstate = 3;

input = 0;

arrayreset = 1;

colcounter=6;

arrayreset = 1;

if (key == '#') {

input = 0;

colcounter=6;

lcd.clear();

askcodequestion = 0;

input = 0;

lcd.home();

programstate = 3;

askcodequestion = 0;

lcd.print("TYPE LOCK CODE");

programstate = 3;

colcounter=6;

input = 0;
}

void tignankokungmahaba(){

void
tanongmokaykuyajobertangmgab
agongpassword(){
if(askcodequestion == 0){
lcd.clear();
lcd.home();
lcd.print("TYPE LOCK CODE");
askcodequestion = 1;

if (userstate == 0){

if (input == 4) {
if (inputArray[0] == x1 &&
inputArray[1] == x2 &&
inputArray[2] == x3 &&
inputArray[3] == x4) {
arrayreset = 1;
colcounter=6;
userstate = 1;

lcd.clear();
lcd.print("WRONG
PASSWORD");
delay(1000);
beep = 2;
if (passwordstate==0){
tries = tries+1;
programstate = 1;

Page

GIZDUINO SECURITY BOX - CODE


}

tries = 0;

lcd.setCursor(9,1);

if (passwordstate==1){

programstate = 5;

lcd.print("09 sec");

tries = tries+1;
programstate = 12;

delay(1000);

lcd.setCursor(9,1);
lcd.print("08 sec");

tries = tries+1;

void menunimadam(){
if(adminmenuquestion == 0){

programstate = 13;

delay(1000);
lcd.setCursor(9,1);

lcd.clear();

lcd.print("07 sec");

lcd.home();

delay(1000);

if (passwordstate==3){

lcd.print("MENU:1-OPEN 2-RS");

lcd.setCursor(9,1);

tries = tries+1;

lcd.setCursor(0,1);

lcd.print("06 sec");

programstate = 2;

lcd.print("3-CHANGE 4-EXIT");

delay(1000);

adminmenuquestion = 1;

lcd.setCursor(9,1);

}
}

lcd.print("05 sec");

if (userstate == 1){

key = kpd.getKey();

delay(1000);

if (key){

lcd.setCursor(9,1);

lcd.clear();
lcd.print("CORRECT CODE!");

beep = 3;

lcd.print("04 sec");

lcd.setCursor(0,1);

inputArray[input] = key;

delay(1000);

lcd.print("ADMIN ACCT.");

input++;

lcd.setCursor(9,1);

delay(1000);

if (input == 1) {

lcd.print("03 sec");

beep = 1;

if (inputArray[0] == Open[0]) {

tries = 0;
programstate = 4;
}
if (userstate == 2){

programstate = 6;

delay(1000);
lcd.setCursor(9,1);

lcd.print("02 sec");

if (inputArray[0] == Reset[0]) {

delay(1000);

lcd.clear();

lcd.setCursor(9,1);

lcd.clear();

lcd.print("The Box will");

lcd.print("01 sec");

lcd.print("CORRECT CODE!");

lcd.setCursor(0,1);

delay(1000);

lcd.setCursor(0,1);

lcd.print("reset in");

lcd.setCursor(9,1);

lcd.print("GUESS ACCT.");

lcd.setCursor(9,1);

lcd.print("00 sec");

delay(1000);

lcd.print("10 sec");

passwordstate = 0;

beep = 1;

delay(1000);

userstate = 0;

if (passwordstate==2){

Page

GIZDUINO SECURITY BOX - CODE


arrayreset = 1;

void openkonaitey(){

void closekonaitey(){

programstate = 1;

if (inputArray[0] == Change[0])
{
programstate = 15;
}

servo.write(10);

servo.write(110);

lcd.clear();

userstate = 0;

lcd.home();

if (passwordstate == 0){

lcd.print("UNLOCKED");

if (inputArray[0] == Exit[0]) {

programstate = 7;

if (passwordstate == 1){

if (passwordstate == 0){
programstate = 1;
}
if (passwordstate == 1){
programstate = 12;

programstate = 12;
void
tanongmokaykuyajobertkungsasar
a(){

}
if (passwordstate == 2){
programstate = 13;

if(closetheboxquestion == 0){
}

lcd.clear();

if (passwordstate == 3){

lcd.home();

if (passwordstate == 2){

programstate = 2;

lcd.print("MENU:1-LOCK");

programstate = 13;

closetheboxquestion = 1;

}
if (passwordstate == 3){
programstate = 2;
}

}
key = kpd.getKey();
if (key){
beep = 3;

void palitpasswordadminte(){
if (palitcodequestion == 0) {
lcd.clear();

inputArray[input] = key;

lcd.home();

input++;

input = 0;

lcd.print("TYPE NEW CODE");

if (input == 1) {

adminmenuquestion = 0;

palitcodequestion = 1;

if (inputArray[0] == Lock[0]) {

programstate = 8;

}
}

input = 0;

void menuniinday(){

closetheboxquestion = 0;

servo.write(10);
}

programstate = 7;
}

}
char key = kpd.getKey();
if (key) {
beep=3;
inputArray[input] = key;
input++;

userstate = 0;

programstate = 1;

Page

GIZDUINO SECURITY BOX - CODE


lcd.setCursor(colcounter,1);

lcd.print(x1);

if (palitcodequestion == 0) {

lcd.print(key);

lcd.setCursor(7,1);

lcd.clear();

colcounter++;

lcd.print(x2);

lcd.home();

if (key == '*') {

lcd.setCursor(8,1);

lcd.print("TYPE NEW CODE");

lcd.clear();

lcd.print(x3);

palitcodequestion = 1;

lcd.home();

lcd.setCursor(9,1);

lcd.print("TYPE NEW CODE");

lcd.print(x4);

char key = kpd.getKey();

lcd.setCursor(colcounter,1);

delay(1000);

if (key) {

colcounter=6;

lcd.clear();

beep=3;

input = 0;

lcd.home();

inputArray[input] = key;

arrayreset = 1;

lcd.print("SUCCESS CHANGE");

input++;

lcd.setCursor(0,1);

lcd.setCursor(colcounter,1);

if (key == '#') {

lcd.print("OF CODE");

lcd.print(key);

lcd.clear();

delay(1000);

colcounter++;

lcd.home();

input = 0;

if (key == '*') {

lcd.print("TYPE NEW CODE");

palitcodequestion = 0;

lcd.clear();

lcd.setCursor(colcounter,1);

if (passwordstate==0){

lcd.home();

colcounter=6;

passwordstate = 1;

lcd.print("TYPE NEW CODE");

input = 0;

userstate = 0;

lcd.setCursor(colcounter,1);

arrayreset = 1;

programstate = 12;

colcounter=6;

input = 0;

if (input == 4) {

if (passwordstate==2){

arrayreset = 1;

x1 = inputArray[0];

passwordstate = 3;

x2 = inputArray[1];

userstate = 0;

if (key == '#') {

x3 = inputArray[2];

programstate = 2;

colcounter=6;

lcd.clear();
lcd.home();

}
}

lcd.print("TYPE NEW CODE");


lcd.setCursor(6,1);

lcd.home();
lcd.print("TYPE NEW CODE");
lcd.setCursor(colcounter,1);
colcounter=6;
input = 0;

void palitpasswordguesste(){

arrayreset = 1;

Page

x4 = inputArray[3];

lcd.clear();

GIZDUINO SECURITY BOX - CODE


}

delay(500);

if (input == 4) {

if (passwordstate==1){

digitalWrite(buzzer, LOW);

x5 = inputArray[0];

passwordstate = 3;

delay(500);

x6 = inputArray[1];

userstate = 0;

digitalWrite(buzzer, HIGH);

x7 = inputArray[2];

programstate = 2;

delay(500);

x8 = inputArray[3];

colcounter=6;

lcd.clear();
lcd.home();

digitalWrite(buzzer, LOW);
delay(500);

beep = 0;

void ulitdaw(){

void dutdotbeep(){

lcd.print("TYPE NEW CODE");

lcd.print(x5);

digitalWrite(buzzer, HIGH);

delay(10);

lcd.print(x6);
lcd.setCursor(8,1);

digitalWrite(buzzer, LOW);
void tamacodebeep(){

lcd.print(x7);

digitalWrite(buzzer, HIGH);

lcd.setCursor(9,1);

delay(50);

lcd.print(x8);

digitalWrite(buzzer, LOW);

delay(1000);

delay(50);

lcd.clear();

digitalWrite(buzzer, HIGH);

lcd.home();

delay(100);

lcd.print("SUCCESS CHANGE");

digitalWrite(buzzer, LOW);

lcd.setCursor(0,1);

beep = 0;

lcd.print("OF CODE");

void tahimikka(){
digitalWrite(buzzer, LOW);
}

void malika(){
beep = 3;
lcd.clear();

delay(1000);
input = 0;

beep = 0;

lcd.home();
void malicodebeep(){

lcd.print("WRONG PASSWORD");

palitcodequestion = 0;

digitalWrite(buzzer, HIGH);

lcd.setCursor(0,1);

if (passwordstate==0){

delay(500);

beep = 3;

passwordstate = 2;

digitalWrite(buzzer, LOW);

lcd.print("Wait for 5min");

userstate = 0;

delay(500);

delay(60000);

programstate = 13;

digitalWrite(buzzer, HIGH);

lcd.setCursor(0,1);

lcd.setCursor(7,1);

digitalWrite(resetcon,LOW);

Page

lcd.setCursor(6,1);

GIZDUINO SECURITY BOX - CODE


beep = 3;

lcd.print("Wait for 08sec");

lcd.print("Wait for 4min");

delay(1000);

if (passwordstate==0){

delay(60000);

lcd.setCursor(0,1);

programstate = 1;

lcd.setCursor(0,1);

lcd.print("Wait for 07sec");

tries = 0;

beep = 3;

delay(1000);

lcd.print("Wait for 3min");

lcd.setCursor(0,1);

if (passwordstate==1){

delay(60000);

lcd.print("Wait for 06sec");

programstate = 12;

lcd.setCursor(0,1);

delay(1000);

tries = 0;

beep = 3;

lcd.setCursor(0,1);

lcd.print("Wait for 2min");

lcd.print("Wait for 05sec");

if (passwordstate==2){

delay(60000);

delay(1000);

programstate = 13;

lcd.setCursor(0,1);

lcd.setCursor(0,1);

tries = 0;

beep = 3;

lcd.print("Wait for 04sec");

lcd.print("Wait for 1min");

delay(1000);

if (passwordstate==3){

delay(30000);

lcd.setCursor(0,1);

programstate = 2;

lcd.setCursor(0,1);

lcd.print("Wait for 03sec");

tries = 0;

beep = 3;

delay(1000);

lcd.print("Wait for 30sec");

lcd.setCursor(0,1);

delay(10000);

lcd.print("Wait for 02sec");

lcd.setCursor(0,1);

delay(1000);

beep = 3;

lcd.setCursor(0,1);

lcd.print("Wait for 20sec");

lcd.print("Wait for 01sec");

delay(10000);

beep = 3;

lcd.setCursor(0,1);

delay(1000);

beep = 3;

if (passwordstate==0){

delay(1000);

tries = 0;

lcd.setCursor(0,1);

lcd.print("Wait for 09sec");

if (passwordstate==1){

void pilikakungadminoguess(){
if(pilikakungadminoguessquestion
== 0){
lcd.clear();
lcd.home();
lcd.print("1-ADMIN ACCT.");
lcd.setCursor(0,1);
lcd.print("2-GUESS ACCT.");
pilikakungadminoguessquestion
= 1;

delay(1000);

programstate = 2;

lcd.setCursor(0,1);

tries = 0;

key = kpd.getKey();

10

programstate = 1;

Page

lcd.print("Wait for 10sec");

GIZDUINO SECURITY BOX - CODE


if (key){
beep = 3;
inputArray[input] = key;
input++;
if (input == 1) {
if (inputArray[0] == Adminc[0])
{
programstate = 9;
}
if (inputArray[0] == Guestc[0]) {
programstate = 14;
}
}
input = 0;
arrayreset = 1;
pilikakungadminoguessquestion
= 0;
}

Page

11

You might also like