Automation in existing home using Arduino

I am from India and power is supplied at 220V. There are only two-way switches.

Thanks.

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
  • Add SPDT latched relay controlled by arduino to the existing 2-way switch ending up 3-way switch

Please do let me know if I understood right.

Replace one of the switches in 2-way switch by the SPDT latched relay controlled by arduino
Add 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.

Not much help am I?

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.

Hope the optoisolator idea works for you. Keep me posted.

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.

Hi,

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 :slight_smile: 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.

If you need more, just ask.

Regards,
Dario.

plinio.bmp (68.7 KB)

npadma:
Hello,

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.

You can find more information about it here:

http://arduino.cc/forum/index.php/topic,116788.0.html (english arduino threat of the functiodomo system)
http://www.functiodomo.com/en/functiodomo_web/index.html (english version of www.functiodomo.com)
http://functionars.dyndns.org/functiodomo_wp/ (spanish blog with information and documentation about the system)

You can ask me anything that you want about it. I will try to answer you.

@Napoli

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.

@Torremolinos

Thanks for the reply. I did go through your project, but couldn't really find anything related to controlling and monitoring the current status of the light in existing 2-way switch circuits. Please provide me a link or additional info, if I did miss on something.

Yes, the wall switch is connected to a relay (or contactor) with 230V (or 120 V) coil and two NO contacts (lets call C1, C2). So your wall switch will no longer drive the lamp, but only the 230V coil.

These two contacts are driven by the wall switch, C1 is connected to the Arduino. On C1 you simply apply the 5V, then your board will know the position of the wall switch. The Arduino board can so drive an its own relay (5 or 12 V coil with darlington) that drive the lamp with its contact.

Basically is your boar that drive the relay and so you know if is ON or OFF.

The 230V relay was added to give the opportunity to drive the lamp also when the board is p owered off or is broken, and the second contact is used through an additional relay in NC wiring, so when the Arduino is powered on it will cut of that circuit.

Which is your real goal?

Regards,
Dario.

@veseo

Thanks. I had drawn a circuit diagram at a high level, just to let you know what I understood. Please let me if I got you right. I had attached the circuit diagram.

The problem I see in this circuit is that the switches wont perform until the Arduino switches itself off. In other words, if the light is switched on from arduino, the light can not be switched off from the switch.

Circuit.png

You got it partially, instead of a classic wall switch you need something with two contacts one to the NC relay and one to the Arduino board. Since in the market the wall switches with two contacts (4 pins instead of 2 pins) are not so common a relay with 230V coil was used.

So your wall switch will act on that relay, that will transfer the open/close position of your wall switch into two dry contacts (at least one shall be rated for 230V operations). One of these two is used to power the lamp via the NC relay, so is directly connected to the 230V.
The other is used to notify to the Arduino board if the wall switch is pressed or not, so is connected to the 5V and the input pin of the Arduino.

So until the Arduino will not be powered off, the NC relay broke the circuit of the NC relay, but the wall switch positions are reported to the Arduino board and so you could act on the NO relay from wall switch or other interfaces (we are using in Souliss driving also from Android and Modbus). When the Arduino is powered off, for example is broken, the wall switch only will work via the NC relay.

This scheme was used because Shine (that is the other developer of Souliss) was warried about lost completely lamps control in case of faults.

Generally, if you just care about drive the lamp from wall switch or other interfaces going through Arduino, simpli connect the wall switch to the board and the Arduino to the lamp via relay. In that case, if Arduino fails your lights will stay off.

Regards,
Dario.

I don't have an idea on the switch with 4 pins. I understand that the switch comes with two pairs of contacts. One pair of contacts is connected to a 230V supply while the other pair of contacts is connected to a 5V supply.

The 230V supply is used to control the lamp using the NC Relay when the arduino is switched off.

When the arduino is powered on, the 5V supply reports the position of the switch to the Arduino from where the actions over the lamp are controlled.

Am I correct?

Yes you are :slight_smile:

Thanks. I see that these contactors ( with 4 pins) are very expensive. Are there any other cheaper alternatives?

Can a relay also work the other way around, like high voltage circuit driving a low voltage circuit? If so, please provide me a link to such a product.

The one in the link that I've included before is at 12 euros that is mostly the lowest that you can found, the price are related to the contact rate. The contactors are relays, is a just a different name used to indicate devices that has 230V coil rather relays are typically at lower voltages.

If you have a lot of lamps to control and don't want to spend too much money, you can always connect the wall switch to the arduino directly and let it control the lamp, and maybe use the scheme that I've proposed only for some main lights.

A middle way is changing your wall switch with double poles one, they are cheaper a smaller than a contactor and has two poles. These are think for breaking both phase and neutral to a device and are not common for light, rather are used for high power devices.

In that case, you have the switch and two poles, so you can use the same scheme without the contactor in between.

Regards,
Dario.

I considered the double throw relay as a possible solution to knowing the state of a latching relay until I saw the cost. When you spend as much on a relay as the rest of the circuitry, it gets a little silly. That's why I've been researching how to sense that current is flowing in combination with voltage being available.

What I want to do is power the electronics of a switch with the power that's available in the switch box (no batteries or separate power supply) This means that I have to have a tiny power supply that takes mains voltage (110 for me) and gives me 5V to run the circuitry. On a multi-switch setup, where there are both SPDT and DPDT switches in the chain, finding power and knowing the state of the latching relay can become quite a task without rewiring the switches.