ESP32 S3 - Rocker Switch Module
Some choices in a project are made once and then left alone for hours: test mode or normal mode, sound on or off, metric or imperial. A rocker switch suits this kind of choice well, because everyone can see its position from across the desk, and it never moves by itself. In this guide, the ESP32 S3 first reads the DIYables ON/OFF Rocker Switch Module, and then gives it a real job: deciding if the temperature of the ESP32-S3 chip is shown in Celsius or in Fahrenheit.
What you'll build in this tutorial:
- What the rocker switch module is, and why its SIG pin is HIGH when the rocker is on "I"
- How to connect SIG, VCC and GND to GPIO21, 3V3 and GND of the ESP32 S3
- A simple test sketch that shows ON or OFF about three times per second
- A second sketch where the rocker selects the unit of the chip temperature: OFF for °C, ON for °F

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables ESP32 S3 Starter Kit (ESP32 S3 included) | |
| 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

You have seen this switch many times. It is the black rocker on power strips and on the back of many devices. DIYables mounts a KCD1 rocker of this kind on a small blue board with a mounting hole in each corner and a 3-pin right-angle header on one edge. One end of the rocker carries the mark "I", which means ON. The other end carries "O", which means OFF. Beside the rocker, the board says "ON (H)" and "OFF (L)": H stands for a HIGH level on the signal pin, L for a LOW level.
In switch language, this rocker is "maintained" (some shops say "latching"). Push one end down and it stays there until you push the other end. A push button behaves in another way: it is only active while your finger is on it. So there is no "press" for the code to catch. The ESP32 S3 looks at the current position, ON or OFF, and it can do something at the moment that position changes. Think of the rocker as a setting, not as a command.
Inside, the module is simple. The switch is a single SPST contact between VCC and SIG, and a 10 kΩ pull-down resistor (marked "103") is soldered on the board as well. With the rocker on "O", the resistor holds SIG at 0V. With the rocker on "I", the contact connects SIG to VCC. You add no resistor of your own, and nothing is inverted: ON reads HIGH, OFF reads LOW.
Key Specifications
| Item | Value |
|---|---|
| Switch | KCD1 rocker, SPST, maintained (latching) |
| Marks on the rocker | I = ON, O = OFF |
| Supply voltage (VCC) | 3.3V to 5V (3.3V on the ESP32 S3) |
| SIG when ON | HIGH, the same voltage as VCC |
| SIG when OFF | LOW (0V) |
| Resistor on the board | 10 kΩ pull-down (103) |
| Header | 3 pins, 2.54 mm pitch, right-angle male |
| Board | about 24 x 24 mm, 4 mounting holes |
| Size with the pins | about 24 x 29 x 22 mm |
| Pack | 5 modules |
There is also "6A 250VAC / 10A 125VAC" molded into the side of the switch. Those numbers describe the switch as a loose part, not the module. Here the switch only passes a small logic signal to a GPIO pin, so never send mains power or a motor current through the three header pins.
Rocker Switch Module Pinout
Turn the board over to read the pin names; they sit right behind the header. Seen from the top, with the header pointing to the right, the order from top to bottom is:
- SIG — the output; HIGH (the VCC voltage) while the rocker is on "I", LOW (0V) while it is on "O" (GPIO21 in this guide)
- VCC — supply input, rated 3.3V to 5V; on the ESP32 S3 it always goes to the 3V3 pin
- GND — ground (0V), shared with the ESP32 S3
How does this compare with the parts on our other pages? The bare 2-leg switch in ESP32 S3 - Switch also stays in place, but it has no resistor, so it needs INPUT_PULLUP and reads LOW for ON, which feels upside down. The ESP32 S3 - Button Module has the same 3-pin shape and the same pull-down, but its key springs back. The rocker module takes the best part of both: it holds its position like the bare switch, and it gives a plain HIGH for ON like the button module.
Wiring Diagram
The resistor is already on the module, so three jumper wires make the whole circuit. Run SIG to GPIO21, VCC to 3V3, and GND to one of the GND pins of the ESP32 S3.

This image is created using Fritzing. Click to enlarge image
| Rocker Switch Module Pin | ESP32 S3 Pin |
|---|---|
| SIG | GPIO21 |
| VCC | 3V3 |
| GND | GND |
Pushing jumper wires into the headers is quick, but the wires can slip out. The ESP32 S3 fits a Screw Terminal Block for ESP32 S3, which turns every pin into a screw terminal. See the diagram below for the screw terminal version.

This image is created using Fritzing. Click to enlarge image
Another choice is a GPIO Breakout Board for ESP32 S3. Each GPIO has a signal pin with 3.3V and GND pins next to it, as shown below:

This image is created using Fritzing. Click to enlarge image
Safety Notes
Take VCC from the 3V3 pin, never from the 5V pin. When the rocker is ON, SIG simply carries whatever voltage VCC has, and the GPIO pins of the ESP32 S3 are made for 3.3V only, so a 5V supply would push 5V into GPIO21. At 3.3V the module works just as well. A rocker is also often left ON while you plug in the USB cable or upload a sketch. That is fine on GPIO21, because it is not one of the pins the chip checks at boot, so the board starts normally in both rocker positions.
How To Program For Rocker Switch Module
Reading the module needs one pin and two functions. In setup(), pinMode() makes GPIO21 a plain INPUT; INPUT_PULLUP stays out, because the module already brings its pull-down. In loop(), digitalRead() returns HIGH for ON and LOW for OFF. The first sketch only prints that value. The second sketch also reacts to changes, so it accepts a new rocker position only after the pin has stayed the same for 50 ms, and it measures that time with millis() instead of delay(). It reads the chip temperature with temperatureRead(), a function of the ESP32 Arduino core, so you install no library for either sketch.
ESP32 S3 Code - Read the Rocker Switch Position
This sketch checks your wiring. About three times per second it reads GPIO21 and prints the rocker position next to the raw value. Contact bounce does not matter here. The contacts settle within a few milliseconds, and the next reading comes 300 ms later.
Detailed Instructions
- New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
- Make the three connections from the table: SIG to GPIO21, VCC to 3V3, GND to GND. Make sure that VCC goes to 3V3 and not to 5V.
- Plug the ESP32 S3 into your computer with the Type-C cable.
- In the Arduino IDE, pick the ESP32 S3 board under Tools > Board and its port under Tools > Port.
- Copy the code into a new sketch and click Upload.
- Start the Serial Monitor with the baud rate at 9600.
- Push the "I" end of the rocker down, wait a second or two, then push the "O" end.
- Pro Tip: If the monitor always says OFF, the VCC wire is probably loose. If it always says ON, the wire on GPIO21 may come from VCC instead of SIG; check the labels on the back of the module.
Take your hand away from the rocker and the line does not change. That is the latching behavior at work. A button module would drop back to 0 the moment you let go.
ESP32 S3 Code - Rocker Switch Selects Celsius or Fahrenheit
Now the rocker gets a real job. The ESP32-S3 chip has a small temperature sensor inside, and temperatureRead() returns its value in degrees Celsius as a float. The sketch prints this value once per second. With the rocker on "O" (OFF), you see Celsius. With the rocker on "I" (ON), the same value is turned into Fahrenheit with °F = °C × 9 / 5 + 32. Each time you flip the rocker, one extra line names the new unit, so you know exactly when the change happened.
※ NOTE THAT:
This is the temperature of the chip itself, not of the air in the room. The chip warms up while it runs, so the value is usually far above room temperature, often between 35 and 50 °C. It is a fine number for this demo and for keeping an eye on the board. To measure the room, use a real sensor, for example the DS18B20 in ESP32 S3 - Temperature Sensor.
This time the code reacts to a change, so bounce matters: one flip could look like ON, OFF, ON within a few milliseconds and print three unit lines. To stop that, the sketch saves the time of every raw change on GPIO21 with millis(). It trusts the new position only after GPIO21 has stayed the same for 50 ms. Since there is no delay() in loop(), the once-per-second print keeps its pace while you play with the rocker.
Detailed Instructions
- Keep the wiring as it is.
- Upload this sketch the same way as the first one.
- Open the Serial Monitor at 9600 baud. The line with the start unit is printed only once, at power-up, so press the RESET button of the ESP32 S3 if you missed it.
- Wait a few seconds, flip the rocker to "I", wait again, then flip it back to "O".
- Pro Tip: Prefer ON for Celsius? Change unitLevel == HIGH to unitLevel == LOW in both places, and the rocker works the other way round.
In the first minutes after power-up the value creeps up slowly, while the chip warms to its working temperature. After that it stays almost flat.
Application and Project Ideas
A rocker fits any setting that should stay put and be easy to see at a glance.
- Metric or imperial display: Show a real air sensor on a small screen, and let the rocker pick °C or °F, hPa or inHg.
- Night mute: Silence a buzzer alarm by turning the rocker OFF, while the rest of the project keeps working.
- Service mode: With the rocker ON, the ESP32 S3 skips its normal task and prints debug data instead.
- Upload pause: Keep a WiFi data logger measuring, but stop sending to the cloud while the rocker is OFF.
- Chip heat watch: Print a warning when the chip temperature passes a limit you choose, and use the rocker to turn the warning on or off.
Challenge Yourself
- Beginner: Print the temperature every 3 seconds instead of every second, and put the seconds since start (millis() / 1000) at the front of each line.
- Intermediate: Remember the highest chip temperature since power-up, and print it in the selected unit after every 10 readings.
- Advanced: Show the chip temperature on a small web page over WiFi, and let the rocker choose the unit that the page displays.