Eric LongGrayson Pope
Published

We'll Leave The Light On For You

Never forget to leave a light on before leaving your house, giving people the idea that someone may be there.

BeginnerFull instructions provided6 hours1,214
We'll Leave The Light On For You

Things used in this project

Story

Read more

Schematics

Photon 1 Diagram

Photon 2 Diagram

Photoresistor

This graph shows a series of turning on and off our main lights, in order to display a visual of our code working with the photoresistor to send a HIGH or LOW signal where HIGH equals a binary value of 1 and LOW equals a binary value of 0. A HIGH signal being sent turns on our small light, and a LOW signal being sent turns off the small light.

Code

Main Photon

Arduino
int led = D0; 
int photoresistor = A0; 
int power = A5; 
int analogvalue; 
void setup() {

    
    pinMode(led,OUTPUT); 
    pinMode(photoresistor,INPUT);  
    pinMode(power,OUTPUT); 
    digitalWrite(power,HIGH);
    Particle.variable("analogvalue", &analogvalue, INT);

}


void loop() {
  analogvalue = analogRead(photoresistor);
  delay(50);
  if (analogRead(photoresistor)< 70)
  {
    digitalWrite (led, HIGH);
    Particle.publish("your-event-here","HIGH",60,PUBLIC);
    delay(2000);
  }
  else
  {
    digitalWrite (led,LOW);
    Particle.publish("your-event-here","LOW",60,PUBLIC);
  }
  
}

Receiver Photon

Arduino
int led = D0; 
void setup() {
    pinMode(led,OUTPUT); 
    digitalWrite(led,LOW);
    Particle.subscribe("your-event-here",myHandler);
    }
void myHandler(const char *event, const char *data){
   if (strcmp(data,"HIGH")==0) {
    digitalWrite(led,HIGH);
}
    if(strcmp(data,"LOW")==0){
    digitalWrite(led,LOW);
   }
}

Credits

Eric Long

Eric Long

1 project • 0 followers
Grayson Pope

Grayson Pope

1 project • 0 followers

Comments