Keeping Manual On/Off Alongside Remote Relay Function

Dears,

I have tested the two way switch today, and it is working great.

My setup is the following:

ESP8266-01 ( in replacement for the Arduino)
and home designed relay board connected to the ESP

the Relay is connected to GPIO 2
the two way switch is connected (1- GRND , and 2- to GPIO 3)

in the code i have three parameters:

int buttonState = HIGH; // variable for reading the switch change state
int relayState = HIGH; // variable for reading the Relay status
int switchState = HIGH; // variable for holding the current switch state

in the Setup()

void setup ( void ) {
pinMode(2, OUTPUT); //
digitalWrite(2, HIGH); //Switch relay off, before starting the setup module
relayState = HIGH; // equal to GPIO setting, used as global varialble to keep status available to every body

digitalWrite(3, HIGH); // Setting GPIO3 to HIGH in preparation to manual intervention

switchState = digitalRead(3); //GPIO 3

in the loop()

buttonState = digitalRead(3); //GPIO 3
if (buttonState != switchState) {
switchState = buttonState;
if (relayState == HIGH) {
digitalWrite(lightPin, LOW);
} else {
digitalWrite(lightPin, HIGH);

}
delay(1000);
}

your arduino code will fit in here

}

Hope it clarify the scenario with 2-way switch

Regards
Samir Tafesh