Hardware components | ||||||
![]() |
| × | 3 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
| × | 3 | ||||
![]() |
| × | 3 |
We started this project with a dream; a dream of freedom and a world free of fear. The worst fear in this world is feeling insecure or unsafe in your own home. We have made this feeling a thing of the past.
With this project, you can set up anywhere in your home and without any supervision, this sentry gun will protect your home from any intruder, with extreme prejudice. All while keeping you informed from a safe distance and giving you time to call the police and prepare yourself.
// 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 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;
}
}
// 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);
}
}
Comments