2
\$\begingroup\$

I wanted to read the state of an AC switch using a microcontroller. S1 is an SPST switch and cannot be changed.

enter image description here

What circuit will be required for doing this?

I'm using this for my home automation project where I should have both manual and wireless control. This will also help me find the state of the load (on/off.)

\$\endgroup\$
12
  • 3
    \$\begingroup\$ Please describe what you are trying to do. This switch is probably switching something on and off? \$\endgroup\$
    – Eugene Sh.
    Dec 4, 2019 at 15:56
  • \$\begingroup\$ Voltage, current? \$\endgroup\$ Dec 4, 2019 at 15:57
  • \$\begingroup\$ @EugeneSh. I have added more details to it, please let me know if anything else is required. \$\endgroup\$
    – Rohitsam
    Dec 4, 2019 at 16:10
  • \$\begingroup\$ I'm struggling to see how you can "have both manual and electronic controll". \$\endgroup\$
    – Andy aka
    Dec 4, 2019 at 16:15
  • \$\begingroup\$ @Andyaka I think If the ? block is solved then it should be possible. \$\endgroup\$
    – Rohitsam
    Dec 4, 2019 at 16:17

5 Answers 5

1
\$\begingroup\$

One way It would solve is if I also have Neutral going into my ?Block then I could use an AC optoisolator to see if the switch is closed or not. enter image description here

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ If this is at full mains voltage, that resistor is probably not nearly enough. Honestly, I'd advise against doing anything at mains voltage if you can avoid it, it's dangerous. But if you must, look into a capacitive dropper. \$\endgroup\$
    – Hearth
    Dec 6, 2019 at 16:33
  • 1
    \$\begingroup\$ @Hearth Definitely Dangerous to play with mains, but Optoisolater will never mess up with my uC part and other DC components, but I fell Capacitive dropper might affect uC or other DC components? \$\endgroup\$
    – Rohitsam
    Dec 6, 2019 at 17:10
1
\$\begingroup\$

Welcome to the site!

If you really don't need to know the state of the physical switch, but instead know if there is current flowing through the switch, you could use a current sensor to measure that. Something like an Allegro ACS724.

As you are tying into high voltages, please be smart.

\$\endgroup\$
3
  • \$\begingroup\$ Current wouldn't flow until uC knowns the state of the switch and turn the relay on. \$\endgroup\$
    – Rohitsam
    Dec 5, 2019 at 15:07
  • \$\begingroup\$ @Rohitsam Why does anything need to be at mains voltage then? Why not just hook the switch up to 5V or something instead? \$\endgroup\$
    – Hearth
    Dec 6, 2019 at 16:35
  • \$\begingroup\$ @Hearth This was considered to simplify the wiring part So that my module would easy fit inside the switchboard without much change existing wiring. \$\endgroup\$
    – Rohitsam
    Dec 6, 2019 at 17:00
0
\$\begingroup\$

That's something you don't generally want to DIY. You are likely to create a hazardous situation. One way to do it relatively safely, assuming you have a way to separately power a microcontroller, is to introduce a solid state relay. Something like this.

You'd wire the physical switch to a circuit something like this:

schematic

simulate this circuit – Schematic created using CircuitLab

The MCU could monitor that pin as an input to find out the state of the switch. And if it wanted to, it could also dictate the state of that pin with as output. That's just one possibility. Deciding on a topology that satisfies a set of desired outcomes about precedence and what not is what designing something like this is all about, and that's where you come in.

UDPATE #1 As per the update to the OP's question, same idea but two separate connections to the microcontroller.

schematic

simulate this circuit

\$\endgroup\$
1
  • \$\begingroup\$ This is would defenetly work, but in my case it would be difficult to rewire all the switches with the dc part. \$\endgroup\$
    – Rohitsam
    Dec 5, 2019 at 15:01
0
\$\begingroup\$

Get a 110V (or whatever voltage you're working with) relay and connect the coil from S1 to neutral. Then connect C to uP ground, and NO to a uP input with a pullup. When S1 is closed, that input will go low. (If you want the opposite polarity, use NC instead of NO.)

\$\endgroup\$
0
\$\begingroup\$

If you just want to know whether the switch is in on/off state, you can try recreating the following circuit :-

enter image description here

Source

The optocoupler mentioned here is PC817. You can also use H11AA1 instead of PC817.

  • Whenever AC voltage is present at the input of optocoupler, output of it would be LOW and microcontroller will receive logic 0 as input.
  • And when AC voltage is absent at the input of optocoupler, output of it would be HIGH and microcontroller will receive logic 1 as input.

Here the H11AA1 is used.

\$\endgroup\$
3
  • \$\begingroup\$ Exactly Now I realized I don't require any bridge rectifier also, A capacitor at the output would solve the need. \$\endgroup\$
    – Rohitsam
    Dec 6, 2019 at 16:50
  • \$\begingroup\$ @Rohitsam, Just to let you know using PC817 in this circuit will continuously produces a pulse on each AC cycle when switch is in a constant on position. It won't be a constant on signal rather a pulsating one. You should handle this switch input with care in your software or else you will end up with a pulsating relay. \$\endgroup\$ Dec 6, 2019 at 17:09
  • \$\begingroup\$ With AC this schematic will go beyond 6 Volt reverse rating of the LED. You must use a bipolar optocoupler or add an extra diode. \$\endgroup\$
    – Jeroen3
    Dec 6, 2019 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.