Lighting control with status - Check for a closed circuit?

Hi All,

I've been playing with Arduino for a little while and managed to get my relay to work from a web browser rather well. So I wont be asking how to connect that up! My next step is to get it actually wired to the lighting in my house.

What I would like to do though is be able to see from a browser the status of the lights, are they on or off. I would then be able to control my home lights from anywhere I have internet and be able to see if I had left a light on in the kitchen for example. This would also eventually apply to some other devices I have that I will control but for now lets stick to the lights.

Each light circuit (in most cases in my home this is a single lamp with a single switch on the wall) will retain the original light switch on the wall, these I will re-wire in a 2 way design that allows the relay or the light switch to control the light. The relay is then to be controlled by the Arduino connected to a PC running a web server. So using the switch or the browser interface I can control the light.

The interface on the web pages will show a top down layout of my home where you can click on each area to turn the light on or off. I intend on making this usable for touch screen devices so I can use my tablet or smartphone to control the house as I carry either with me all the time.

This will obviously require a single output pin for each relay.

With the easy part planned, I now have a number of ideas for checking if the lights are on but cant decide which is best for what I want:

Option 1: Check if the circuit is open or closed - I have no idea how I would attempt this with an Arduino on a mains voltage circuit and think this may require a number of precious I/O pins for each circuit. I don't know how to pass readings to the web server either.

Option 2: Check for a load on the circuit - This seems like the easier option and I think it would only require a single pin for each circuit on the Arduino, and again I'm not sure how to do this and pass the output to the web server.

Option 3: Make the switch also control the Arduino and store the changes in a db - More complicated wiring and means the lights cant be controlled if the Arduino isn't working.

I'm starting this project small with only 4 lights to begin with and will add more on eventually. Im using an Arduino Duemilanove at the moment but the current code appears to work on my nano as well. I am possibly thinking of using a Mega but may just use multiple small units for the different areas. Switching, and Sensing. The web server will eventually be a Linux ITX box but for now its a Windows box with Apache.

I'd appreciate your comments on the above options and if anyone has some suggestions for how I would do option 2 that would be awesome.

Thanks in advance :slight_smile:

Let's assume you won't kill yourself playing with mains wiring. :wink:

If I were attempting that probably the simplest would be to have a voltage detection on the switched side (ie. the wire to the light) isolated via a couple of resistors in series and then into an opto-coupler to decouple the mains from the Arduino.

I will re-wire in a 2 way design that allows the relay or the light switch to control the light

2-way switches actually switch a middle circuit to either the A or B side, so a simple relay might not achieve that. You need a common contact and then both a NO and NC contact.

I can see there might be either a lot of extra mains cable running to where you have the opto-couplers, or alternatively a lot of extra data cables running around (one for each light). The cabling would put me off, personally, plus you need to make sure it is done properly so you don't start a fire.

Perhaps a safer system would be to have an Arduino in each room with a light sensor on it, to indirectly sense if the lights are on. Then you don't have to touch the mains wiring. These could communicate via wireless to a central point. Of course, during the day, it might mistake sunlight for the light being on.

Unless you are well versed with circuit design, keep in mind that interfacing Arduino inputs to household AC circuits is potentially extremely hazardous to people and equipment.

Load sensing (current draw) is the safest method of detecting whether a household circuit is on and active (e.g. the bulb is not burned out), and can be accomplished using a current transformer (CT). A CT is a small transformer that surrounds a current-carrying wire and detects the current flowing in the wire by magnetic coupling. So, no hazardous voltages are presented to an input.

However, the output of a CT is an AC signal (60 Hz in North America) on the order of a few millivolts per ampere of load current and usually requires amplification before sensing by an Arduino. I've used the Coilcraft CS60-010 with a simple operational amplifier precision rectifier circuit in several designs. You can get free samples of CTs from Coilcraft for experimentation: CS60-010 50/60 Hz Current Sensor | Current Sense Transformers & Sensors | Coilcraft

A further advantage of CTs over some other means of detecting circuit status is that they can often be located in or near the breaker box, so in one central location.

Hi!

I forgot to mention this is being installed right next to the mains switch board of the house. Im no electrician but I know safe wiring and use the correct wire for the circuit usage and I make sure its correctly colour coded for what it is. Also some of the wiring in the my house needs replacement anyway so I'll be simply replacing the old 2 core + earth wire with 3 core + earth between the switch and relays.

2-way switches actually switch a middle circuit to either the A or B side, so a simple relay might not achieve that. You need a common contact and then both a NO and NC contact.

The Relay's I have are SPDT what I believe as being needed for 2 way switches.

Im basically going to be using something like this:

A CT is a small transformer that surrounds a current-carrying wire and detects the current flowing in the wire by magnetic coupling

I actually have something that fits that description. I have an energy monitor that has a sensor attached the incoming cables that basically just clamps onto the wire and reads the wattage draw. Is this the same thing?

Yes, the thing that clamps on to the wire is almost certainly a CT. Do you have to enter the voltage value on your energy monitor, to get wattage?

BTW I posted the circuit for a simple amplifying precision rectifier for use with a CT here: measuring current with Current transformer - Project Guidance - Arduino Forum

From memory I don't remember setting a voltage but it has got cents as a cost option as well as pence, so I would assume you could choose between 110v and 230v. I bought it in the UK and brought it to NZ and it has worked in both locations (both countries use ~230V). Its not the latest one but its made by these guys: http://www.theowl.com/
I have a rough idea of what some of my appliances I brought over draw when used and checked the monitor was reading the same in both locations :slight_smile:

I look at your circuit briefly and will need to spend a bit more time before I fully understand it. It did lead me on to look up CT's though and I came across this: http://www.mindkits.co.nz/mindkits-news-and-blog/arduino-energy-monitor

Right now I'm looking only to find out if there is a load as opposed to what the load is. So If the load is greater than X the light must be on :slight_smile: ultimately though it wouldn't be too hard to modify the code/setup to read the load on each circuit which would be useful for things like wall outlets.

Thinking about the wiring of a few of these on one Arduino, is it possible I would get interference if I was to use the same 5v and ground across multiple CT's? Would I have to individually power each CT to make this work?

Perhaps the power monitor was intended solely for 220 VAC circuits. In any case, an accurate power monitor needs to know the instantaneous line voltage. In the U.S. this can vary from about 105 VAC to 140 VAC in different localities and from time to time.

There is no need to have separate power and ground supplies for current CT amplifiers. They are completely independent and need a common ground with the Arduino anyway.

However, if you just want to know whether there is SOME current draw as opposed to an open household circuit, you don't need an amplifier. You can use the technique described in the nice link you posted, which uses a DC offset of half the power supply voltage, and samples the CT output directly. It won't be as accurate as an amplified solution, especially for low currents, but seems just the ticket for your current application!

Off topic, I've lived in Auckland for short periods and have traveled pretty extensively in NZ. It is a spectacular country; far more sane than most, and I envy anyone who has a chance to live there or visit!