Ryan DixonSam Johnson
Published © GPL3+

Motion Sensor - UNCC MEGR 3171 Fall 2018

Ever wonder if there's someone in you house and possibly drinking your beer? Well then, we have the solution for you!

BeginnerProtip6 hours499
Motion Sensor - UNCC MEGR 3171 Fall 2018

Things used in this project

Hardware components

Photon
Particle Photon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×10
Adafruit SSD1306 OLED Display
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×2
Breadboard (generic)
Breadboard (generic)
×2

Software apps and online services

Maker service
IFTTT Maker service
Particle
ThingSpeak API
ThingSpeak API
Fritzing

Story

Read more

Schematics

Motion Sensor Display Schematic

This is a picture of our OLED Schematic

Motion Sensor Schematic

This shows how to connect pins form the Photon to the Motion sensor for this project

Code

Motion Sensor Code

C/C++
This is the code for the PIR Motion Sensor.
int PIRSensor = D0;
int led = D7;
int var=0;
int last=0;

void setup() 
{
    pinMode(led, OUTPUT);
    Particle.subscribe("LED-OFF", myHandler, "1c0032000e51353338363333");
 
}

void myHandler(const char *event, const char *data)
{
    digitalWrite(led, LOW);
}

void loop() {
    
    var=digitalRead(PIRSensor);
    if((digitalRead(PIRSensor) == HIGH) && (last == LOW))
    {
        digitalWrite(led, HIGH);
        
        // Get some data
        String data = String(var);
        // Trigger the integration
        Particle.publish("Motion", String(data), PRIVATE);
        Particle.publish("Motion-Detected", "Motion Detected In Living Room!");
    }

    last = var;
   
    if(digitalRead(PIRSensor) == LOW)
    {
        last = 0;
    }
    delay(10000);
}

Motion Sensor Display

C/C++
This is the code for the photon connected to the OLCD screen. It will display "Motion Detected" when triggered by an event in the cloud created by the Motion Sensor photon.
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_SSD1306.h>

// use hardware SPI
#define OLED_DC     D3
#define OLED_CS     D4
#define OLED_RESET  D5
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);

int vari = 1;
int tim = 0;

void setup()   
{
    Particle.subscribe("Motion-Detected", myHandler, "230023000547363332363639");
}

void myHandler(const char *event, const char *data)
{
    // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC);

  display.setTextSize(2);       // text size
  display.setTextColor(WHITE); // text color
  display.clearDisplay();
  display.println("MOTION");
  display.println("DETECTED");
  display.display();
  delay(5000);
  
  display.setCursor(0,0);
  display.clearDisplay();
  display.display();
  
  Particle.publish("Motion_occured", NULL, 60, PRIVATE);
  Particle.publish("text", NULL, 60, PRIVATE);
  delay(1000);
  Particle.publish("LED-OFF", "LED should turn off");
}

Credits

Ryan Dixon

Ryan Dixon

1 project • 0 followers
Sam Johnson

Sam Johnson

1 project • 0 followers

Comments

Add projectSign up / Login