We are talking about the regular white colour rocker switches which are commonly used across the globe. They came into the market in the 70s replacing the tumbler switches made up of Bakelite and China clay. They are SPST switches ( read our old article Type of switches to know more). They have different names such as piano switch, rocker switch, decorator rocker switch etc. As because before wide-spread usage of the internet there was no need to worldwide unify the household electrical components, they do have minor difference for debouncing. In electronics, we commonly use push buttons for a universal bouncing effect so that the debouncing code works in any country. North Americans will not easily find “decorator paddle rocker light switch” among the “modular switches” in India :
1 2 | https://lsin.panasonic.com/switch-socket-accessories/switch-and-socket https://www.orientelectric.com/switch-gear/modular-switches |
Ignoring these differences, we are pointing towards your household electrical switch. We want to interface the common rocker switches with ESP32 and relay to make it “digital”. So these switches will not handle the current of AC mains but will handle DC signal. This approach of making the home smart is a method that is least hazardous but most complicated. In this design, the power sockets are electrical appliances. For 3.3V or 5V DC signal, an AC switch will behave like a DC switch of that cost. But know the theory – AC switches are different and do not think to convert AC to DC to power your household appliances. DC at higher voltage tends to create an arc for a longer period in a micro gap (like the switches have). We are brutally hacking the AC switches to make them an electronics gadget to maintain a traditional feel and operation. So :
When the rocker/piano switch is ON -> Light is ON
When rocker/piano switch is OFF -> Light is OFF
---
But the setup is “smart” and internet-connected. The state of the physical switch can be overridden. Unless we do this hard work of wiring, we can run automation. The relays are parts that may fail upon excessive load.
Coming to the topic. This is an illustration of wiring :
The LED must be present in any circuit, you need to interpret the signal. The design in PCB will be like this one. A sample basic code without debouncing and relay can be like this one :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | int switch_pin = 4; int led_pin = 5; byte leds = 0; void setup() { pinMode(switch_pin, INPUT); pinMode(led_pin, OUTPUT); } void loop() { if(digitalRead(switch_pin) == HIGH){ digitalWrite(led_pin, LOW); } if(digitalRead(switch_pin) == LOW){ digitalWrite(led_pin, HIGH); } } |