Jackson WhiteRuben Castillo-Martinez
Published © GPL3+

Motion Activated Light Communication Device

Uses 2 Particle Argons to control a motion sensor, switch, and two lights that communicate with each other. For MEGR 3171 IOT Project.

BeginnerFull instructions provided2 hours175
Motion Activated Light Communication Device

Things used in this project

Hardware components

Argon
Particle Argon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Slide Switch
Slide Switch
×1
LED (generic)
LED (generic)
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2
Jumper wires (generic)
Jumper wires (generic)
×11

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Switch Schematic

Very simple, power is given from the vusb pin meaning about 4.5-5V is given. This is wired to a switch which then goes to D7 pin and the LED module is wired from D4 pin to ground. Power goes to D7 to ensure the user they are activating the switch. The vusb pin is used in hopes of making the LED module brighter

Motion Sensor Schematic

Power is given from the vusb pin meaning about 4.5-5V is given. This is wired to the positive rail on the side of the breadboard. Ground is then also wired to the negative terminal of this rail. The PIR motion sensor is powered from here and its output is wired to D7 to see if it is working. The LED module's positive terminal is on pin D4 and its negative is on the ground terminal.

Code

Switch Code

C/C++
Code given to the argon with the switch
int inputPin = D7;              // choose the input pin (for PIR sensor)
int ledPin = D4;                // LED Pin
int pirState = LOW;             // we start, assuming the switch is breaking the circuit
int val = 0;                    // variable for reading the pin status

int calibrateTime = 10000;      

void setup()
{
  pinMode( ledPin, OUTPUT );
  pinMode(inputPin, INPUT);     // declare switch as input
  Particle.subscribe("iot/motion", LEDUP, MY_DEVICES);//allows for communication with other argon
}

void loop()
{

  // in order to keep efficiency up code was copied from motion sensor
  if ( calibrated() )
  {
  // get the data whether the switch is flipped on or off
    readTheSensor();

    // report it out, if the state of the switch has changed
    reportTheData();
  }
}

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

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

void reportTheData() {

  // if the switch is flipped
  // or if its not
  if (val == HIGH) {

    // the current state there is no power going through so switch is breaking the circuit
    // i.e. it's just changed
    // announce this switch by publishing an eent
    if (pirState == LOW) {
      // we have just turned on
      Particle.publish("iot/flipon", "1", PRIVATE);
      //This is the line of code that will send information to the cloud in order for the other argon to recieve it.
      //Its given the value of 1 inorder to tell the receiving argon to turn its LED on
      // Update the current state
      pirState = HIGH;
    }
  } else {
    if (pirState == HIGH) {
      // we have just turned of
       Particle.publish("iot/flipon", "0", PRIVATE);
        //Sends receiving argon the given the value of 0 inorder to tell the receiving argon to turn its LED off
      // Update the current state
      pirState = LOW;
    }
  }
}

void LEDUP(const char *event, const char *data)//Allows this argon to recieve information from the argon with the switch in order to power its own LED on or off
    {
        digitalWrite(ledPin, HIGH);
        delay(2500);
        digitalWrite(ledPin, LOW);
    }

Motion Sensor Code

C/C++
This is the code given to the argon wired with the motion sensor
int inputPin = D7;              // choose the input pin (for PIR sensor)
int ledPin = D4;                // LED Pin
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

int calibrateTime = 10000;      // wait for it to calibrate

void setup()
{
  pinMode( ledPin, OUTPUT );
  pinMode(inputPin, INPUT);     // declare sensor as input
  Particle.subscribe("iot/flip", LEDON, MY_DEVICES); //This is how this argon comunicates with the other by subscribing to the others event
}

void loop()
{

  // if the sensor is calibrated
  if ( calibrated() )
  {
  // get the data from the sensor
    readTheSensor();

    // report it out, if the state has changed
    reportTheData();
  }
}

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

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

void reportTheData() {

  // if the sensor reads high
  // or there is now motion
  if (val == HIGH) {

    // there is no motion
    // i.e. it's just changed
    // announce this change by publishing an eent
    if (pirState == LOW) {
      // we have just turned on
      Particle.publish("iot/motion", "1", PRIVATE);
      //This is the line of code that will send information to the cloud in order for the other argon to recieve it.
      //Its given the value of 1 inorder to tell the receiving argon to turn its LED on
      // Update the current state
      pirState = HIGH;
    }
  } else {
    if (pirState == HIGH) {
      // we have just turned of
       Particle.publish("iot/motion", "0", PRIVATE);
       //Sends receiving argon the given the value of 0 inorder to tell the receiving argon to turn its LED off
      // Update the current state
      pirState = LOW;
    }
  }
}

void LEDON(const char *event, const char *data)//Allows this argon to recieve information from the argon with the switch in order to power its own LED on or off
    {
        digitalWrite(ledPin, HIGH);
        delay(2500);
        digitalWrite(ledPin, LOW);
    }

Credits

Jackson White

Jackson White

1 project • 1 follower
Ruben Castillo-Martinez

Ruben Castillo-Martinez

1 project • 2 followers

Comments