Garrett ColeyBrianna Plaster
Published

Light Pager

This project uses two Particle Photons, with two way communication. These photons are used to gain the attention of the other user.

IntermediateShowcase (no instructions)4 hours300
Light Pager

Things used in this project

Hardware components

Photon
Particle Photon
×2
Jumper wires (generic)
Jumper wires (generic)
×8
LED (generic)
LED (generic)
×2
Through Hole Resistor, 4.7 kohm
Through Hole Resistor, 4.7 kohm
×2
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×2
Breadboard (generic)
Breadboard (generic)
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
fritzing
Maker service
IFTTT Maker service
Google Sheets
Google Sheets

Story

Read more

Schematics

Photon 1

Photon 2

Code

Particle 1 code

C/C++
This sends a message from the first particle to the second.
//Defines pins to make reading code easier

int ledPin = D7;
int led = D6;
int button = D0;
int val = 0;                   
int calibrateTime = 10000;   
int pirState = LOW;  


void setup() {
    //Set Pin Modes 
    pinMode(led, OUTPUT);
    pinMode(ledPin, OUTPUT);
    pinMode(button, INPUT);

    //Default outputs to LOW
    digitalWrite(led, LOW);
    digitalWrite(ledPin, LOW);

    Particle.subscribe("Runchickenrun789", myHandler);
}
void myHandler(const char *event, const char *data) {
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
}

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


void readTheSensor() {
  val = digitalRead(button);
}
bool calibrated() {
  return millis() - calibrateTime > 0;
}
void reportTheData() {
  
  if (val == HIGH) {
   
    if (pirState == LOW) {
     
      Particle.publish("Runchickenrun780", NULL, PUBLIC); 
      
      pirState = HIGH;
      setLED( pirState );
    }
  } else {
    if (pirState == HIGH) {
     
      pirState = LOW;
      setLED( pirState );
    }
  }
}
void setLED( int state )
{
  digitalWrite(ledPin, state );
}

Particle 2 code

C/C++
This sends a message from the second particle to the first.
//Defines pins to make reading code easier

int ledPin = D7;
int led = D6;
int button = D0;
int val = 0;                   
int calibrateTime = 10000;   
int pirState = LOW;  


void setup() {
    //Set Pin Modes 
    pinMode(led, OUTPUT);
    pinMode(ledPin, OUTPUT);
    pinMode(button, INPUT);

    //Default outputs to LOW
    digitalWrite(led, LOW);
    digitalWrite(ledPin, LOW);

    Particle.subscribe("Runchickenrun780", myHandler);
}
void myHandler(const char *event, const char *data) {
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
}

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


void readTheSensor() {
  val = digitalRead(button);
}
bool calibrated() {
  return millis() - calibrateTime > 0;
}
void reportTheData() {
  
  if (val == HIGH) {
   
    if (pirState == LOW) {
     
      Particle.publish("Runchickenrun789", NULL, PUBLIC); 
      
      pirState = HIGH;
      setLED( pirState );
    }
  } else {
    if (pirState == HIGH) {
     
      pirState = LOW;
      setLED( pirState );
    }
  }
}
void setLED( int state )
{
  digitalWrite(ledPin, state );
}

Credits

Garrett Coley

Garrett Coley

1 project • 0 followers
Brianna Plaster

Brianna Plaster

0 projects • 0 followers

Comments

Add projectSign up / Login