How To Control Rocker Switch

I am trying to control a rocker switch with the arduino but can’t seem to figure out a workable solution. As you can see in the pictures when the switch is up the Green & Red are connected along with the White & Black. When the switch is down the Green & Black are connected along with the White & Red. Any help in point me in the right direction is appreciated. Thanks

Connect green wire to ground, connect red wire to an IO pin on your Arduino. Don’t connect the black and white wires to anything. Set the pin mode of the pin to INPUT_PULLUP:
pinMode(switchPin, INPUT_PULLUP);
Now when the switch is up your pin will read LOW and when it’s down your pin will read HIGH.

What do you mean by control a switch?
Do you mean have the Arduino replace the actions of that switch and also replace the switch?
Or do you mean that the Arduino has to physically push that switch?

Or do you mean that the Arduino has to replace the action if the switch while the switch is still in place?

What signals are on this switch, is it mains electricity?

Note pert’s answer is about using that switch as an input to the Arduino not about controlling the switch.

Looks like a mains lighting cross-over switch. The type that would be used where 3 switches control the same lighting circuit (the other two would be simple SPDT).

To replace or override it (whichever OP meant), a DPDT relay could be used. But there would be a problem, because to switch the lighting circuit on or of, the Arduino would need to know the positions of the other 2 (or 3) switches, or be able to sense the current flow in the netutral wire or sense the light produced.

The switch is to control a baffle that opens and closes. I am trying to eliminate the need for the wall switch where I can open and close the baffle remotely using the arduino. You can see in the video there is a white plastic wheel (above the left board) that spins and contacts 2 limit switches. One will stop it when its open and the other when its closed. I tried reversing the polarity but the board must auto correct for that because it didn't change the direction. My plan is to send a command to the aurdunio and say have it run in one direction for 10 seconds that will open or close it completely stopping at the limit switches. I don't really care about being able to open or close it partially.

Video of switch (Dropbox - 2019-06-21 08.40.06.mp4 - Simplify your life)

I know that the below wires have to be complete or nothing works.

To Open Green & Red / White & Black

To Close Green & Black / White & Red.

So, ideally, the wall switch will be gone? If you still need the wall switch as an additional, emergency override switch, that will make things significantly more complicated. However, if you want the switch to act as a secondary means of control, and only work correctly only if the Arduino circuit is also working normally, then that's less difficult. The switch can be wired directly to the Arduino, carrying 5V, low current signals to the Arduino's digital inputs. The Arduino can then control the mains AC power to the motor using an Arduino-compatible dual SPDT relay module.

You need a DPDT latching relay that does not have to be constantly energized, pulse one coil to switch one way, pulse the other coil to switch the other way.

You need a DPDT latching relay that does not have to be constantly energized

A nice idea, but not a "need".

A DPDT relay can replace a DPDT switch. A relay is an electrically-operated and electrically-isolated switch. But a DPDT relay doesn't have a "center off" position, so you'd need two relays. (One for direction and another for on/off.)

The Arduino can't directly drive a relay but you can get a "relay board" with one or more relays plus the driver circuitry.

You'll need two Arduino outputs to drive two relays.

If you wanted to keep the original switch operational you can connect it to two Arduino inputs. (You need two inputs because the center-off position gives you 3 possible states.) Home automation switches work like that... They are spring-loaded center-off and the light/appliance simply remembers the "last command". A light can be turned-on automatically, then turned-off manually with the switch and it will hold the on/off state until another local or remote command comes-along.

Looks like low voltage motor there so how about a H-bridge..??