advertisement
Facebook
X
LinkedIn
WhatsApp
Reddit

How to build a loadshedding busting emergency light system

Ah Eskom. It may be a month since you last loadshed us but things still aren’t great are they? At least two of the htxt.africa staffers have regular power outages because local grid problems, and with news of gas and hydro shortages coming from our neighbours you could do worse than prepare yourself for more rough times ahead.

You could go off-grid, or build your own solar powered UPS. But we’ve got something simpler here that tackles on of the biggest problems around lack of electricity – a quick hack to build an emergency lighting system using off-the-shelf maker electronics.

If you want the lights to come on when the power goes off, you’ve got a couple of options. You can buy dual use light bulbs with a built in battery back-up, or get a qualified electrician to change your domestic lights to a 12V circuit that can be powered by batteries. But here’s something we put together in the office.

We started by thinking about what also goes off when the power goes down – and realised that the one thing many households leave on all the time, even in this energy conscious era, is their WiFi router. Aha, we thought. That’s good news, because we also have an Intel Edison kit in the office. Edison, if you don’t know, is a hobbiest electronics board that comes with a built-in WiFi radio. If we configure the Edison correctly, it should be able to detect when the router turns off – because the power is out – and turn a back-up lighting circuit on.

Genius, huh?

To built our working prototype we used the following kit:

  • Intel Edison
  • Intel Edison Arduino Breakout board
  • 2 x Micro USB to USB cables
  • 4 x Jumper Cables
  • 1 x 220 Ohm resistor
  • 1 x LED
  • 1 x breadboard

This prototype will turn on a single LED when the WiFi goes down: to take it further we’ll add a relay that can switch on a separate circuit full of 12V lights. Why stop there though? You could also have it trigger a back-up router too.

Everything you'll need to build your own Loadshedding Light
Everything you’ll need to build your own Loadshedding Light

Let’s build a basic circuit

Before we get to the programming we’re going to need to build the circuit that will become the light. You can could solder everything together but until you’re 100% sure everything is working we suggest using a breadboard.

1. Position your breadboard so that the numbers and letter are the right side up.

2. We’re going take our resistor and plug one end into the second female header on the negative pole on the left side of the bread board. Then plug the other end of the resistor a little bit further down. It doesn’t matter how far down you go we’re just creating resistance so that our LED doesn’t experience a surge and pop.

Make sure to leave an input open at the top of the breadboard for a jumper.
Make sure to leave an input open at the top of the breadboard for a jumper.

3. Take one of the jumpers and insert it into the input immediately following the header that you plugged the second end of the resistor into.

4. Now it didn’t matter which headers the resistor was plugged into but for the next steps make sure that your components are all plugged into the same numbered row, for our circuit we’ve chosen row 10.

5. Take the second end of the jumper that was plugged into the hole next to the resistor and plug it into the header numbered 10D.

You can use an row you like just make sure that you use the same row from here on out.
You can use an row you like just make sure that you use the same row from here on out.

6. Take your LED and plug the negative (this is the shorter leg of the LED) end into the header labelled 10E.

7. Take the positive (this is the longer leg of the LED) and plug it into the header marked 10F.

Now we have a light for our Loadshedding Light.
Now we have a light for our Loadshedding Light.

8. Finally take a jumper and plug one end into hole 10J and the other end into a header in the positive channel of the bread board. We used one in line with the rest of our circuit.

9. We now have a circuit on our breadboard but we still need to connect it to the Arduino breakout. To do this we’re going to use the two remaining jumper cables.

Our almost complete circuit.
The almost complete circuit.

10. Take one jumper cable and plug it into the first header in the negative channel that we plugged the resistor into earlier. Take the second jumper cable and plug one end into the positive channel that the other end of the LED is connected to.

The only thing you should still have is the Edison attached to breakout board.
The only thing you should still have is the Edison attached to breakout board.

11. Next take the jumper coming from the negative channel and plug it into Digital Pin 8 header on the Arduino breakout board.

Take note of the pin you use, you'll need this for programming
Take note of the pin you use, you’ll need this for programming

12. Take the jumper coming from the positive channel and plug it into the Digital ground (GND) pin.

With this connection we now have a full circuit.
With this connection we now have a full circuit.

13. We now have a complete circuit that uses the Intel Edison as the switch. We recommend you use the Blink test we used in the previous tutorial to test that your circuit is working, just make sure to change the LED pin from 13 to 8 to account for the new pin your LED is plugged into. If for some reason your LED doesn’t blink check that your LED is plugged into the breadboard correctly.

Let’s write some code

With this breakout board, Edison is fully Arduino compatible. So we’re going to use the Arduino IDE for this project because it has access to all the C++ libraries we need and the coding is dead simple. If you would like to familiarise yourself with the language before we begin go right ahead.

1. Before we begin we need to tell the Edison which library it should be referencing our commands from. We’ll be using the native WiFi library in the Edison as well as the SPI library.

#include <WiFi.h>
#include <SPI.h>

 2. Next, declare what elements will be used in the code. To start off we’ll declare the WiFi status. Since we don’t know if the WiFi will be witched on or off when we start the sketch we’ll set the WiFi status to Idle.

3. After we’ve set the WiFi status to Idle we’ll want to set the pin that our LED is plugged into. Since we know that pin 13 is an LED anyway we’ll be using a different pin: in this case, pin 8.

4. Seeing as we’re building a WiFi detecting light we’ll need to give the Edison access to the WiFi network, we input our WiFi network’s name in the SSID and the password in the Pass field. This must be done at the start of the sketch so that the code is able to connect to the WiFi network everytime it loops.

int status = WL_IDLE_STATUS;
int led1 = 8;
char ssid[] = "YourWifiSSIDHere";
char pass[] = "YourPasswordHere";

5. Setup is quite simple and uncomplicated. We’ll set the serial mode to 9600 bits per second and set the LED pin to as an output. This will make sure that when we tell the pin to write it will switch on and not, for example try and draw power from the LED.

void setup(){
Serial.begin(9600);
pinMode(8, OUTPUT);}

7. We start off the loop code by telling the Edison to try connecting to the Wifi network we specified at the start of our code. If the Edison is able to connect to the Wifi network the code will write LOW to the LED meaning that it will be switched off. When a Wifi connection is not possible the code will write HIGH to the LED, switching it on.

void loop() {
status = WiFi.begin(ssid, pass);
if (status != WL_DISCONNECTED)
digitalWrite(8, HIGH);
delay (100);
status = WiFi.begin (ssid, pass)
if (status = WL_CONNECTED)
digitalWrite (8, LOW);
delay (100);
}

8. You may notice that the WiFi.begin command is included twice. We have done this so that a connection request is sent each time even when a result is achieved. This is to ensure that the light switches off when the power is restored, and your WiFi boots up.

Click to enlarge this image and see the full code.
Click to enlarge this image and see the full code.

9. Once you’ve done this Verify your code to make sure the syntax and commands are correct. Depending on your PC this could take a while so don’t be alarmed if it looks like the application has stalled, it hasn’t its just working.

10. Once the code has been verified you should get a “Done Compiling” message and a summary of the size of your sketch.

If you see this message your code is ready to be deployed.
If you see this message your code is ready to be deployed.

11. Finally, click upload and your code should start being deployed to the Edison. Once that is done you should get a “Transfer Complete” message. Wait a few seconds for the Edison to run the code and that is it.

Your Loadshedding Light is ready for use.

Yay! We have Wifi!
Yay! We have WiFi!
And there goes the Wifi, but at least we have a light now.
And there goes the WiFi, but at least we have a light now.

We have just used a light to tell us when the power is off but you could easily replace the light with a sensor that when activated uses the connectivity in the Edison to send you a notification. An even cooler application would be sending you a message when the Wifi drops though that would require that your Wifi constantly has power.

advertisement

About Author

advertisement

Related News

advertisement