Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
Noah Bryantzach brown
Published

Motion Sensor IOT Project

Saving energy and your electric bill, our Motion Sensor Light can give you the piece of mind knowing you are saving energy. and your wallet.

BeginnerFull instructions provided10 hours565
Motion Sensor IOT Project

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
×2
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
AdaFruit

Story

Read more

Schematics

Motion Sensor Circuit Diagram

Light Circuit Diagram

Code

Motion sensor code

C/C++
This is the code that will detect motion from the sensor and send a signal to the other Argon to turn on the light.
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("Noahs_Argon", myHandler);
    }

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

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

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

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

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

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

Light Code

C/C++
This is the code that takes the signal received from the motion sensor Argon and turns on the light
int led = D7;



void setup() {

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

Particle.subscribe("3171", myHandler);


}

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

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

  
}}

Credits

Noah Bryant

Noah Bryant

1 project • 0 followers
zach brown

zach brown

1 project • 0 followers

Comments