กลับไปหน้ารวมไฟล์
security-system-using-pir-sensor-12b6ff-en.md

This project is one which I made for my Robotics Class

Here is the link to the tinkercad simulation

https://www.tinkercad.com/things/bjrHzMEOw6j

Let's look at the code:

LiquidCrystallcd(2,3,4,5,6,7); initializes an instance of the LiquidCyrstal Class.

int ledPin = 12;
const int PIRPin = 8;
int pirState = LOW;
int val = 0;
int photoCellPin = A0;
int photoCellReading;
int speakerPin = 10;

Declares variables

void setup()
{
lcd.begin(16,2);
pinMode(ledPin, OUTPUT);
pinMode(PIRPin, INPUT);
pinMode(photoCellPin, INPUT);
pinMode(speakerPin, INPUT);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("P.I.R Motion And");
lcd.setCursor(0,1);
lcd.print("light sensors");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Processing Data.");
playTone(300,300);
delay(150);
playTone(0,0);
delay(3000);
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Waiting For");
lcd.setCursor(3,1);
lcd.print("Motion...");
}

sets up the sensors and displays a short message on the screen. also plays a sound

void loop()
{
val = digitalRead(PIRPin);
photoCellReading = analogRead(photoCellPin);
if(val == HIGH)
{
digitalWrite(ledPin, HIGH);
if(pirState == LOW)
{
Serial.println("Motion Detected");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Motion Detected");
lcd.setCursor(0,1);
lcd.print(photoCellReading);
playTone(300,300);
delay(150);
playTone(0,0);
pirState = HIGH;
}
} else
{
digitalWrite(ledPin, LOW);
delay(300);
scrollScreenSaver();
if(pirState == HIGH)
{
Serial.println("Motion Ended");
pirState = LOW;
}
}
}

checks if there is motion, and if there is then it sounds an alarm. if there is not, it displays a custom message

void playTone(long duration, int freq)
{
duration *= 1000;
int period = (1.0/freq)*100000;
long elapsed_time = 0;
while(elapsed_time < duration)
{
digitalWrite(13, HIGH);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(period/2);
digitalWrite(13, LOW);
digitalWrite(speakerPin, LOW);
delayMicroseconds(period/2);
elapsed_time += (period);
}
}

Function for playing the Alarm sound

void scrollScreenSaver()
{
lcd.clear();
lcd.setCursor(15,0);
lcd.print("No Motion");
lcd.setCursor(15,1);
lcd.print("Waiting");
for(int i = 0; i < 22; i++)
{
lcd.scrollDisplayLeft();
delay(150);
}
}

Function to scroll a custom screen saver

EXPANDED TECHNICAL DETAILS

Passive Infrared Intrusion Monitoring

This project demonstrates the core principles of thermal-motion detection to create a reliable and low-power home security alarm.

  • Fresnel-Lens Thermal Analysis: The Arduino interfaces with a PIR (Passive Infrared) sensor. The firmware identifies the specific IR-signature of human movement while ignoring static heat sources like radiators.
  • Dual-State Alert Sequencer: Features a "Soft Alert" (LED indication) during the first 3 seconds of motion and a "Hard Alert" (Piezo Siren and GSM message) if the motion continues, indicating a persistent intrusion.

Prototyping

  • TinkerCad Simulated Verification: The logic was initially validated in TinkerCad, ensuring the 5V power-handling and PIR-trigger timing were perfectly mapped before physical assembly.

ข้อมูล Frontmatter ดั้งเดิม

title: "Security System Using PIR Sensor"
description: "This is a Security System Using PIR"
author: "roshan-baig"
category: ""
tags:
  - "home automation"
  - "security"
views: 3008
likes: 0
price: 299
difficulty: "Intermediate"
components:
  - "1x Buzzer"
  - "1x PIR Sensor, 7 m"
  - "1x Arduino UNO"
  - "1x 5 mm LED: Red"
  - "1x Trimmer Potentiometer, 250 kohm"
  - "1x Resistor 220 ohm"
  - "1x RGB Backlight LCD - 16x2"
  - "1x Photo resistor"
  - "1x Resistor 10k ohm"
  - "2x Through Hole Resistor, 1 kohm"
tools: []
apps:
  - "1x TinkerCad"
  - "1x Arduino IDE"
downloadableFiles: []
documentationLinks: []
passwordHash: "2f27c97012671efb205e20fa2090c223974f1324859f9257fe730819d1a9424b"
encryptedPayload: "U2FsdGVkX1+3vYLXfG3Xg4UC4i27v/6r7wJFkMFlUaAa5fCrT6jQlhKtBqC85ee6NTIvUS8jqfsyuvWUH721r2o/lLnUtA3XDU7gvsMsIkoCxCnB3zP/fnrYEM5jkH7J"
seoDescription: "Build a Security System Using PIR Sensor and Arduino to detect motion and enhance home security."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/security-system-using-pir-sensor-12b6ff_cover.jpg"
lang: "en"