Overriding 220V switch with arduino

Hello,

I am trying to override a regular 220V light switch for an home automation project.

The circuit goal is to let the switch work as usual when the arduino is not powered on but take over the switch when on. Then the switch position need to be "read" by the arduino to possibly override it's behavior.

The main behavior can be achieved with 2 relays (1 to take over the switch and 1 to simulate a new switch). But I don't know how to "read" the switch:

As we are dealing with 220V, I figured it may not as straightforward as detecting the position of a regular 5v switch.

Do you know simple way to get the switch state?

You can use one H11AA1 in paralel with the light and then you can read the switch.

if (write1 == LOW) && (digitalRead from H11AA1 is HIGH) then user use switch.

I recommend a regular "home automation" type switch [u[/u]](WS12A Decorator Dimmer Switch - X10 – X10.COM). They have momentary contacts so they can be used locally or remotely and it will just hold the current on/off (or dim) state until changed locally or remotely.

You'll also need a compatible transmitter/controller. I'd recommend buying the switches & outlets even if you want to build your own master timer/controller. There are lots of engineering & construction challenges building something like that, that fits into a regular switch box, looks nice, and doesn't require re-wiring your home. And, it will probably end-up costing more to build than to buy.

There are a few different standards/protocols and some are "open" so it's easier to build something compatible. X-10 is the oldest (and maybe the most outdated) standard. I don't know what Alexa & Google use but the "new big companies" are now forming a consortium to get everything more standardized in the future.

P.S.
I've got a combination X-10/Insteon system. I've had it more than 20 years and I didn't build any of it myself. I've got about 10 controlled lights/outlets, a master timer/controller that turns-on the outside lights on at sunset and off at sunrise (etc.). There is one motion sensor, and a couple of manual remote controllers around the house.

...I did build a "sunrise dimmer" that plugs into a controlled outlet. (That was done with a different-older microcontroller, before the Arduino.) The home automation system just turns-on that outlet 10-minutes before wake-up time and the light fades-on over a 10-minute period. (My particular automation system has "limitations" and it can't do that by itself, so the automation system takes care of the time-of-day and day-of-week stuff.) Then after 10 minutes with the light fully-bright, a "gentle alarm" wakes me up with a quiet beep once every 30 seconds for the 1st minute, 2 beeps after 2 minutes, etc.

A more practical approach is to leave the Arduino powered continuously - its consumption in a mains environment is trivial - and control the circuit with a single relay. Then connect the original switch as an input to the Arduino.

Then it is all under control of the Arduino code.

maybe the user has already thought about using the old switch as a digital input in the arduino. and then, what are the alternatives if we take into account the data of the current problem?

Make it safe, I generally use a very small transformer that is rated at only a few mills but more mills is OK for detecting (sensing) and measuring AC voltages. The transformer can be mounted in appropriate enclosure and the secondary wires run to your arduino system. You will need to convert the AC from the secondary to the appropriate DC value needed for the Arduino but that circuit is very easy to find. Have fun, Gil

"But I don't know how to "read" the switch:"

"Reading" 120/220vac switch states seem to be a frequent question, so a forum search might be helpful.

Indeed, I'd like to both use the same physical switch as "standard" 220v input or 5v "digital" input depending on what the arduino decides. By default (arduino powered off), the "standard mode" would be selected.

Using an optocoupler seems to solve the problem.

Would this diagram work?

Optocoupler:


https://www.aliexpress.com/item/32828199766.html?spm=a2g0o.detail.1000060.1.45ed10d25cA6y0&gps-id=pcDetailBottomMoreThisSeller&scm=1007.13339.146401.0&scm_id=1007.13339.146401.0&scm-url=1007.13339.146401.0&pvid=37ced7fb-10f4-4959-a610-d4d2b6f29c11

Relay:

Diagram and choice of optocoupler seem fine.

But why would you want to turn the Arduino off? Why not just use it? A lot simpler, only one relay, no optocoupler so more compact. :roll_eyes:

Thanks for checking on the diagram!

This is a good point. I am designing for failure.

By adding an arduino and more electronics, I am adding a lot of complexity to something that is basically just turning a light on with a switch. That complexity is bound to fail at some point.

I don't want to hold my family hostage of a home that was perfectly fine just because I wanted it to be finer :slight_smile:

ggrome:
This is a good point. I am designing for failure.

That is a worry. I would say that using two relays where one would suffice is indeed, designing for failure by multiplying the points of failure, the relays being the most likely failure point.

ggrome:
By adding an arduino and more electronics, I am adding a lot of complexity to something that is basically just turning a light on with a switch. That complexity is bound to fail at some point.

Why? Which faulty components do you propose to use?

ggrome:
I don't want to hold my family hostage of a home that was perfectly fine just because I wanted it to be finer :slight_smile:

Then do not proceed with your project. :grinning:

The error here is in the presumption that failure will always occur in a particular direction. :roll_eyes:

Not sure what the issue is . You already linked an AC detector breakout bd so what's the issue /question ?

Wants to do it the hard way! :grinning: