Then take a look at single pole double throw relays (SPDT). These things are the functional equivalent of your two way switch. For this kind of thing I like the latching versions of the relays because you don't have to keep power to it.

Thanks. That sounds interesting. I just read about SPDT latching relays. It was very helpful. I was searching for some stuff related to latched SPDT relays with arduino but couldn't find any. Please do let me know of any useful resources in this direction.

From what I understand, the following two options are available:

Replace one of the switches in 2-way switch by the SPDT latched relay controlled by arduino

Replace one of the switches in 2-way switch by the SPDT latched relay controlled by arduinoAdd SPDT latched relay controlled by arduino to the existing 2-way switch ending up 3-way switch

The idea of replacing one of the switches with an SPDT relay will work; the idea of another SPDT won't work in 'normal' house wiring. If you want to add another switch, which is sometimes easier, you'll have to go to a DPDT relay. This is because electricians carry the power from switch to switch using two carrier wires. You can actually add as many DPDT type switches or relays as you want between the two SPDT devices. To see what I mean, google "wiring diagram multiple light switches" and there are a ton of examples that will show you what is happening.

As far as examples that will work for replacing one of the switches, go to digikey.com and look at SPDT power relays. Here is an example that will do the kind of thing you want:

This particular relay has a 5V coil so you don't have to have another supply voltage and will latch. Note, this is only an example of what will do the kind of thing you want, there are lots of others out there. While there is little mention of using a latching relay with an arduino, there are lots of circuits that do the same thing that are illustrated on the web. There is also something you should consider: the current required by most power relays is too high for the arduino to supply, so look also at using a transistor external to the arduino to supply the current you need to run the relay; there are lots of these examples also.

There are also relay shields that have this stuff already built into the board, however I haven't seen one that uses a latching relay.

Thanks, that was informative. I studied on the SPDT and DPDT and will have to do some more study to understand them completely. Most importantly, I'm able to get an idea over the final circuit.

One more question that popped up, let's consider that 2-way switch is implemented with one switch controlled by Arduino and SPDT relay. I understand that the state of the light could be toggled using any of the switches. Would it be possible to read the current status of the light? The whole idea is to figure out if the light is on or off from a remote location and this helps me to toggle the current state or not. Hope I'm not missing something really basic.

You hit the problem I've been dealing with on a project of mine. The short answer is yes, but.....

You see there are a couple of problems that have to be considered carefully. First, what the heck is going to power the circuitry you want to install. Second, do you want to know if there is power there or actually flowing. See, if you have power available and the bulb is burned out, the light isn't on. There are a couple of reasons for which one you want.

The power comes in on the common lead of the relay and is switched between the two carriers, so it matters where you pick up the power because in one position or the other, there won't be any power available on one or the other of the carriers. If you hook to the common line, you must be on the side where the power comes into the circuit. If you mix them up and get the side that leads to the light, you'll only have power to the circuitry when the light is on.

But these annoyances aside, there are two well known ways to tell if power is somewhere. First is to use something that samples voltage. People usually use a capacitor to feed an optoisolator hooked to the power line and then on the other side hook it up to an analog pin on the arduino. A little code and you can tell if there is mains power there. Second is to sample the current using something like an ACS712 to actually measure the power by hooking the output of it to an analog pin of the arduino. A little more code later you can tell if there is current flowing. A little (actually a lot) of searching on Google and you can turn up many examples of both of these ideas.

I don't have a definitive answer for either of these because my parts are on order to test the optoisolator idea. I have tested the ACS712 idea and it works really well to tell if there is current flowing, however the range of current is large and that can lead to troubles. For example, an incandescent light will pull around 800ma from my 110 supply, but a CFL light will pull less than a tenth of an amp. If I want to be able to tell current flow in a multiple light circuit as well as a single light circuit, it can get tough deciding what to do. This problem is compounded if you have parasitic devices (phone chargers, instant on TVs, etc.) on the circuit.

Thanks, your info seems to be helpful. Tried to do some google on optoisolators but couldn't figure out the exact purpose and how they could be used in the current situation I think the stuff is getting complex for me to handle. Will have to do some background study on the suggested options.

My first impression was that optoisolators act more like a fuse breaking the circuit on detecting additional voltages, but wasn't sure how it could be used in conjunction with by the arduino to track if the device is powered on. Any links for reference would be helpful. Correct me if I'm wrong.

Regarding optoisolators, here's a recent thread on this very subject. Notice how the idea evolves as you read down through the thread. The poster is doing exactly what we discussed.

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=45&t=9617

One thing I want to mention just to be sure you're aware. The voltages you'll be working with can blow an arduino to pieces if you mess up. It can also actually kill you. Yes, I know you know this and will take care, but there may be some young person that reads this thread and gets the idea to just jump in there and start hooking things together. This paragraph is mostly for them. Don't do it if you don't know what the heck you're doing, or at least have your life insurance paid up to date.

we used the following scheme to do that job. Basically the wall switch power a 220V coil of a relay, one contact goes to the Arduino to know the position of the wall switch, the other goes to the lamp via a relay that is on the Arduino it self.The NC relays is keep open by the Arduino, so the wall switch will never act on the lamp while the Arduino is powered, than the Arduino can drive the lamp using the other relay.

So, the Arduino knows about the wall switch position and drive the lamp. If the Arduino is off or broken, the NC relay will control the lamp directly from the wall switch.

This scheme is used in a home along with the Souliss project, so the lamp is either controlled via Android or Modbus.

Please take care, because not always you can try the 220V twice and get help if your local law or your knowledge request it.

Note that the wiring of the GND pin is wrong, you need a pull-down to an input pin.

I am having two way switches in my room. I am a newbie planning to do some home automation using Arduino and got a few questions in this directions.

--> I am interested to keep the existing AC circuit intact. Would it be possible to add the arduino controlled output into the existing circuit making it a 3-way switch?

Please do let me know of any other alternative approaches if the proposed approach doesn't work.

The overall idea is to have my existing two way switches intact and add an additional switch thats controlled by Arduino enabling home automation.

Any help is appreciated. Thanks.

Hello npadma:

The same that you want I thought it some time ago, and as I did not find anything that it was able to solve my aims, I developed my own solution. I have developed a home automation system based at the Arduino platform and called functiodomo that it lets you to control any electric compontent at your home without modify your electrical instalation.

Thanks. The NC Relay looks as an interesting option, but still not sure if it could be applied to the 2-way or 3-way switch circuits for controlling and monitoring the status of the circuit.

I'm sorry, I couldn't exactly get the circuit diagram you explained. Would be great if you can help me with some visuals.

From what I understood: in addition to the traditional light-switch circuit, one terminal of the switch is connected to the arduino and the other is connected to the NC relay. Please do let me know if my understanding is correct, before I go further on this.