Arduino Nano ESP32 - Rocker Switch Module
Look at a power strip. Its big switch often has a small lamp, so you can see from across the room if the power is on. A homemade project can have the same thing. The DIYables ON/OFF Rocker Switch Module gives you that kind of switch on a small board, and the Arduino Nano ESP32 already has an RGB LED on the board to act as the lamp. Use it as the main switch of a project box: flip it to pause a WiFi gadget without pulling the USB cable, and the LED tells everyone what state the gadget is in. In this guide, you will wire the module to the Nano ESP32 and build that status light. In detail, we will learn:
- The meaning of the two rocker symbols and of the three header labels.
- Wiring to 3V3, D2 and GND, and the reason the VBUS pin must stay free.
- Printing the rocker position on the Serial Monitor.
- Turning the built-in RGB LED into a green/red status lamp, debounced with millis() instead of delay().

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of Rocker Switch Module
The part on top is a black KCD1 rocker, the kind built into power strips and desk lamps. It sits on a small blue PCB, roughly 24 mm square, with a hole in each corner for screws or standoffs. The rocker shows two symbols. Push down the end marked "I" to switch ON. Push down the end marked "O" to switch OFF. The two labels beside the rocker, "ON (H)" and "OFF (L)", give one more hint: H for HIGH and L for LOW on the signal pin.
Let go of the rocker, and nothing moves back. It rests on the end you pushed until you push the other end. Switches like this are called maintained, or latching. The short technical name is SPST: a single circuit that is either closed or open. So your sketch does not wait for a press. It asks "is the switch ON or OFF right now?", and it reacts when the answer changes.

You find the pin names on the underside of the PCB, beside the right-angle header:
- SIG pin: connect to D2 of the Arduino Nano ESP32. In the I position it carries the VCC voltage and reads HIGH. In the O position it sits at 0V and reads LOW.
- VCC pin: connect to 3V3. 3.3V to 5V is allowed on the module, yet with this board only the 3.3V choice is safe.
- GND pin: connect to GND (0V).
Also on the PCB: a pull-down resistor of 10 kΩ, labelled "103". Thanks to it, SIG stays at a clean LOW whenever the rocker is on O. That is why you add no resistor of your own, and why D2 is set as a plain INPUT, not INPUT_PULLUP. The logic is the natural one: HIGH stands for ON, LOW stands for OFF.
| ON/OFF Rocker Switch Module | |
|---|---|
| Switch type | KCD1 rocker, one circuit (SPST), stays in place |
| Symbols on the rocker | I for ON, O for OFF |
| SIG level | VCC level (HIGH) when ON, 0V (LOW) when OFF |
| Supply voltage (VCC) | 3.3V to 5V |
| Pull-down on the PCB | 10 kΩ |
| Header | 3 pins (SIG, VCC, GND), 2.54 mm pitch, right-angle male |
| PCB | about 24 x 24 mm, one mounting hole per corner |
| Size including the header | about 24 x 29 x 22 mm |
The switch body may show "6A 250VAC / 10A 125VAC". Those numbers belong to the switch as a stand-alone part. On this module, the switch only passes a tiny signal to a GPIO pin. Never send mains power or motor current through its header pins.
※ NOTE THAT:
In the I position, the switch simply joins SIG to VCC. If VCC came from VBUS (5V), D2 would receive 5V. The ESP32-S3 chip of the Nano ESP32 handles 3.3V on its GPIO pins, not 5V, so D2 could be damaged. Keep VCC on the 3V3 pin.
Wiring Diagram
The module needs only three wires, one for each header pin. No breadboard and no resistor are used.

This image is created using Fritzing. Click to enlarge image
| Rocker Switch Module | Arduino Nano ESP32 |
|---|---|
| SIG | → D2 |
| VCC | → 3V3 (never VBUS) |
| GND | → GND |
Jumper wires are good for a quick test, but not for a final build. You can plug the Arduino Nano ESP32 into a Screw Terminal Expansion Board for Arduino Nano and connect the wires to its screw terminals. The wiring stays the same. Only the wires now go to the screw terminals, as shown below.

This image is created using Fritzing. Click to enlarge image
How To Program For Rocker Switch Module
Nothing has to be installed for this part. The two sketches share these lines:
- Give the SIG pin a name:
- In setup(), make it a normal input. The pull-down on the module does the rest:
- Read the state. HIGH means the I end is down (ON). LOW means the O end is down (OFF):
- For the second sketch, store the state you trust in a variable. A reading that disagrees with it becomes the new state only when it holds steady for 50 ms.
Arduino Nano ESP32 Code - Read the Rocker Position
This first sketch only reports. Every 500 ms, it checks D2 and shows where the rocker is, plus the raw value. Run it once to make sure the wires are right.
Detailed Instructions
Try it step by step:
- New to the Arduino Nano ESP32? Install its board package first, as explained in how to setup environment for Arduino Nano ESP32 on Arduino IDE.
- Connect SIG, VCC and GND as in the table above. Look once more at the VCC wire: it must end on 3V3.
- Plug the Nano ESP32 into your computer with the USB Type-C cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Nano ESP32 board (e.g., Arduino Nano ESP32) and COM port.
- Paste the sketch into an empty window and press Upload.
- Choose 9600 baud in the Serial Monitor.
- Leave the rocker on O for two seconds, switch it to I for about three seconds, then back to O.
The state does not change between two flips. That is the latching rocker at work. A push button would go back to 0 as soon as you let go. If you see 0 on both sides of the rocker, check that the VCC wire is on 3V3 and the SIG wire is on D2.
When you flip the switch, its metal contacts bounce for a few milliseconds. This sketch looks only every half second, so it never catches the bounce. The next sketch reacts to every change, and there the bounce matters.
Arduino Nano ESP32 Code - Green or Red Status Light on the Board
Now the rocker gets its lamp, like on a power strip. ON lights the RGB LED of the Nano ESP32 in green, and OFF lights it in red. No extra LED and no extra wire are needed. The board package names the three colours LED_RED, LED_GREEN and LED_BLUE. This LED is active LOW: digitalWrite(..., LOW) turns a colour on, and HIGH turns it off. The sketch keeps blue off all the time.
The sketch also prints one line for each flip. To ignore the bounce, it notes the time of every change of the raw level with millis(). A new level counts only after it stayed the same for 50 ms. The loop never waits, so you can later add WiFi or sensor code to it, and the switch still responds at once.
Detailed Instructions
- Do not change the wiring.
- Upload the code above to the Arduino Nano ESP32.
- Keep the Serial Monitor open at 9600 baud. Watch the RGB LED on the board while you flip the rocker four times.
Four flips give four lines. The bounce never shows up as an extra flip. Right after an upload or a reset, the USB port of the Nano ESP32 needs a moment to come back, so the Serial Monitor may miss the "Rocker starts at" line. The LED does not need USB: it shows the start position anyway.
Using it in your own project: in loop(), put your main work under the check if (switchState == HIGH). A weather station could then upload its readings only in the I position. Flip to O, and the uploads stop while the board stays powered, with a red light as a reminder.
Module or bare ON/OFF switch?
This board also has a page for the bare 2-leg rocker switch: Arduino Nano ESP32 - Switch. The main differences:
| 2-leg ON/OFF switch | This module | |
|---|---|---|
| Wire count | 2 | 3 |
| Resistor | internal pull-up (INPUT_PULLUP) | 10 kΩ pull-down on the module (INPUT) |
| Level when ON | LOW (inverted) | HIGH |
| Pin labels | none | SIG, VCC, GND |
For a key that returns by itself when you let go, read Arduino Nano ESP32 - Button Module.