Arduino 101: Security alarm using a PIR(Passive Infrared Module) Sensor

in #utopian-io6 years ago (edited)

What Will I Learn?

Write here briefly the details of what the user is going to learn in a bullet list.

  • You will know about the PIR
  • You will learn how the sensor works and how to use it with the arduino mega board.
  • You will learn the programming code used to make this sensor work.

Requirements

  • Arduino Mega

Untitled.png

Image Source

  • PIR(Passive Infrared Module) Sensor

Untitled.png

Image Source

  • GSM Module SIM900

Untitled.png

Image Source

  • Servo Motor

Untitled.png

Image Source

  • Jumper wires

Untitled.png

Image Source

  • Computer/Laptop

Untitled.png

Image source

  • Software

Untitled.png

Knowledge

  • Basic electronics and programming

Difficulty

  • Intermediate

Project Description

  • This project uses a PIR(Passive Infrared Module) Sensor that is connected to the arduino mega board. The PIR sensor is a sensor that detects movement from a range of 7 meters from its 120 degrees looking angle. Once it detects a movement, the PIR sensor will send an input signal to the Arduino UNO. The Arduino UNO is a programmable microcontroller.

Components Description

Arduino Mega- is a microcontroller board based on the ATmega2560 (datasheet). It has 54 digital input/output pins (of which 15 can be used as PWM outputs), 16 analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button.

PIR sensor-is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. They are most often used in PIR-based motion detectors.

GSM Module SIM900- is a GSM/GPRS-compatible Quad-band cell phone, which works on a frequency of 850/900/1800/1900MHz and which can be used not only to access the Internet, but also for oral communication (provided that it is connected to a microphone and a small loud speaker) and for SMSs.

Servo motor -is a rotary actuator or linear actuator that allows for precise control of angular or linear position, velocity and acceleration.

Tutorial Contents

Step 1: Gather the Parts

Untitled.png

Step 2-Construct the circuit

Untitled.png

Connect the Sources

-Connect the 5V pin of the arduino mega board into the Input of the PIR. The connections here are horizontally connected making it an ideal for the sources.

-Connect the GND pin of the arduino mega board into the Ground slot of the PIR but make sure not to place them together to avoid shorting the arduino board.

Step 3: Programming

  • Connect the arduino mega board to the computer using the USB type A to B cable.

Untitled.png

  • Once connected, open the Arduino IDE and click Tools > Board: > then select the Arduino/Genuino Uno.

Untitled.png

void setup() {
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int x = 0;
int y = 0;
int pirPin = 34;
int pirPin2 = 33;
int ledPin = 13;
#include <Servo.h>
Servo myservo;
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;
Servo myservo7;
Servo myservo8;
Servo myservo9;
#include <Sim800l.h>
#include <SoftwareSerial.h>
Sim800l Sim800l;
String text;
uint8_t index;
bool error;
char* textA;
char* textB;
char* textC;
char* textD;
char* textE;
char* textF;
char* textG;
char* textH;
char* textI;
char* textJ;
char* textK;
char* textL;
char* textM;
char* textN;
chartexx;
char number;
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(pirPin2, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(pirPin, LOW);
digitalWrite(pirPin2, LOW);
Serial.begin(9600);
Sim800l.begin();
error=Sim800l.delAllSms(); number="09122792762";
Serial.print("calibrating sensor ");
textC="calibrating sensor";
error=Sim800l.sendSms(number,textC);
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
textB="Sensor Active";
error=Sim800l.sendSms(number,textB);
}
void loop()
{
index=1;
text=Sim800l.readSms(index);
Serial.println(text);
error=Sim800l.delAllSms();
if (text.indexOf("AIN")!=-1){
SENSING();
}
if (text.indexOf("AOUT")!=-1)
{
SENSING2();
}
if (text.indexOf("D1Open")!=-1){
door1open();
textD="door 1 open";
error=Sim800l.sendSms(number,textD);
if (text.indexOf("D1Close")!=-1){
door1close();
textE="door 1 close";
error=Sim800l.sendSms(number,textE);
}
if (text.indexOf("D2Open")!=-1){
door2open();
textF="door 2 open";
error=Sim800l.sendSms(number,textF);
}
if (text.indexOf("D2Close")!=-1){
door2close();
textG="door 2 close";
error=Sim800l.sendSms(number,textG);
if (text.indexOf("D3Open")!=-1){
door3open();
textH="door 3 open";
error=Sim800l.sendSms(number,textH);
}
if (text.indexOf("D3Close")!=-1){
door3close();
textI="door 3 close";
error=Sim800l.sendSms(number,textI);
if (text.indexOf("D4Open")!=-1){
door4open();
textJ="door 4 open";
error=Sim800l.sendSms(number,textJ);
if (text.indexOf("D4Close")!=-1){
door4close();textK="door 4 close";
error=Sim800l.sendSms(number,textK)
}
void SENSING(void)
{
texx="Inside sensor activated";
number="09122792762";
error=Sim800l.sendSms(number,texx);
delay(1000);
if(digitalRead(pirPin) == HIGH){
delay (2000);
textA="intruder dettected house in lockdown mode";
number="09122792762";
error=Sim800l.sendSms(number,textA);
delay(1000);
door1close();
door2close();
door3close();
door4close();
delay(10000);
}
if(digitalRead(pirPin) == HIGH){
delay (1000);
textA="intruder dettected house in lockdown mode";
number="09122792762";
error=Sim800l.sendSms(number,textA);
delay(1000);
door1close();
door2close();
     door3close();
     door4close();
   delay(10000);
}
}
void SENSING2(){
textL="Outside sensor activated";
error=Sim800l.sendSms(number,textL);
delay(1000);
 if(digitalRead(pirPin2) == HIGH){
   textM="intruder detected house in lockdown mode";
error=Sim800l.sendSms(number,textM); 
     Serial.println("intruder dettected");
     Serial.println("house in lockdown mode");
     delay(2000);
      door1close();
      
      door2close();
      
      door3close();
      
      door4close();
      
    delay(10000);
  }
   
  
 if(digitalRead(pirPin2) == HIGH){
   textM="intruder detected house in lockdown mode";
error=Sim800l.sendSms(number,textM); 
     Serial.println("intruder dettected");
     Serial.println("house in lockdown mode");
     delay(2000);
      door1close();
      
      door2close();
      
      door3close();
      
      door4close();
      
    delay(10000);
  }
}
void door1open()
{
     myservo.attach(22);
     myservo1.attach(23);
    myservo1.write(0);
    delay (500);
    myservo.write(180);
    delay(500);
    myservo.detach();
     myservo1.detach();
}
void door1close()
{
     myservo.attach(22);
     myservo1.attach(23);
    myservo.write(0);
    delay (500);
    myservo1.write(180);
    delay(500);
    myservo.detach();
     myservo1.detach();
}
void door2open()
{
myservo2.attach(24);
myservo3.attach(25);
myservo3.write(0);
delay (500);
myservo2.write(180);
delay(500);
    myservo2.detach();
     myservo3.detach();
}
void door2close()
{
myservo2.attach(24);
myservo3.attach(25);
myservo2.write(0);
delay (500);
myservo3.write(180);
delay(500);
    myservo2.detach();
     myservo3.detach();
}
void door3open()
{
myservo4.attach(26);
myservo5.attach(27);
myservo5.write(0);
delay (500);
myservo4.write(180);
delay(500);
myservo4.detach();
myservo5.detach();
}
void door3close()
{
myservo4.attach(26);
myservo5.attach(27);
myservo4.write(0);
delay (500);
myservo5.write(180);
delay(500);
myservo4.detach();
myservo5.detach();
}
void door4open()
{
myservo7.attach(28);
myservo6.attach(29);
myservo6.write(0);
delay (500);
myservo7.write(180);
delay(500);
myservo7.detach();
myservo6.detach();
}
void door4close()
{
myservo7.attach(28);
myservo6.attach(29);
myservo7.write(0);
delay (1000);
myservo6.write(180);
delay(500);
myservo7.detach();
myservo6.detach();
}
}
void loop() {
// put your main code here, to run repeatedly:
}

Curriculum

This is my first contribution in utopian at the same time first contribution in Tutorials



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved because it is a duplicate. It is very similar to a contribution that was already accepted here.

You can contact us on Discord.
[utopian-moderator]

Hey @rufans, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Congratulations @furrychix! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Do not miss the last post from @steemitboard:

Carnival Challenge - Collect badge and win 5 STEEM
Vote for @Steemitboard as a witness and get one more award and increased upvotes!

Congratulations @furrychix! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

Use your witness votes and get the Community Badge
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.27
TRX 0.13
JST 0.032
BTC 62983.95
ETH 2962.52
USDT 1.00
SBD 3.58