Ethan WatrudJacob Longuillo
Published

MEGR 3171 IOT Motion Sensor

A motion-sensing light system that has 2-way communication between 2 Particle Argons and uploads data to ThingSpeak.

IntermediateShowcase (no instructions)2 hours96
MEGR 3171 IOT Motion Sensor

Things used in this project

Hardware components

Argon
Particle Argon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
LED (generic)
LED (generic)
×2
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Male/Male Jumper Wires
×7
Male/Female Jumper Wires
Male/Female Jumper Wires
×3
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×2

Software apps and online services

ThingSpeak API
ThingSpeak API
Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

LED Circuit

Motion Sensor Circuit

ThingSpeak Graph

Code

LED Light Argon Code

C/C++
int led = D7;



void setup() {

pinMode(led, OUTPUT);
digitalWrite(led, LOW);

Particle.subscribe("ewatrud22", myHandler, "43001b001951353337343731");


}

void myHandler(const char *event, const char *data)
{
if (strcmp(data,"1")==0) {
  digitalWrite(led, HIGH);
  Particle.publish("jlonguil","1");

  }else if (strcmp(data,"0")==0) {
      digitalWrite(led, LOW);

  
}}

Motion Sensor Argon Code

C/C++
int inputPin = D4;              
int ledPin = D7;                
int pirState = LOW;             
int val = 0;
int ledout = D6;
int calibrateTime = 10000;      

void setup()
    {
        pinMode( ledPin, OUTPUT );
        pinMode(inputPin, INPUT);   
        pinMode(ledout, OUTPUT);
        digitalWrite(ledout, LOW);
        Particle.subscribe("jlonguil", myHandler, "43001b001951353337343731");
    }

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

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

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

void reportTheData() 
    {
        if (val == HIGH) 
            {
                Particle.publish("ewatrud22", "1"); 
                pirState = HIGH;
                setLED( pirState );
                delay(60000);
            } 
            
        else 
            {   Particle.publish("ewatrud22","0");
                pirState = LOW;
                setLED( pirState );
                delay(10000);
            }
    }

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

void myHandler(const char *event, const char *data)
    {
        digitalWrite(ledout, HIGH);
        delay(5000);
        digitalWrite(ledout, LOW);
    }

Credits

Ethan Watrud

Ethan Watrud

1 project • 0 followers
Jacob Longuillo

Jacob Longuillo

1 project • 0 followers

Comments

Add projectSign up / Login