Arduino Home Security System - Stay Safe Yall! :)

by 900006 in Circuits > Arduino

33 Views, 1 Favorites, 0 Comments

Arduino Home Security System - Stay Safe Yall! :)

Screenshot 2026-06-19 193933.png
20260614_223010.jpg

This Home Security System Project is an automated safety system that uses an Arduino to monitor a space for unauthorized entry. By integrating a PIR motion sensor for room surveillance, an ultrasonic sensor as a digital tripwire for doorways, and a tilt sensor to detect window tampering, the hub provides multi-layered protection. The system features a "State Logic" design, allowing a user to arm or disarm the alarm via a 4x4 keypad, with colored LEDs and a high-pitched piezo siren providing immediate visual and audible alerts if a security breach occurs.


I tweaked this project a lot. But I did get this project idea from 2 people (References!) :

  1. https://projecthub.arduino.cc/rajun10/arduino-security-alarm-system-f38f99
  2. https://medium.com/@adambens/arduino-home-security-environment-monitoring-system-4e3698bd32a9

Supplies

images.jpg
images.jpg
images.jpg
images.jpg
images.jpg
image-22.png
images.jpg
images.jpg
images.jpg
images.jpg
images.jpg
  1. 1x Arduino Uno
  2. 1x Long Breadboard
  3. 1x PIR Motion Sensor
  4. 1x Ultrasonic Sensor (HC-SR04)
  5. 1x SW200D Tilt Sensor
  6. 1x Piezo Buzzer
  7. 1x 4 by 4 Keypad
  8. 2x LED (1x Red, 1x Green)
  9. 3x Resistor (1x 10kΩ, 2x 330Ω)
  10. Several Jumper Wire

Keypad

Screenshot 2026-06-20 001417.png

Connect the keypad to the Arduino.

row 1 to pin 13,

row 2 to pin 12,

row 3 to pin 11,

row 4 to pin 10,

And for the column pins, same as well. We need to connect it from pin 9 to the digital pin 6.


PIR Motion Sensor - Power & Ground

Screenshot 2026-06-20 004021.png

Connect the PIR Motion Sensor to the breadboard

We need to connect from the signals to the digital pin. Here it's connected to pin 2.


Also to get this out of the way, Of course connect the power and ground. (Don't forget the colors - Red for positive & Black for negative)

Ultrasonic Sensor

Screenshot 2026-06-20 004337.png

Connect the Ultrasonic Sensor to the breadboard.

Connect both power and ground first

Connect the trigger pin and echo pin to the digital pins

Tilt Sensor

Screenshot 2026-06-20 010423.png

Connect the Tilt to the breadboard.

One side to the 5 volts

And the other side to the ground along with a 10kΩ resistor

We need to connect the ground side of the tilt sensor to a digital pin as well

Piezo Buzzer

Screenshot 2026-06-20 011508.png

Connect the Piezo Buzzer to the breadboard.

Since we have no more pins on the digital input on the Arduino UNO,

we will use the analog pins as the digital output and input for the other sensors.

The Piezo Buzzer is connected to A0 from the positive side.

The negative side is connected to ground.

LEDs

Screenshot 2026-06-20 012019.png

Connect the LEDs to the breadboard.

Red Led: The anode (positive side) is connected to A1.

Green Led: The anole (positive side) is connected to A2.

The cathode of both LEDs connects with a 330 ohm resistor to ground.

Code

Screenshot 2026-06-20 013559.png
Screenshot 2026-06-20 013613.png
Screenshot 2026-06-20 013634.png
Screenshot 2026-06-20 013658.png

Here is the code (proofreaded this code with google AI):

#include <Keypad.h>


// Keypad setup

const byte ROWS = 4;

const byte COLS = 4;

char keys [ROWS][COLS] = {

{'1', ‘2’, ‘3’, ‘4’},

{'4', '5', '6', 'B'},

{'7', '8', '9', 'C'},

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

};

byte rowPins[ROWS] = {13, 12, 11, 10};

byte colPins [COLS] = {9, 8, 7, 6};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);


// Pins

const int PIR = 2;

const int trigPin = 4;

const int echoPín = 3;

const int tiltsensor = 5;

const int buzzer = A0;

const int redLED = A1;

const int greenLed = A2;


bool isArmed = false;


void setup()

pinMode(PIR, INPUT);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(tiltSensor, INPUT_PULLUP);

pinMode(buzzer, OUTPUT);

pinMode(redLED, OUTPUT);

pinMode(greenLED, OUTPUT);

Serial.begin(9600);

}


void loop()

char key = keypad.getkey():


//Arming Logic

if (key =='#') {

isArmed = true;

digitalWrite(redLED, HIGH);

digitalWrite(greenLED, LOW);

tone(buzzer, 1000, 200); // Confirmation beep

}


// Disarming logic

if (key == '*') {

isArmed = false;

digitalWrite(redLED, LOW);

digitalWrite(greenLED, HIGH);

noTone(buzzer);

}


if (isArmed) {

// 1. Check Motion (PIR)

if (digitalRead(PIR)== HIGH) triggerAlarm("Motion Detected!");

// 2. Check Tripwire (Ultrasonic)

long duration, distance;

digitalWrite(trigPin, LOW); delayMicroseconds(2);

digitalWrite(trigPin, HIGH); delayMicroseconds(10);

digitalWrite(trigpin, LOW);

duration pulseIn(echopin, HIGH);

distance (duration / 2) / 29.1;

if (distance< 50) triggerAlarm("Doorway Breach!");

// 3. Check Window (Tilt)

if (digitalRead(tiltSensor) == HIGH) triggerAlarm("Window Opened!");

}

}


void triggerAlarm(String reason) {

Serial.println(reason);

tone(buzzer, 2000); // Continuous siren

// Flash Red LED

digitalWrite(redLED, LOW); delay(100);

digitalWrite(redLED, HIGH);

}

ENJOY!

20260615_104859.jpg

Try is out and see if it works!


When you press a certain key, a alarm will be turned on

If you reach a certain close distance, the alarm will be triggered, the buzzer makes a loud sound and the red LED will turn on.

When you press a certain key the alarm will be turned off and the green LED will turn on.


STAY SAFE OUT THERE AND CATCH THOSE CRIMINALS THAT LOVE TO INVADE PEOPLE'S HOMES. :)