ESP32 S3 UNO - Rocker Switch Module
The black rocker with an "I" and an "O" on it is the switch you know from power strips and desk lamps. DIYables puts that same rocker on a small blue board with three labeled pins, so the ESP32 S3 Uno can read it like any other digital input. Press one side of the rocker and it stays down until someone presses the other side. In the second sketch of this page, the board keeps a tally: each time the rocker goes to "I", a counter goes up by one. Now you can see how often a machine, a test rig or a game box was switched on since the last reset.
The plan for this page:
- Meet the module: the rocker, its "I" and "O" marks, and the SIG, VCC and GND pins
- Join it to the ESP32 S3 Uno with three jumper wires, with VCC on 3.3V
- Print the rocker position from D7 (GPIO14) twice a second
- Turn the rocker into a flip counter with a debounce that uses millis()

You do not have to install anything extra in Arduino IDE. The two sketches only call pinMode(), digitalRead() and millis().
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
A rocker switch has a small seesaw on top. Push the "I" side down and the switch is ON. Push the "O" side down and it is OFF. The DIYables module uses a black KCD1 rocker, the size you find on power strips, soldered on a blue board of about 24 x 24 mm with four mounting holes. Its 3-pin male header is bent at a right angle, so the wires leave the board to the side.
The rocker is a maintained (latching) switch. It does not spring back when you take your finger away. That is the big difference from a push button: a button only gives a short "pressed" moment, while the rocker gives a steady state that lasts until someone flips it again. So the code asks two questions: "is it ON or OFF right now?" and "did it just change?"
A 10 kΩ pull-down resistor (marked "103") sits on the board. While the rocker is on "O", it holds SIG at 0V. While the rocker is on "I", the switch joins SIG to VCC. This is why the print next to the rocker says "ON (H)" and "OFF (L)": ON gives a HIGH level and OFF gives a LOW level.

The pin names are printed on the back of the board, next to the header:
- SIG: the output. It carries the VCC voltage (HIGH) while the rocker is on "I", and 0V (LOW) while it is on "O". Here it goes to D7 (GPIO14).
- VCC: power for the module, 3.3V to 5V. On the ESP32 S3 Uno, give it 3.3V, because SIG copies this voltage.
- GND: ground. Any GND pin of the board is fine.
| ON/OFF Rocker Switch Module | |
|---|---|
| Switch | KCD1 rocker, SPST, maintained (latching) |
| Rocker marks | "I" = ON, "O" = OFF |
| Board print | ON (H), OFF (L) |
| Supply voltage (VCC) | 3.3V to 5V |
| SIG when ON | HIGH, the same voltage as VCC |
| SIG when OFF | LOW (0V) |
| Resistor on board | 10 kΩ pull-down on SIG (marked 103) |
| Header | 3 pins, 2.54 mm pitch, right angle |
| Size with pins | about 24 x 29 x 22 mm |
| Pack | 5 modules |
The side of the rocker says "6A 250VAC / 10A 125VAC". These numbers are for the bare rocker. On this module, the rocker only switches a tiny logic signal into a GPIO pin. Never send mains power, a motor current or any other load through the three header pins. If a big load must turn on, let the ESP32 S3 Uno read the rocker and drive a relay.
ESP32 S3 Uno Pinout
Before you wire, look for three pins in the picture. 3.3V and GND are on the power side of the board. D7 is on the digital side. The chip itself calls D7 GPIO14, and that is the number you will see in the code.

Wiring Diagram
The module brings its own header and its own resistor, so there is no breadboard in this circuit. Three jumper wires go from the module straight to the headers of the ESP32 S3 Uno.

This image is created using Fritzing. Click to enlarge image
| Rocker Switch Module Pin | ESP32 S3 Uno Pin |
|---|---|
| SIG | D7 (GPIO14) |
| VCC | 3.3V |
| GND | GND |
If the project will run for a long time, or sit inside a box, it is better to fix the wires with screws. To do that, mount a Proto Screw Terminal Block Shield or a Screw Shield V2 on the ESP32 S3 Uno. Here is the same circuit wired through the Screw Shield V2:

This image is created using Fritzing. Click to enlarge image
WARNING
Keep VCC on the 3.3V pin. Never move it to 5V or VIN. While the rocker is on "I", whatever voltage is on VCC also appears on SIG, and so on GPIO14. This board's input pins accept 3.3V at most and are not 5V tolerant, so 5V can damage the pin. The module works just as well at 3.3V.
A rocker is often left ON while the board powers up or takes a new sketch. On D7 that is no problem: GPIO14 has no boot strapping job, so a HIGH level on it during reset does not change how the board starts.
How To Program For Rocker Switch Module
The module already gives a clean HIGH or LOW, so reading it takes only a few lines.
- Name the pin. In Arduino code for this board you write the GPIO number, not the header label, so D7 becomes 14:
- Set the pin as a plain input once, inside setup(). The pull-down on the module sets the OFF level, so leave out INPUT_PULLUP:
- Read the position. HIGH means ON and LOW means OFF. Nothing is inverted:
- To count or log flips, look for changes, not for the level. Keep the last trusted level, and accept a new one only after the pin has stayed the same for about 50 ms. millis() measures that time without stopping the loop.
ESP32 S3 Uno Code - Read the Rocker Switch State
A switch that stays put does not need fast code. This sketch reads SIG every half second and prints the raw number and the rocker position. Contact bounce does not matter here: when the next reading comes, the contacts are quiet again.
Detailed Instructions
- Arduino IDE not ready for this board yet? Start with ESP32 S3 Uno - Getting Started.
- Connect the three wires: SIG to D7, VCC to 3.3V, GND to GND. Look at the VCC wire once more: it must sit on 3.3V.
- Plug in the USB Type-C cable between the ESP32 S3 Uno and your computer.
- Select ESP32S3 Dev Module and the COM port of the board in Arduino IDE.
- Paste the code into a new sketch and click Upload.

- Open the Serial Monitor and pick 9600 baud.
- Press the "I" side, wait about two seconds, then press the "O" side:
- Look at the result: the value does not change while you leave the rocker alone. A push button would show 1 only while a finger is on it.
ESP32 S3 Uno Code - Count How Many Times the Switch Is Turned ON
Now the rocker becomes a power switch with a memory. Think of a machine in a tutorial: you want to know how many times it was switched on today. The sketch watches SIG and adds one to a counter each time the level goes from LOW to HIGH. When the rocker goes back to "O", it prints a short line that also tells you how long the switch was ON.
A counter needs a clean signal. One flip can bounce for a few milliseconds and look like three flips. So the sketch notes the time of every raw change with millis(), and it trusts a new level only after 50 ms without a change. The loop never waits, so you can add more work to it later.
The position at power-up is not counted. If the rocker is already on "I" when the board starts, the sketch says so but leaves the total at 0. Only a real OFF to ON flip counts.
Detailed Instructions
- Keep the wiring from the first sketch.
- Upload this code the same way.
- Set the rocker to "O", open the Serial Monitor (9600 baud), then tap RESET on the board. Now the start lines show up.
- Flip the rocker to "I" and back a few times. Hold each position for a moment:
- Press RESET again: the total starts from 0. The counter lives in RAM, so a reset or a power cut clears it.
Video Tutorial
Additional Knowledge
Rocker switch module, bare ON/OFF switch or button module?
This board has pages for the two other parts too. ESP32 S3 Uno - Switch reads a bare 2-pin ON/OFF switch, and ESP32 S3 Uno - Button Module reads a push button on a 3-pin board like this one.
| Rocker switch module (this page) | Bare ON/OFF switch | Button module | |
|---|---|---|---|
| Stays where you leave it | yes | yes | no, it springs back |
| Pins | SIG, VCC, GND, labeled | 2 pins, no labels | VCC, OUT, GND, labeled |
| Resistor | pull-down on the board | internal pull-up of the pin | pull-down on the board |
| pinMode | INPUT | INPUT_PULLUP | INPUT |
| Level when ON or pressed | HIGH | LOW (inverted) | HIGH |
| Wires to the board | 3 | 2 | 3 |
The bare switch saves one wire. The module saves soldering, and its reading needs no translation: 1 means ON.
Ideas for the flip counter
- Machine log: count how many times a fan, a lamp or a 3D printer box is switched on during a day.
- Total run time: add up the seconds of every ON period to know how long a device really ran.
- Game rounds: let the rocker start and stop each round of a game, and count the rounds.
- Service reminder: print a message after 100 ON flips, as a reminder to check a part of the machine.
Function References
FAQ
Why does VCC go to 3.3V and not 5V on the ESP32 S3 Uno?
SIG is joined to VCC while the rocker is on "I". With 5V on VCC, GPIO14 would get 5V, and the ESP32 S3 Uno pins are made for 3.3V only. At 3.3V the module gives a clean HIGH and nothing is at risk.
The rocker was ON at start, but the total is 0. Is that a bug?
No. The sketch counts flips from OFF to ON. A rocker that is already on "I" at power-up was not turned on after the reset, so the sketch only reports the start position. Flip it to "O" and back to "I", and the total becomes 1.
Does the first sketch need a debounce?
No. It reads the pin only every 500 ms, and the bounce is over after a few milliseconds. The flip counter is different: it reacts to every change, so without the 50 ms quiet time one flip could add 2 or 3 to the total.
Can I use INPUT_PULLUP with this module?
It is not needed, and it is better to leave it out. The module already has a pull-down on SIG. An internal pull-up would pull the same wire the other way, and the OFF level could read badly. Use pinMode(pin, INPUT).
Can I put SIG on another pin?
Yes. D4 or D5 work well. Change ROCKER_SIG_PIN to the GPIO number of that pin (see the pinout image). Keep away from D0 and D1, which carry the USB serial data. Also keep away from D6 (GPIO3) and D9 (GPIO46). The chip checks those two pins at boot, so a rocker left ON could hold one of them HIGH during reset and stop the board from starting. With soldered headers, GPIO35 to GPIO42, GPIO15 and GPIO16 in the extra rows are good inputs too. GPIO47 and GPIO48 are output only, so they cannot read the rocker.
How do I keep the total after a power cut?
The counter is a normal variable in RAM, so it starts again from 0. To keep it, save the number to the flash memory of the ESP32-S3 after each ON flip, and read it back in setup().
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| Arduino IDE shows no COM port | no USB driver, or the cable only charges | Add the CP210x or CH340 driver, change to a data cable, or keep BOOT held while you tap RESET |
| SIG stays 0 in both positions | VCC wire missing, or the code uses 7 | Connect VCC to 3.3V and write 14 for D7 |
| SIG stays 1 in both positions | the SIG wire sits on the 3.3V pin, not on D7 | Move the SIG wire to D7 (GPIO14) |
| Total goes up by 2 for one flip | contact bounce | Set QUIET_TIME to 80 instead of 50 |
| The "Start position" line is missing | it was printed before you opened the Serial Monitor | Tap RESET on the board once |
| Strange characters in the Serial Monitor | wrong baud rate | Choose 9600 in the baud menu of the Serial Monitor |