Joe ConnersJosh Madsen
Published

You've Got the Power! (or not... )

The DIY solution that provides safety in the event of a power outage.

BeginnerFull instructions provided100
You've Got the Power! (or not... )

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×2
Resistor 100 ohm
Resistor 100 ohm
×2
Elegoo KY-018 Photoresistor Module
×1
Elegoo KY-011 Two Color LED Module
Any LED will do, this was chosen for convenience. In practice a more powerful LED is preferable.
×1
3.7V, 1800mAh Li-Ion Polymer Battery
×2

Story

Read more

Schematics

Wall Module

Wall Module

Light Module

Light Module

Code

Wall Module

C/C++
This detects and monitors wall voltage. If wall voltage falls below threshold, sends a signal to activate power the photoresistor module and LED. Receives confirmation LED is on.
int Power = A5; //Voltage output from VUSB

int Indicator = D7; //Indicator that remote light is on

int PowerOut = 100; //Low Voltage Threshold

int volts = 0; //Current Voltage


void setup() {

pinMode(Power, INPUT);
pinMode(Indicator, OUTPUT);

}

void loop() {
    
Particle.subscribe("Light", Indication); //subscribes to emergency light in order to show light on/off condition
    
delay(1000);

volts=analogRead(Power); //update volts

if (analogRead(Power)<PowerOut) {
    
    delay(500);
    Particle.publish("The Power is Out", Time.format(Time.now(), "%I:%M%p"), 60, PUBLIC); //power outage notification with time data
    delay(500);
    Particle.publish("volts", String(volts)); //volts publish for adafruit
    delay(10000);

}
else {
    
    Particle.publish("volts", String(volts)); //volts publish for adafruit
    delay(10000);
}
}

void Indication(const char *event, const char *data) { //subscribe to emergency light module
    if(strcmp(data,String(1))==0) {
        digitalWrite(Indicator, HIGH);
    }
    else if(strcmp(data,String(0))==0) {
        digitalWrite(Indicator, LOW);
    }
    else {
    }
}

Light Module

C/C++
Receives instruction from Wall Module. Turns on LED in low light situations when the wall module is on battery power. Publishes light status. Sends light status to wall module.
int Light = D0;

int Power = D1;

int Sensor = A2;

void setup() {

pinMode(Light, OUTPUT);
pinMode(Power, OUTPUT);
pinMode(Sensor, INPUT);
pinMode(D7, OUTPUT); //hardware issue that turns D7 HIGH at boot, this corrects the issue
digitalWrite(Power, LOW);
}

void loop(){
    
delay(1000);

Particle.subscribe("The Power is Out", Emergency); //Power outage notification
}

void Emergency(const char *event, const char *data) {

digitalWrite(Power, HIGH);

if (analogRead(Sensor)<700) {
    
    digitalWrite(Light, HIGH); //light on
    Particle.publish("Light", String(1));
    delay(3000);
}
else {
    
    digitalWrite(Light, LOW); //light off
    Particle.publish("Light", String(0));
    delay(3000);
}
}

Credits

Joe Conners
1 project • 0 followers
Josh Madsen
1 project • 0 followers

Comments