Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
rajun10
Published © GPL3+

Arduino security alarm system

This project will detect any intruders and alarm you using the components of an LED, a buzzer, ultrasonic sensor, and a LCD display.

IntermediateProtip4,520
Arduino security alarm system

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
RGB LCD Shield Kit, 16x2 Character Display
RGB LCD Shield Kit, 16x2 Character Display
×1
5 mm LED: Red
5 mm LED: Red
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Buzzer
Buzzer
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×2
9V battery (generic)
9V battery (generic)
×1
Bench Power Supply, DC Power Module
Bench Power Supply, DC Power Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit diagram

screenshot_(5)_EET0j3sVwd.png

Code

The code

C/C++
We are using this code to detect intruders and alarm you
#include <LiquidCrystal.h>
LiquidCrystal LCD(A0,A1,A2,A3,A4,A5); // the pins for the lcd display
#define trigPin 13 
#define echoPin 12
//for the ultrasonic sensor
const int buzzer = 11;
const int ledPin = 10;
//the integers for the led and buzzer

void setup()
{
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT); 
  pinMode(buzzer, OUTPUT);
  pinMode(ledPin, OUTPUT);
  LCD.begin(16,2); // contacting the lcd display
  }

void loop(){

 
 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;
 delay(500);

 LCD.setCursor(0,1);
 LCD.print("                ");
 LCD.setCursor(0,1);
 LCD.print(distance);
 LCD.print(" cm");
 //to print the distance the ultrasonic sensor is detecting when it finds an object

 if (distance <= 40) {
  LCD.setCursor(0,0);
  LCD.print("Intruder       ");
  digitalWrite(buzzer, HIGH);
  digitalWrite(ledPin, HIGH);
  //saying if the device detects an object in a distance lower than 40 cm it will alarm you that there is an inrtuder. The lcd display will say intruder.
  }
    else 
  {
    LCD.setCursor(0,0);
    LCD.print("             ");
    digitalWrite(buzzer, LOW);
    digitalWrite(ledPin, LOW); 
    // and if there is no object in a distance lower than 40 cm it will say to keep the buzzer and led blank. There will also be no words printed on the lcd display
  }

Credits

rajun10

rajun10

0 projects • 2 followers

Comments