J. Mike AndersonDavid HawkinsClayton Sommer
Published © GPL3+

The All-American Automated Home Security System

Shoot first, ask questions later. Supervision optional. (Some assembly required, batteries not included.)

AdvancedFull instructions provided1,121
The All-American Automated Home Security System

Things used in this project

Hardware components

Photon
Particle Photon
×3
Jumper wires (generic)
Jumper wires (generic)
×1
PIR Sensor, 7 m
PIR Sensor, 7 m
×1
0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1
Buzzer, Piezo
Buzzer, Piezo
×1
LED (generic)
LED (generic)
×1
Servo Module (Generic)
×3
Breadboard (generic)
Breadboard (generic)
×3

Story

Read more

Schematics

Motion Sensor

This is the sensor that detects motion and tells the gun to fire.

Sensor Display

This is the sensor screen display that shows the user when motion is detected.

Gun Board

This is the photon board that controlled the gun motion and firing sequences.

Code

Motion Sensor Display Program

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

/*****************************************************************************
Motion Sensor Display

NOTE: This code example requires the Adafruit_SSD1306 library to be included,
so make sure to add it via the Libraries tab in the left sidebar.
******************************************************************************/


#define OLED_DC     D3
#define OLED_CS     D4
#define OLED_RESET  D5
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);

int  y, x, minX;

void setup()   
{
    pinMode(D7, OUTPUT);
    
    Particle.publish("DisplayPowerOn", "On", PUBLIC);

    Particle.subscribe("DickInAVice", getMotionData);
    delay(2000);

    display.begin(SSD1306_SWITCHCAPVCC);

    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setTextWrap(false);
    y = display.height()/3;
    x = display.width();
    minX = -1500;
    display.clearDisplay();
    display.display();
}

void getMotionData(const char *event, const char *data) 
{
    int gaveWarning = false;

    String str = String(data);
    
    digitalWrite(D7, HIGH);

    if(str.equals("Motion Detected"))
    {
        digitalWrite(D7, HIGH);
        display.clearDisplay();
        display.setCursor(x/6, y);
        display.print("*Firing*");
        display.display();
        if(--x < minX)
        {
            x = display.width()*2;
        }
        
        if(gaveWarning == false)
        {
            for(int i=0; i<3; i++)
            {
                tone(D0, 2000, 100);
                delay(200);
            }
            gaveWarning = true;
        }
    } 
    
    if(str.equals("Still"))
    {
        digitalWrite(D7, LOW);
        display.clearDisplay();
        display.display();
    }
}

Motion Sensor Program

C/C++
// Motion Detector Program

int inputPin = D0;
int ledPin = D1;
int pirState = LOW;
int val = 0;

int calibrateTime = 3000;

void setup() 
{
    pinMode(ledPin, OUTPUT);
    pinMode(inputPin, INPUT);
    Particle.subscribe("PowerOn", getPowerData);
}

void getPowerData(const char *event, const char *data)
{
    String Power = String(data);
    
    if (Power.equals("On"))
    {
        digitalWrite(D7, HIGH);
        return;
    }
}

void loop() 
{
    if (calibrated()) 
    {
       readTheSensor();
       reportTheData();
    }
}

void readTheSensor() 
{
    val = digitalRead(inputPin);
}

bool calibrated() 
{
    return millis() - calibrateTime > 0;
}

void setLED(int state) 
{
    digitalWrite(ledPin, state);
}

void reportTheData() 
{
    if (val == HIGH) 
    {
        if (pirState == LOW) 
        {
          Particle.publish("DickInAVice", "Motion Detected", PUBLIC);
          pirState = HIGH;
          setLED(pirState);
        }
    }
    
    else 
    {
        if (pirState == HIGH) 
        {
          Particle.publish("DickInAVice", "Still", PUBLIC);
          pirState = LOW;
          setLED(pirState);
        }
    }
}

void getFiringData(const char *event, const char *data) 
{
    String str = String(data);
    digitalWrite(D7, HIGH);
    if(str.equals("Firing"))
    {
        
    }
    
    if(str.equals("Complete"))
    {
        reportTheData;
    }
    
    if(str.equals("NoMotion"))
    {
        reportTheData;
    }
}

Gun Control and Firing Program

C/C++
// Firing Program

Servo trigger;
Servo turn;

int pos = 0;

void setup()
{
    Particle.subscribe("DickInAVice", getMotionData);
    turn.attach(D3);
    turn.write(0);
    trigger.attach(D2);
    trigger.write(-20);
    pinMode(D7, OUTPUT);
}

void getMotionData(const char *event, const char *data) 
{
    int gaveWarning = false;

    String str = String(data);
    
    digitalWrite(D7, HIGH);

    if(str.equals("Motion Detected"))
    {
        Particle.publish("FiringSequence", "Firing", PUBLIC);
        for (int i = 0; i < 3; i++)
        {
            turn.write(15);
            trigger.write(60);
            digitalWrite(D7, HIGH);
            delay(1000);
            trigger.write(-15);
            digitalWrite(D7, LOW);
            delay(2000);
            turn.write(-15);
            trigger.write(60);
            digitalWrite(D7, HIGH);
            delay(1000);
            trigger.write(-15);
            digitalWrite(D7, LOW);
        }
    Particle.publish("FiringSequence", "Complete", PUBLIC);
    }

    if(str.equals("Still"))
    {
        Particle.publish("FiringSequence", "NoMotion", PUBLIC);
        digitalWrite(D7, LOW);
    }
}

Credits

J. Mike Anderson

J. Mike Anderson

1 project • 0 followers
Mechanical Engineering Student at UNC-Charlotte
David Hawkins

David Hawkins

1 project • 1 follower
Clayton Sommer

Clayton Sommer

1 project • 1 follower

Comments

Add projectSign up / Login