0% found this document useful (0 votes)
17 views3 pages

Security Access System

Security Access System

Uploaded by

marcbrown1009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Security Access System

Security Access System

Uploaded by

marcbrown1009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <LiquidCrystal.

h>

// Initialize the LiquidCrystal library with the LCD pins


LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // RS, E, D4, D5, D6, D7

// Define pins for LEDs


const int greenLedPin = A3;
const int yellowLedPin = A4;
const int redLedPin = A5;

// Define pins for buttons


const int buttonAPin = 2;
const int buttonBPin = 3;
const int buttonCPin = 4;
const int buttonDPin = 5;

// Code sequence to disarm the alarm (press 'A' four times)


const char disarmCode[] = "AAAA";
const int disarmCodeLength = 4;
int disarmCodeIndex = 0;

// Countdown timer variables


unsigned long previousMillis = 0;
const long interval = 1000; // 1 second
int seconds = 15; // Change to 15 seconds
boolean alarmActive = true;

// Delay between button 'A' presses


unsigned long buttonDelayMillis = 500; // Adjust as needed

void setup() {
// Initialize the LCD with 16 columns and 2 rows
lcd.begin(16, 2);

// Display initial time on the LCD


lcd.print("TIME: 15");

// Set the pinMode for LEDs and buttons


pinMode(greenLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
pinMode(buttonAPin, INPUT_PULLUP);
pinMode(buttonBPin, INPUT_PULLUP);
pinMode(buttonCPin, INPUT_PULLUP);
pinMode(buttonDPin, INPUT_PULLUP);
}

void loop() {
// Check for button presses
if (digitalRead(buttonAPin) == LOW) {
checkButton('A');
}
if (digitalRead(buttonBPin) == LOW) {
checkButton('B');
}
if (digitalRead(buttonCPin) == LOW) {
checkButton('C');
}
if (digitalRead(buttonDPin) == LOW) {
checkButton('D');
}

// Update the countdown timer


unsigned long currentMillis = millis();
if (alarmActive && currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
seconds--;

// Check if seconds is negative


if (seconds < 0) {
// Timer expired, activate red LED and display "DENIED"
alarmActive = false;
digitalWrite(redLedPin, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Access DENIED");
delay(2000); // Display "Access DENIED" for 2 seconds
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TIME: 15"); // Reset timer to 15 seconds
seconds = 15;
disarmCodeIndex = 0; // Reset code input
}
}

// Display countdown and code on LCD


lcd.setCursor(6, 0);
lcd.print(seconds < 10 ? " " : ""); // Add a leading space if seconds is single-
digit
lcd.print(seconds);

// Check if the correct code was entered


if (disarmCodeIndex == disarmCodeLength) {
alarmActive = false;
digitalWrite(greenLedPin, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Access GRANTED");
delay(2000); // Display "Access GRANTED" for 2 seconds
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TIME: 15"); // Reset timer to 15 seconds
seconds = 15;
disarmCodeIndex = 0; // Reset code input
}
}

void checkButton(char button) {


if (button == disarmCode[disarmCodeIndex]) {
disarmCodeIndex++;
if (disarmCodeIndex == disarmCodeLength) {
// Correct code entered, grant access
alarmActive = false;
digitalWrite(greenLedPin, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Access GRANTED");
delay(2000); // Display "Access GRANTED" for 2 seconds
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TIME: 15"); // Reset timer to 15 seconds
seconds = 15;
disarmCodeIndex = 0; // Reset code input
} else {
// Delay between button presses
delay(buttonDelayMillis);
}
} else {
// Incorrect code, reset code input
disarmCodeIndex = 0;
digitalWrite(yellowLedPin, HIGH);
delay(1000); // Display "Incorrect" for 1 second
digitalWrite(yellowLedPin, LOW);
}
}

You might also like