Skip to main content

SmartGuard: Raspberry Pi Pico W Burglar Alarm System

Raspberry Pi Pico W-powered Smart Burglar Alarm System with Multi-Sensor Detection.

info

Author: RATA MIRCEA-ANDREI
GitHub Project Link: https://github.com/UPB-FILS-MA/project-MirceaAndrei/tree/main

Description

This project provides an opportunity to develop a smart alarm system tailored to modern security requirements. It offers a practical and efficient solution to detect intruders with advanced technology. Its compact, user-friendly design allows for seamless implementation in a wide range of environments, providing enhanced safety and peace of mind. Moreover,it has user-friendly interface where you can set custom security keys

How it works:

For this project, we have developed a comprehensive alarm system utilizing a range of hardware components to enhance security and convenience. At the core of this system is the Raspberry Pi Pico W, which serves as the central controller and processor.

The system is equipped with a Passive Infrared (PIR) sensor, which is designed to detect motion in its vicinity. When the PIR sensor registers movement, it triggers an immediate response from the system: LEDs and a buzzer are activated, alerting those nearby of potential activity.

Additionally, the system includes a keypad and an LCD screen. Once motion is detected and the alarm is activated, the person present must input the correct password into the keypad to deactivate the alarm. The password prompt is displayed on the LCD screen for easy reference, ensuring a seamless user experience and an added layer of security.Once the whole project starts, it displays on the LCD screen some information for configuration of the alarm. It takes like 8 seconds to initialize, then it will show you what to do to set this system. Basically once started, the user can self-input a custom password, and when motion is detected, it guides you to enter the password and disarm the alarm for a few seconds, enough time if you are the owner and not the intruder :), then it starts again. Additionally, a game of lights is starting when it checks if the password is correct. If the password is correct, after the game of lights,a small music will start for 3 seconds , and the green LED will remain on until it finish writing the messages on the LCD. After, the alarm is again initialized. It also has another function, if you enter the wrong password 3 times, you will need to wait an additional 5 seconds before entering it again. Also, if the password is wrong, after the game of lights, the red LED will remain on.

This combination of hardware and functionality results in a sophisticated yet user-friendly alarm system that offers reliable security for a variety of settings. It provides users with real-time alerts and control over the system, making it a valuable asset for safeguarding properties and ensuring peace of mind.

Motivation

The motivation behind this project stems from a desire to enhance home and property security by leveraging modern technology. Traditional alarm systems can be costly and complex to install, often requiring professional services. In contrast, this project offers an opportunity to create an affordable and customizable smart alarm system using a Raspberry Pi Pico W and a range of hardware components.

Architecture

System Diagram

Log

8-12.04

I choose the concept and the main ideas for this project.

15-19.04

I found all the hardware parts and everything that i need and i proceed a order.

26.04-3.05

I already learned how it should work, and I am still at the hardware part, at all the connection and everything. I try to make them work

6.05-10.05

I manage to do all the hardware part and finished soldering all the parts.

13.05-17.05

I am the software part,with small steps trying to learn how to do it. I'm still trying to improve as mush as I can, and find new ideas to implement for this project.

20.04-25.04

I finished everything on the project,the software milestone and also the design and fix all the errors.

Hardware

The hardware includes a Raspberry Pi Pico W for control, a PIR sensor for motion detection, LEDs for visual alerts, a buzzer for audio alerts, an LCD screen for display, and a keypad for user input and password authentication.

  • Raspberry Pi Pico W is the microcontroller,the brain of this project.
  • Passive Infrared (PIR) sensor is used to detect movement.
  • LEDs are used to provide visual alerts when motion is detected. I am am the software part,with small steps trying to learn how to do it.

Hardware

The hardware includes a Raspberry Pi Pico W for control, a PIR sensor for motion detection, an LED for visual alerts, a buzzer for audio alerts, an LCD screen for display, and a keypad for user input and password authentication.

  • Raspberry Pi Pico W is the microcontroller,the brain of this project.
  • Passive Infrared (PIR) sensor is used to detect movement.
  • LED is used to provide visual alerts when motion is detected.
  • Passive Buzzer is used for making sound when the alarm is triggered.
  • LCD with I2C MODULE is used for displaying the information on lcd.
  • Matrix keypad allows users to input a password for authentication and disarm the alarm system.
  • Breadboard is used for connecting every pin of the hardware components.

Schematics

For the KiCad I connected the hardware as following :

LCD i2c:

VCC to pin VBUS GND to pin GND SDA to pin GP12 SCL to pin GP13

PIR MOTION SENSOR:

VCC to pin VSYS GND to pin GND OUT to pin GP3

KEYPAD:

ROW to pin 3V3_OUT COL1 to pin GP4 COL2 to pin GP5 COL3 to pin GP6 COL4 to pin GP7

BUZZER:

POSITIVE to pin GP1 NEGATIVE to GND

LEDS:

RED to pin GP16 GREEN to pin GP17 BLUE to pin GP18

kicadschematic

Here are also a few pictures of the actual project :

Hardware1

Hardware2

Hardware3

Hardware4

The final project pictures:

Design

Design2

Design3

Design4

Bill of Materials

DeviceUsagePrice
Rapspberry Pi Pico WThe microcontroller35 RON
LcdDisplay15 RON
I2c moduleDIsplay module6 RON
LedVisual alert0.45 RON
BuzzerSound4 RON
PIRSensor9 RON
KeypadUser input4 RON

Software :

LibraryDescriptionUsage
embassy-rpRP2040 PeripheralsUsed for accessing the peripherals
PWMPulse-Width ModulationUsed to make buzzer sound louder
embassy-executorExecutor for Rust Embedded SystemsAn async/await executor designed for embedded usage
GPIOGPIOUsed for interacting with GPIO Pins of the Pi Pico
lcd_lcm1602_i2cHITACHI HD44780 LCDUsed to initialize the lcd with i2c module
ufmt_writeA collection of methods that are required / used to format a message into a streamUsed to write strings on LCD
rp2040-halA Rust Embedded-HAL impl for the rp2040 microcontrollerUsed for implementation of the embedded-hal traits for the RP2040 microcontroller
embassy-usbA rust libraryUsed for Async USB device stack for embedded devices in Rust
logA lightweight logging facade for RustUsed for excluding messages with a lower priority
cortex-mARM Cortex-M Processor SupportUsed for accessing Cortex-M peripherals
embassy-timeTime and Timer UtilitiesProvides duration and timer utilities
embassy-usb-loggerUSB Logging UtilityUsed for logging via USB
ufmtMicrocontroller-Friendly FormattingProvides lightweight formatting utilities

Software Explanation

Project Power-Up and Initialization

1. Power-Up:

When you power up the Raspberry Pi Pico, the program begins execution starting from the main function, which is an asynchronous function denoted by #[embassy_executor::main].

2. Peripheral Initialization:

The first step is initializing the hardware peripherals:

  • The GPIO pins are set up for the LEDs, buzzer, PIR sensor, and keypad.
  • The I2C bus is initialized for communication with the LCD.
  • PWM configuration is set up for the buzzer to control its sound.

LCD and LED Initialization Sequence

3. LCD Welcome Message:

The LCD displays the initial message "Burglar alarm" followed by "Calibrating PIR" and "Please wait...". This informs the user that the system is booting up and calibrating the PIR sensor.

4. LED Visual Game:

Simultaneously, the LEDs perform a visual game to indicate the system is initializing. This involves blinking LEDs in a sequence (RED -> GREEN -> BLUE) to provide a visual countdown.

PIR Sensor Calibration

5. Calibration Countdown:

The LCD displays a countdown from 5 to 1, indicating the time left for PIR sensor calibration. During this countdown:

  • LEDs continue their visual game, providing a dynamic visual feedback by flashing in sequence.

Initialization Complete

6. Initialization Complete Message:

After the PIR sensor is calibrated, the LCD shows "Initializing software..." and then a countdown message from 5 to 1 again with the same LED visual game.

Main Functionality - Alarm Armed

7. Alarm Armed Message:

The LCD displays "Alarm armed!" indicating the system is now active. The blue LED is turned on to show that the alarm is armed.

8. Prompt for Password Setup:

The LCD asks the user to "Enter custom password:". The user enters a custom 4-digit password using the keypad. Each entered digit is displayed on the LCD, and a short buzzer sound is played for feedback.

Main Loop - Motion Detection and Alarm Activation

9. Waiting for Motion:

The system enters the main loop, where it waits for motion detection from the PIR sensor. The blue LED remains on, indicating the system is armed and in standby mode.

10. Motion Detected:

When motion is detected:

  • The buzzer sounds, and the LEDs flash in sequence to alert the user.
  • The LCD displays "Motion alert!!!" for 2 seconds.

Password Entry to Disarm the Alarm

11. Password Entry Prompt:

The LCD prompts "Enter password:" for the user to disarm the alarm. The user enters the 4-digit password using the keypad.

Password Validation:

  • If the password is correct:
    • The LEDs flash in sequence, and the green LED is turned on.
    • The LCD displays "Password correct".
    • A melody is played using the buzzer.
    • The LCD then shows "Alarm disarmed".

Password Validation

  • If the password is incorrect:
    • The incorrect attempt counter increments.
    • The LEDs flash to indicate an incorrect password, and the red LED is turned on.
    • The LCD displays "Password incorrect".

Handling Incorrect Password Attempts

13. Max Incorrect Attempts:

If the maximum number of incorrect attempts is reached:

  • The system locks for a period, showing a countdown on the LCD.
  • The LEDs flash in a warning sequence.
  • After the lock period, the system resets the incorrect attempt counter and prompts the user to enter the password again.

Main Loop Continuation

14. Resuming Main Loop:

After disarming the alarm or handling incorrect attempts, the system re-enters the main loop to wait for motion detection again. The blue LED is turned on, indicating the system is armed.

Panic Handler

Panic Handler:

If the program encounters a critical error, it enters an infinite loop to halt further execution, preventing undefined behavior.

Project Demo

Here's the link to the project demo: Project Demo

  1. Lab 4
  2. Lab 7
  3. Lab 8
  4. Rust tutorials
  5. The concept