0% found this document useful (0 votes)
33 views12 pages

Micro Oo

Uploaded by

fdboussi
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

Topics covered

  • User Feedback,
  • Servo Control,
  • Interactive System,
  • Advanced Security Features,
  • Home Security,
  • Security System,
  • Home Automation,
  • Access Granted,
  • Access Control,
  • Circuit Diagram
0% found this document useful (0 votes)
33 views12 pages

Micro Oo

Uploaded by

fdboussi
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

Topics covered

  • User Feedback,
  • Servo Control,
  • Interactive System,
  • Advanced Security Features,
  • Home Security,
  • Security System,
  • Home Automation,
  • Access Granted,
  • Access Control,
  • Circuit Diagram

Final Project Report

MICROPROCESSOR INTERFACING
Department of communication engineering
BEIRUT ARAB UNIVERSIT
Arduino-Based Security System

Dr: Ghina El-Waly

Students: Fahmi El-Daboussi

Id: 202304741

Layal Boukhary

Id:202303903

1
TABLE OF CONTENTS
Page No

1. INTRODUCTION ........................................................................................................................ 3
2. PROPOSED SYSTEM ................................................................................................................ 3
3. TOOLS & SPECIFICATIONS .................................................................................................... 4
4. HARDWARE MODELLING ...................................................................................................... 7
5. SOURCE CODE .......................................................................................................................... 7
6. RESULTS & DISCUSSIONS .................................................................................................... 11
7. CONCLUSIONS ........................................................................................................................ 12
8. REFERENCES ........................................................................................................................... 12

ABSTRACT

This project presents an Arduino-based password-protected security system designed for access control
applications. The system integrates a 4x4 keypad, an LCD display, a servo motor, and a buzzer to provide
interactive and functional user feedback. When the user inputs the correct password, the system grants
access by simulating door control using a servo motor, displaying an "Access Granted" message on the
LCD, and playing a melody resembling a simple guitar-like rhythm with specific musical notes and pauses.
If an incorrect password is entered, access is denied, accompanied by a buzzer tone and the "Access
Denied" message. Additionally, after three consecutive incorrect attempts, an alarm sequence with rising
and falling buzzer tones is triggered. The system demonstrates a practical, cost-effective solution for home
security, lockers, and restricted-access control systems, with potential for future enhancements such as
network integration and advanced security features.

2
1. INTRODUCTION

This project implements an Arduino-based security system that allows users to input a password
via a keypad. The system includes an LCD for visual feedback, a servo motor to control the opening
and closing of a door, and a buzzer for audio feedback. If the correct password is entered, the system
grants access by opening the door and plays a melody. If the wrong password is entered multiple
times, an alarm is triggered to indicate unauthorized access attempts.

2. PROPOSED SYSTEM

The proposed system utilizes an Arduino microcontroller to implement a secure password-


protected access system. The following components and functionalities are included:
• Password Validation
• Users enter a predefined password via a 4x4 keypad.
• The system validates the entered password.
• If the password is correct:
• The LCD displays "Access Granted."
• A servo motor rotates from 0° to 90°, simulating door opening.
• A melody of predefined notes (e.g., G4, A4, C5) plays, simulating a simple guitar-like rhythm.
• The door remains "open" for 3 seconds, after which the servo resets to 0°, representing door
closure.
• If the password is incorrect:
• The LCD displays "Access Denied."
• The buzzer emits a 500 Hz tone for half a second.
• After three consecutive failed attempts, the system triggers an alarm sequence with rising and
falling buzzer tones.
• LCD Feedback
• The LCD displays real-time messages, including:
• "Enter Password": Prompting user input.
• "Access Granted": Displayed when the password is correct.
• "Access Denied": Displayed when the password is incorrect.
• Servo Motor Control
• A servo motor operates to simulate the door mechanism, moving between 0° (closed) and 90°
(open) states.
• The door remains "open" for 3 seconds before returning to the closed state.
• Buzzer Feedback
• Correct password input triggers a melodic sequence played by the buzzer.
• Incorrect password input produces a 500 Hz tone for half a second.

3
• An alarm with rising and falling tones is activated after three incorrect attempts.
• Code Flow
• Initialization: The LCD displays "Enter Password."
• User Input: The user inputs the password via the keypad.
• Decision Logic:
• If correct: Door opens, melody plays, and access is granted.
• If incorrect: Denied access, buzzer sounds, and attempts are tracked.
• Three failed attempts activate an alarm.

3. TOOLS & SPECIFICATIONS

3.1. Arduino Uno


Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital
input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic
resonator, a USB connection, a power jack, an ICSP header and a reset button. It contains everything
needed to support the microcontroller; simply connect it to a computer with a USB cable or power
it with a AC-to-DC adapter or battery to get started.

Figure 1. Arduino Uno

4
Arduino Uno Technical Specifications:

Microcontroller: ATmega328
Working Voltage: 5V
Input Voltage (recommended): 7-12V
Input Voltage (limit): 6-20V
Digital I/O Pins: 14 (6 of which are PWM outputs)
Analog Input Pins: 6
Current per I/O: 40 mA
Current for 3.3V Output: 50 mA
Flash Memory: 32 KB (ATmega328) 0.5 KB from bootloader
SRAM: 2 KB (ATmega328)
EEPROM: 1 KB (ATmega328)
Clock Speed: 16MHz
Length: 68.6mm
Width: 53.4mm
Weight: 25g

32. Servo Motor


Tower Pro MG996R High Torque Servo Motor - 13KG 360 Degrees
Servo is defined as a drive system that accurately controls the angular-linear position, speed and
acceleration of mechanisms. In other words, it is a motion-controlled mechanism. Although servo
motors are the most used motor type in robot technologies, they are also used in RC (Radio
Control) applications. RC Servo Motors were first used in remote controlled model vehicles.
Servos are designed to take the desired position and not change its position unless a new
command is received. Servo motors can be used for many different purposes.

5
Tower Pro MG996R High Torque Servo Motor Technical Specifications:

Model: MG996R
Control System: +Pulse Width Control
(RX) Required Pulse: 3.0 ~ 5V Peak-to-Peak Square Wave
Working Voltage: 4.8 ~ 7.2V/DC
Carrying Capacity: 13KG
Rotation Angle: 360 Degrees
Gear Type: Metal Gear
Box Material: Sturdy Plastic
Programmable: NO
Connector Type: JR
Connector Cable Length: 32.0cm
Weight: 50gr

Figure 2. Servo Motor

3.3. 4X4 Membrane Keypad


4x4 Keypad- 4x4 Keypad; The keypad with 16 keypads provides support for your
microcontroller projects. You can mount it easily thanks to the adhesive surface on the back. It is
used as a hardware tool to input your information in your projects. It works compatible with
Arduino and other small processors. Since it has 16 keypads, there is a special membrane switch
under each key. All these membrane switches are connected to each other by a conductive line
under the pad forming a grid matrix.
Figure 3. 4X4 Membran

4x4 Keypad Technical Specifications:

Maximum Efficiency:24V/DC
Operating Temperature:0/5°C
Interface:8-pin access to 4x4 matrix

6
4. HARDWARE MODELLING

4.1. Circuit Diagram

Figure 4. Circuit Diagram

5. SOURCE CODE

#include <LiquidCrystal.h> // Include necessary libraries


#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h> // Servo motor library

// Define keypad configuration


#define ROW_NUM 4 // Four rows for the keypad
#define COL_NUM 4 // Four columns for the keypad

char keys[ROW_NUM][COL_NUM] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROW_NUM] = {9, 8, 7, 6}; // Connect keypad rows to these Arduino pins
byte colPins[COL_NUM] = {5, 4, 3, 2}; // Connect keypad columns to these Arduino pins

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROW_NUM, COL_NUM); // Initialize


keypad

7
// LCD Configuration
LiquidCrystal_I2C lcd(0x27, 20, 4); // Set the LCD address to 0x27 for a 16 characters, 2-line display

// Servo motor configuration


Servo doorServo;
#define SERVO_PIN 12 // Pin for the servo motor
#define BUZZER_PIN 10 // Pin for the buzzer
#define RED_LED_PIN 11 // Pin for the red LED (for incorrect password)
#define GREEN_LED_PIN 13 // Pin for the green LED (for correct password)

String password = "1234"; // Predefined password


String inputPassword = "";
bool doorOpen = false;
int wrongAttempts = 0; // Counter for wrong attempts

// Notes frequencies (in Hz) for melody


int melody[] = {
392, // G4
440, // A4
523, // C5
587, // D5
659, // E5
698, // F5
784, // G5
880, // A5
987 // B5
};

// Note durations (in milliseconds)


int noteDurations[] = {
250, // Quarter note
500, // Half note
125, // Eighth note
375, // Dotted quarter note
1000 // Whole note
};

void setup() {
// Initialize LCD
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.print("Enter Password:");

// Attach the servo


doorServo.attach(SERVO_PIN);
doorServo.write(0); // Ensure the door is closed

// Initialize buzzer and LED pins


pinMode(BUZZER_PIN, OUTPUT);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT); // Pin for the green LED
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, LOW); // Ensure green LED is off initially

// Display initial state on serial monitor


Serial.begin(9600);
Serial.println("System Ready");
8
}

void loop() {
char key = keypad.getKey(); // Get the key pressed

if (key) {
Serial.print("Key pressed: ");
Serial.println(key);

if (key == '#') { // Submit password


if (inputPassword == password) {
lcd.clear();
lcd.print("Access Granted");
openDoor();
digitalWrite(GREEN_LED_PIN, HIGH); // Turn on the green LED for correct password
delay(500); // Keep the door open for 0.5 seconds
playMelody();
closeDoor();
digitalWrite(GREEN_LED_PIN, LOW); // Turn off the green LED after access
wrongAttempts = 0; // Reset wrong attempts counter
} else {
lcd.clear();
lcd.print("Access Denied");
tone(BUZZER_PIN, 500); // Emit a 500 Hz tone for incorrect password
digitalWrite(RED_LED_PIN, HIGH); // Turn on the red LED for incorrect password
delay(500); // Wait for 0.5 seconds
noTone(BUZZER_PIN); // Stop the buzzer
digitalWrite(RED_LED_PIN, LOW); // Turn off the red LED
delay(500); // Wait for 0.5 seconds before resetting
wrongAttempts++; // Increment the wrong attempt counter
if (wrongAttempts >= 3) {
triggerAlarm(); // Trigger alarm after 3 incorrect attempts
}
}
inputPassword = ""; // Reset the input
lcd.clear();
lcd.print("Enter Password:");
} else if (key == '*') { // Clear input
inputPassword = "";
lcd.clear();
lcd.print("Enter Password:");
} else {
inputPassword += key; // Add the key to the input password
lcd.setCursor(0, 1);
lcd.print(inputPassword);
}
}
}

void openDoor() {
doorOpen = true;
doorServo.write(90); // Open the door (Servo to 90 degrees)
Serial.println("Door opened");
}

void closeDoor() {
doorOpen = false;
doorServo.write(0); // Close the door (Servo back to 0 degrees)
9
Serial.println("Door closed");
}

void triggerAlarm() {
lcd.clear();
lcd.print("ALARM TRIGGERED!");

// Rising and Falling Frequencies with a faster rhythm for the police alarm
for (int i = 0; i < 6; i++) {
tone(BUZZER_PIN, 1800); // Low frequency tone
digitalWrite(RED_LED_PIN, HIGH); // Turn on the red LED
digitalWrite(GREEN_LED_PIN, LOW); // Turn off the green LED
delay(200); // Wait for 200 ms
noTone(BUZZER_PIN); // Stop the tone
digitalWrite(RED_LED_PIN, LOW); // Turn off the red LED
digitalWrite(GREEN_LED_PIN, HIGH); // Turn on the green LED
delay(200); // Wait for 200 ms

tone(BUZZER_PIN, 2000); // High frequency tone


digitalWrite(RED_LED_PIN, HIGH); // Turn on the red LED
digitalWrite(GREEN_LED_PIN, LOW); // Turn off the green LED
delay(200); // Wait for 200 ms
noTone(BUZZER_PIN); // Stop the tone
digitalWrite(RED_LED_PIN, LOW); // Turn off the red LED
digitalWrite(GREEN_LED_PIN, HIGH); // Turn on the green LED
delay(200); // Wait for 200 ms
}
digitalWrite(GREEN_LED_PIN, LOW);
// Add a small pause between repetitions
delay(2000); // Wait for 2 seconds before restarting the siren pattern

wrongAttempts = 0; // Reset wrong attempts counter after alarm


}

void playMelody() {
// Play a melody after the correct password is entered
for (int i = 0; i < 8; i++) {
tone(BUZZER_PIN, melody[i]); // Play the note
delay(noteDurations[i % 5]); // Duration of the note
noTone(BUZZER_PIN); // Stop the tone

// Add a small pause after each note to simulate rhythm


delay(50); // Short pause between notes
}
}

10
6. RESULTS & DISCUSSIONS

The code is divided into several sections: password entry, system response, melody playback,
and alarm system.
a. Password Entry
The user is prompted to enter a password using the keypad. The entered password is compared
with a predefined password ("1234").
If the correct password is entered, the system grants access, opening the door for 3 seconds, and
then plays a melody.
If the password is incorrect, the buzzer emits a 500 Hz tone to signal the failed attempt, and the
system waits for the user to retry.
b. Door Control
If the correct password is entered, the servo motor is activated to open the door (moving to 90
degrees) for 3 seconds.
After 3 seconds, the servo closes the door (moving back to 0 degrees).
The door state (open or closed) is monitored through boolean variables.
c. Buzzer Feedback
On incorrect password entry, the buzzer emits a 500 Hz tone for half a second.
If three incorrect attempts are made, the system triggers an alarm.
d. Alarm System
The alarm is activated if the user fails to enter the correct password three times.
The buzzer generates rising and falling frequency tones (1800 Hz and 2000 Hz) with a rhythm,
simulating an alarm sound. The alarm plays in a loop for a short period before resetting.
e. Melody Playback
If the password is entered correctly, the system plays a melody using different musical notes (G4,
A4, C5, etc.) that simulate a simple guitar-like rhythm. Each note has a specific duration and is
followed by a small pause.

5. Functionality
Password Validation: Users input the password via the keypad. The system checks whether the
entered password matches the predefined password. If correct, the door opens for 3 seconds;
otherwise, it denies access and provides audio feedback.

Servo Motor Control: The servo motor simulates door control by moving between 0 and 90
degrees to represent door opening and closing. If the password is correct, the door opens for 3
seconds.

11
LCD Feedback: The LCD screen provides real-time messages, displaying "Enter Password,"
"Access Granted," or "Access Denied," based on the user’s actions.
Buzzer: The buzzer emits different frequencies depending on whether the password is correct or
incorrect. A melody is played for correct password input, and an alarm is triggered after three
wrong attempts.

6. Code Flow
The system starts by displaying "Enter Password" on the LCD.
The user enters the password on the keypad.
If the password is correct:
The LCD displays "Access Granted."
The servo opens the door.
The melody plays.
After 3 seconds, the door closes.
If the password is incorrect:
The LCD displays "Access Denied."
A 500 Hz tone sounds from the buzzer for half a second.
After 3 incorrect attempts, the alarm sequence is triggered with rising and falling tones.

7. CONCLUSIONS

This project demonstrates an effective and straightforward Arduino-based security system with
password protection. The integration of a keypad, LCD display, servo motor, and buzzer creates
an interactive and functional system for controlling access. The project can be expanded with
additional features like more complex password algorithms, networked control, or integration
with other sensors

8. REFERENCES

[1] To learn the basics of Arduino or electronics you can learn from the arduino.cc it's very
useful.
[2] JavaTpoint provides Arduino Tutorial.
[3] Arduino Course for Beginners - Open-Source Electronics Platform.
[4] I created circuit diagram, schematic diagram of the project and I learned more about
electronics with Tinkercad is a free web app for 3D design, electronics, and coding, trusted by
over 50 million people around the World.

12

You might also like