Ashley SpicerDylan Appleyard
Published © GPL3+

Motion Detector Alert System

The purpose of this project is to detect motion at set locations and provide a light&/or a buzzer notification to alert the user.

BeginnerFull instructions provided2 hours300
Motion Detector Alert System

Things used in this project

Hardware components

Argon
Particle Argon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Buzzer
Buzzer
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
Rotary Potentiometer, 10 kohm
Rotary Potentiometer, 10 kohm
×1
Breadboard (generic)
Breadboard (generic)
×2
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×2
Jumper wires (generic)
Jumper wires (generic)
×26

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Google Sheets
Google Sheets
https://docs.google.com/spreadsheets/d/13J5VMuyPMXG020TMau5VeLzELuW9Vnb82z4zOLGOaFI/edit?usp=sharing
Fritzing
Maker service
IFTTT Maker service

Story

Read more

Schematics

Flow Chart

This is the overall flowchart of our Instrumentation project design, Each step in the process of our project can be found here. The flowchart shows how all of the sensors, charts, and notifications interact with each other through the particles argons and the code that is provided below.

PIR Motion Sensor and Passive Buzzer Circuit Diagram

Both the Buzzer and Motion Sensors have a positive and negative terminal that are connected to the power and ground rails. They each also have 1 wire connected to a digital pin. The motion sensor sends a signal through the D2 pin and the buzzer receives a signal through the D3 pin.

LCD Screen Circuit Diagram

The LCD Screen is used to show a message when motion is detected by the motion sensor. The potentiometer is used to adjust the backlight of the LCD screen so you can see the message.

Code

Motion and Buzzer

C/C++
This part of the code senses motion and triggers a buzzer sound as a result. This code also sends data into a google sheets to document each time instance of detected motion.
// This #include statement was automatically added by the Particle IDE.
#include <JsonParserGeneratorRK.h>

// This #include statement was automatically added by the Particle IDE.
#include <LiquidCrystal.h>

int sensorPin = 2;                //Sensor pin
int buzzerPin = 6;                //Buzzer pin
int motionsensorInput = 0;        //This reads the motion status
int temp = 0;

void setup() {
pinMode(D2, INPUT);     //sets the motion sensor pin as an input
pinMode(D6, OUTPUT);    //sets the passive buzzer to be an output

delay(10000); //Calibration Delay for Motion Sensor
}

void loop() {
 motionsensorInput = digitalRead(D2);       //reads the input value
 if (motionsensorInput == HIGH){	        //checks to see if there is an input. If there is: the led turns on, the argon publishes an event to trigger IFTTT, waits 5 seconds, then stops buzzer noise.
    beep();                                 //beep loop played for sound            
    createEventPayload(motionsensorInput);  //event for reading motion to input in google sheets
    Particle.publish("IntruderAlert","Warning", PRIVATE);   
    delay(1000);
    digitalWrite(D6, LOW); 
    
  }
  else {
      digitalWrite(D6, LOW);
      delay(1000);
  }
}

//code for passive buzzer beeps
void beep() {
    tone(D6, 3500, 50);
    tone(D6, 2000, 50);
    tone(D6, 3500, 50);
    tone(D6, 2000, 50);
    delay(50);
}

//Following code is for formatting into google sheets
void createEventPayload(int motionInput)
{
 JsonWriterStatic<256> jw;
 {
   JsonWriterAutoObject obj(&jw);

   jw.insertKeyValue("Motion", motionInput);
 }
  Particle.publish("env-vals", jw.getBuffer(), PRIVATE);
}

LCD Screen

C/C++
This code pulls information from the Motion and Buzzer code to display alerts to an LCD screen and also by phone notification based on motion readings.
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_LiquidCrystal.h>
#include "application.h"
#include "Particle.h"


//int RS = D8; //Integers/Commections from the LCD screen to the argon
//int E = D7;
//int D4 = D6;
//int D5 = D5;
//int D6 = D4;
//int D7 = D3;
LiquidCrystal lcd(D8,D7,D6,D5,D4,D3); //Initializing the connections for the LCD screen with the outputs of the argon


void setup() {
        lcd.begin(16,2); // Setting up the LCD screen display
        lcd.setCursor(3,0); // Moving the cursor to row 1 and in the middle
        lcd.print ("Booting Up");
        delay(5000); // 5 second delay in the code so you can see the display message
        lcd.clear(); // clearing the screen for other inputs
        Particle.subscribe("IntruderAlert",screenprint);
    
}
void loop() {
    lcd.setCursor(6,0); // Moving the cursor to row 1 and in the middle
        lcd.print("Armed"); // Displaying the string Armed
        lcd.setCursor(4,1); // Moving the cursor to row 2 of the screen and to the left a little more
        lcd.print("Alarm On"); // Displaying the string Alarm On
}

void screenprint(const char *event, const char *data) {
        delay(1000); //1 second delay
        lcd.clear(); //Clearing the screen for new message to be displayed
        delay(1000); // 1 second delay
        lcd.setCursor(4,0); // Moving the cursor to row 1 on the LCD screen
        lcd.print("Warning"); // Displaying the string Warning
        lcd.setCursor(0,1); // Moving the LCD screen cursor to another position
        lcd.print("Motion Detected"); // Displaying the string Motion Detected
        delay(2000); // 2 second delay in the code so you can see the display message
        lcd.clear(); // clearing the screen for other inputs
        delay(1000);
        
}

Credits

Ashley Spicer

Ashley Spicer

1 project • 0 followers
Dylan Appleyard

Dylan Appleyard

1 project • 1 follower

Comments

Add projectSign up / Login