Control switch manually and via Ard.

Total newbie here to both electronics and Ardy, so any search keywords will help a lot.

On a basic level how can I have a on/off switch with a built-in LED be controlled manually via the switch and electronically via Ard, in the sense that if I hit the switch on I can turn it off via Arduino, and vise-versa.

While the switch is on there is the LED circuit that picks up the state and powers the LED on the button.

OR

Is it just easier to have a momentary switch that when pressed Arduino could pick up the HIGH/LOW state, so that it changes the LED on/off and the actual switch applications (when a state has been changed, check the current value and switch it to the opposite)?

In the case of the second, I'll need to re-think the switch design that suits as they're only available in 6v or 12v, unless there is an easier way than having a control solid state relay just for a LED.

These buttons will control via a hardware software layer, that then controls solid state relays and finally the application. e.g Button press -> Ardunio pickup -> Software change -> Breakout board change -> SSR -> Device on/off

Thanks in advance for any help.

I am not totally sure what your situation is. You have a switch with an LED inside? Obviously, you cannot control the switch itself with Arduino (if you don’t attach a motor or something). Usually the LED is hard-wired to the switch state, so you also cannot control that. Is that the case for you, or can you control the LED independently from the switch.

Here is basically what you can do:

  • Use a momentary switch that is connected to the Arduino, and the Arduino does all the actual switching, based on either the input from the switch or other sources.
  • Use a toggle switch that is connected to the Arduino, and the Arduino does all the actual switching, based on either the input from the switch or other sources.
  • Use an SPDT switch in a traveler system. Advantage: The switch can work independent of the Arduino. Disadvantage: You probably need a relais on the Arduino side, which you would not necessarily in the other cases, depending on what you want to switch
    Of course, in the latter cases, the position of the switch (and the state of a hard-wired LED) is not fixed to an actual switching state, so you couldn’t put labels on there. I prefer momentary switches because of that, because they don’t give false impression of a state.

ElCaron: Here is basically what you can do: - Use a momentary switch that is connected to the Arduino, and the Arduino does all the actual switching, based on either the input from the switch or other sources.

In that case, how would I switch the physical state (electrical circuit on/off) of the switch (to keep the switch LED on). e.g LOW or 0 when off, HIGH/1 when on?

As the LED would be on when the switch state is 'on'

I don't know, because I don't know your switch. Is the LED state hardwired to the physical state of the button? You are suggesting that when you say "As the LED would be on when the switch state is 'on'"

So, is it possible that your question is "How do I make Arduino PHYSICALLY flip a switch?".

ElCaron:
I don’t know, because I don’t know your switch. Is the LED state hardwired to the physical state of the button? You are suggesting that when you say “As the LED would be on when the switch state is ‘on’”

So, is it possible that your question is “How do I make Arduino PHYSICALLY flip a switch?”.

Sorry I should’ve cleared that up, yes it is directly related to the state of the switch (switch on led on, else off).

I mentioned that as the LED needs the physical switch to be on, so it seems unlikely to do via the Arduino (without physically changing the switch).

It is pretty obvious that the Arduino isn't going to magically flip over your switch, isn't it? Your LED is tied to a switch state, you want your circuit NOT to be tied to the switch state (since you want to have it switched with arduino, too), so, by the power of logic, your LED cannot be tied to the cicuit state. Don't know want you expected.

Either you change your indicator away from the switch LED, or you build a sophisticated, Arduino-controlled robot to press the switch. That is about it, if you cannot hack the switch to decouple LED and switch state. With that nobody can help you without knowing the switch.

In terms of a switch that has an internal LED that isn't tied to the on/off state, in simple terms I would just keep track of the state in ardunio, then check if the state changes - and manually power the LED on during the correct time (which would have to be 5-6v).

With that setup I am only using the switch for state changes, thus I would need another method to change any circuits such as a Solid State Relay through another Ard pin (circuits that would normally be activated via the switch).

You can use both a momentary button and a toggle switch. Just read it the right way.

For a momentary, toggle the output when it becomes pushed (switches state from not pushed (probably HIGH) to pressed (probably LOW) but not the other way around. For a toggle switch, simple toggle on each state change.

But for both cases you need debouncing (Google for what it is, Hackaday has a great article). Easy way, use a library like Bounce2. You can use it for both momentary and toggle switches.

As far as the switch goes, you need to be able to control the led from the Arduino with the desired voltage. But that's possible with each switch with build in LED. On most toggle switches you have a in, out and a led connection. If you connect it that way (with IN and LED to the supply and out to the device), the led is turned on/off by the switch together with the device. BUT, if you swap in and out the device is still turned on/off with the switch but the LED is on all the time. Now you can control the led independent via the LED connection :D

Only thing you need to keep track of, most low voltage switches with a led are polarity sensitive. A lot of those switches are designed to switch the positive side. So to independent control the led connect OUT to 5V, IN to an Arduino pin and give that pin a pull down resistor! And the LED to a Arduino pin as well. Now the switch input on the Arduino will read HIGH when the switch is ON, LOW when it's OFF (Because of the pull down) and you can turn on the led by pulling that pin LOW.

But a lot of those switches are for 12V... To use it now, connect OUT to 12V, use a voltage divider between IN and the Arduino (something like 47k and 33k) no extra pull down needed and switch the led via a transistor.

Ow, and keep in mind, if you use 12V from a car it's more like 14V-15V when the care is running!