Alexander Smith
Created April 28, 2016

Is My Lamp on?

My room is in the basement. It can get very dark down there at night. I want to know if my lamp is on or off and turn it on and off

Work in progress39
Is My Lamp on?

Things used in this project

Hardware components

Photon
Particle Photon
×1
Photo resistor
Photo resistor
×2
Breadboard (generic)
Breadboard (generic)
×2
Resistor 221 ohm
Resistor 221 ohm
×2

Software apps and online services

Maker service
IFTTT Maker service

Story

Read more

Schematics

the circuit

The twin photoresistors are powered by a common supply and are referenced to a common ground

Code

light detector

Arduino
When queried, this code will determine if the lamp is on or off based on the difference between the voltage across two photoresistors, a reference and one pointed at the lamp
//light detector V1
int lamp = A1;
int ref = A3;
int power = A2;
bool check = false;

void setup() {
    pinMode(lamp,INPUT);
    pinMode(ref,INPUT);
    pinMode(power,OUTPUT);
    Particle.subscribe("smith1695lamp",ask);
    digitalWrite(power,HIGH);
}

void loop() {
    if (check==true){
        if (analogRead(ref)>analogRead(lamp)-5){
            Particle.publish("LampStatus","off",PRIVATE);
        }
        else{
            Particle.publish("LampStatus","on",PRIVATE);
        }
        check = false;
    }
    else{
    }
}

void ask(const char *event, const char *data){
    if (strcmp(data,"ask")==0){
        check = true;
    }
    else{
        check = false;
    }
}

Credits

Alexander Smith

Alexander Smith

1 project • 0 followers

Comments