Password-Protected Alarm System
Introduction
This project implements a password-protected alarm system using the Arduino Nano ATmega328P board.
What it does: When triggered (via a start button or a PIR motion sensor), a 30-second countdown begins and the passive buzzer starts beeping. The alarm can only be silenced by entering the correct 4-digit password via 4 push buttons. A green LED and a success jingle confirm correct entry, while a red LED and a continuous alarm signal a wrong attempt. The system also controls a servo motor acting as a physical door lock, stores the password persistently in the internal EEPROM (survives power cycles), and allows secure in-system password changes. A 16×2 I2C LCD and UART serial output provide real-time status feedback.
Key features: Password-protected alarm, PIR motion detection with arming delay, servo door lock, EEPROM password persistence, 4-state FSM, UART debug output.
General Description
The system is structured around a 4-state Finite State Machine (FSM) running on the ATmega328P. All peripherals are driven using direct register manipulation.
Hardware Modules:
ATmega328P (Arduino Nano) — central processing unit, 16
MHz, 5V
PIR Sensor (HC-SR501) — motion detection for automatic arming
Servo Motor SG90 — actuates the physical door lock mechanism (PC0)
Passive Buzzer — variable-frequency acoustic feedback via GPIO toggle (PD7)
4x Password Buttons — 4-digit code input (PD3, PD4, PB0, PB1)
Start/Reset Button — alarm trigger and system reset (PD2)
Arming Button — PIR sensor arm/disarm toggle (PB4)
Password Change Button — enters secure password-change mode (PC1)
Green LED — correct password / system disarmed indicator (PD5)
Red LED — active alarm indicator (PD6)
PIR Status LED — visual indicator when PIR is armed (PB2)
16×2 LCD (HD44780 + PCF8574 I2C adapter) — real-time status messages (A4/A5)
Bill of Materials:
| Component | Quantity | Notes |
| —————————- | ———- | ———————————— |
| Arduino Nano ATmega328P | 1 | 16 MHz, 5V |
| Passive buzzer | 1 | Sound |
| Push buttons | 4 | Password input, pull-up resistors |
| Reset button | 1 | Reset purpose |
| Green LED + 220Ω resistor | 1 | Correct password indicator |
| Red LED + 220Ω resistor | 1 | Wrong password indicator |
| 16×2 LCD (HD44780) | 1 | I2C adapter |
| Breadboard + jumper wires | - | Prototyping |
| USB cable | 1 | For flashing the ATmega328P |
Electrical Notes:
All push buttons are wired with the internal pull-up resistors enabled (INPUT_PULLUP equivalent in bare metal: set DDRx bit to 0 and PORTx bit to 1). Buttons are active-low.
LEDs are connected through 220Ω current-limiting resistors to GND.
Algorithms and Structures:
The system uses a simple finite state machine with 5 states:
`IDLE` — system waiting, buzzer silent
`ARMED` — alarm active, buzzer playing alarm melody via PWM
`INPUT` — user is entering the password sequence
`CORRECT` — correct password: green LED on, buzzer off, LCD shows “ACCESS GRANTED”, auto-return to IDLE after timeout
`WRONG` — wrong password: red LED on, buzzer plays intensified tone, LCD shows “ACCESS DENIED”, auto-return to ARMED
Software design
Editor: VS Code with the C and “AVR Utils” extensions for syntax highlighting and register lookup
Debugging: LED-based state signaling and logic analyzer on PWM/GPIO lines
Target: ATmega328P X-Mini
Libraries and 3rd-party sources:
`avr/io.h` — direct register-level access to all ATmega328P peripherals (DDRx, PORTx, PINx, TCCRx, OCRx, etc.)
`avr/interrupt.h` — enabling global interrupts (sei/cli) and defining ISR handlers
`util/delay.h` — used exclusively in the LCD initialization sequence and LED hold timers; all alarm timing is handled via hardware timers
Block Design
Laboratories Used:
*The implementation of this project is based on the concepts studied in the following laboratories:
Laboratory 0 GPIO - Used for basic interfacing. I configured the pins for the LEDs as outputs and the pins for the push buttons as inputs with internal pull-up resistors enabled.
Laboratory 1 UART - Integrated for debugging purposes. The system transmits the current state and the entered sequence to a Serial Monitor, allowing for real-time monitoring of the logic.
Laboratory 2 Interrupts - Used for the reset button and potentially for handling button presses to ensure immediate response from the microcontroller without constant polling in the main loop.
Laboratory 3 Timers - Essential for the acoustic feedback.
Laboratory 6 I2C - Essential for the UX.
Schematics
Pins Layout
| Arduino Nano Pin | Pin Type | Connected Component | Functional Description |
| —————— | —————– | ———————- | ——————————————– |
| D2 | Input | SW_Push (Reset) | System reset button |
| D3 | Input | SW4 | Password input button |
| D4 | Input | Start | Process start / arming button |
| D5 | Input | SW1 | Password input button |
| D6 | Input | SW3 | Password input button |
| D7 | Input | SW2 | Password input button |
| D8 | Output | D2 (Red LED) | “Access Denied” indicator (via 220Ω R1) |
| D9 | Output | D1 (Green LED) | “Access Granted” indicator (via 220Ω R2) |
| D10 | Output (PWM) | BZ1 (Buzzer) | Acoustic alarm / feedback signal |
| A4 | I/O (SDA) | J1 (LCD I2C) | I2C data line |
| A5 | I/O (SCL) | J1 (LCD I2C) | I2C clock line |
Results
Conclusions
Download
Journal
Bibliography / Resources