ESP32 C3 Super Mini - Rocker Switch Module

Many power strips have a rocker switch that glows while the strip is on, so you can see its state from across the room. The DIYables ON/OFF Rocker Switch Module uses the same black KCD1 rocker, but without a lamp inside. In this tutorial the ESP32 C3 Super Mini adds the missing light: first it reads the switch and prints ON or OFF, then its small blue on-board LED becomes the pilot light that follows the rocker.

In this tutorial, you'll learn:

ESP32 C3 Super Mini reads a DIYables rocker switch module on GPIO7 and lights its blue on-board LED while the switch is ON

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×ON/OFF Rocker Switch Module
1×Breadboard
1×Jumper Wires

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of the Rocker Switch Module

The module is a black KCD1 rocker switch soldered on a small blue board, about 24 x 24 mm, with a mounting hole in each corner and a 3-pin right-angle header on one side. Press the side of the rocker marked "I" and the switch is ON. Press the side marked "O" and it is OFF. The text printed on the board says the same thing in logic words: "ON (H)" and "OFF (L)".

The rocker does not spring back like a push button. It is a maintained (latching) switch: it stays on the side you pressed until you press the other side. So the code does not wait for a click. It asks which position the switch is in right now, and it reacts when that position changes.

There is a 10 kΩ pull-down resistor on the board (marked "103"). While the switch is OFF, the resistor holds SIG at 0V. When the switch is ON, the switch itself connects SIG to VCC. That is why the ESP32 C3 Super Mini reads HIGH for ON and LOW for OFF, and the pin never floats.

Key Features:

  • SPST rocker switch that keeps its position by itself
  • Two clear marks on the rocker: "I" = ON, "O" = OFF
  • Works from 3.3V to 5V - use 3.3V with the ESP32 C3 Super Mini
  • Pull-down resistor on the board, so INPUT is enough - no external resistor, no INPUT_PULLUP
  • Not inverted: ON gives HIGH, OFF gives LOW
  • Four mounting holes, so you can fix it behind a cut-out in a box lid
  • Sold in a pack of 5

Why the Rocker Switch Module is Great for Beginners:

  • You see the switch state with your eyes, even when the board is off
  • Three labeled pins and three jumper wires - nothing to solder
  • No resistor to choose and no upside-down logic to remember
  • One sketch shape fits many uses: start/stop, enable/disable, mode A/mode B
Item Value
Switch type KCD1 rocker, SPST, maintained (latching)
Positions I = ON (SIG is HIGH), O = OFF (SIG is LOW)
Supply voltage (VCC) 3.3V to 5V
Pull-down resistor 10 kΩ, on the board
Header 3 pins, 2.54 mm, right-angle
Size with the pins about 24 x 29 x 22 mm

Rocker Switch Module Pinout

Hold the module with the rocker facing you and the header on the right. From top to bottom, the pins are SIG, VCC and GND. The pin names are printed on the back of the board, so from that side you read GND, VCC, SIG. GND is the pin with the square pad.

  • SIG pin: the output of the switch. It is HIGH (3.3V in this project) while the switch is ON and LOW (0V) while it is OFF. Connect it to GPIO7.
  • VCC pin: the supply, 3.3V to 5V. On the ESP32 C3 Super Mini, connect it to the 3.3V pin only.
  • GND pin: ground. Connect it to a GND pin of the board.
Rocker switch module pinout - SIG, VCC and GND on the 3-pin header of the DIYables board
image source: diyables.io

※ NOTE THAT:

Rocker module or bare ON/OFF switch? The ESP32 C3 Super Mini - Switch tutorial uses a bare switch with two legs. There, one leg goes to GND, the code turns on INPUT_PULLUP, and ON reads as LOW, which is easy to get backwards. The module removes those steps: its pins have labels, it has its own pull-down, and ON reads as HIGH. If you need a part that springs back after each press, look at the ESP32 C3 Super Mini - Button Module tutorial instead.

Wiring Diagram between Rocker Switch Module and ESP32 C3 Super Mini

In the drawing, the ESP32 C3 Super Mini sits on a breadboard. The rocker switch module does not go into the breadboard: it stays beside it, and three jumper wires join its own header to the board. SIG goes to GPIO7 (simply 7 in the code), VCC goes to 3.3V, and GND goes to GND.

Why GPIO7? It is not a strapping pin. You may leave the rocker on the "I" side while you plug in the USB cable: GPIO7 is then HIGH at power-up, and that does not change how the board starts. GPIO2, GPIO8 and GPIO9 are strapping pins, so it is better to keep switches away from them. GPIO8 has a job in the second example anyway: it drives the blue on-board LED.

The wiring diagram between ESP32 C3 Super Mini Rocker Switch Module

This image is created using Fritzing. Click to enlarge image

Rocker Switch Module Pin ESP32 C3 Super Mini Pin
SIG GPIO7
VCC 3.3V
GND GND

※ NOTE THAT:

Keep VCC on 3.3V. With the rocker on the "I" side, the SIG pin passes the VCC voltage straight to GPIO7. The ESP32-C3 is a 3.3V chip, so 5V on VCC could damage the pin. Never use the 5V pin for this module.

The rating on the switch body is not for the header. The "6A 250VAC / 10A 125VAC" print is the rating of the bare switch. This module only sends a small logic signal to a GPIO pin. Never run mains power or motor current through its pins.

ESP32 C3 Super Mini Code - Read the Rocker Switch Position

The first sketch checks the wiring. About three times per second it reads GPIO7 and prints the level, the word ON or OFF, and which side of the rocker is pressed. It has no debounce: a bounce lasts only a few milliseconds, and with readings 300 ms apart it does no harm.

What the code does:

  • Sets GPIO7 as a plain INPUT - the module's pull-down keeps it LOW while the switch is OFF
  • Reads SIG with digitalRead(), which gives 1 (HIGH) or 0 (LOW)
  • Prints [ ON] or [OFF] at the start of each line, then the raw level and the pressed side
  • Waits 300 milliseconds and reads again
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-rocker-switch-module */ // ESP32 C3 Super Mini - Rocker Switch Module: read the switch position and print ON or OFF // No library is needed. The module has its own pull-down resistor, so SIG is // LOW (0) when the rocker is on the "O" side and HIGH (1) when it is on the "I" side. // Power the module from 3.3V, NOT 5V: when the switch is ON, SIG gives out the VCC voltage. #define ROCKER_PIN 7 // The ESP32 C3 SuperMini pin GPIO7 connected to the SIG pin of the rocker switch module #define READ_INTERVAL 300 // time between two readings, in milliseconds (about 3 readings per second) // The setup function runs once on reset or power-up void setup() { Serial.begin(115200); // start the Serial Monitor at 115200 baud (enable "USB CDC On Boot" in Arduino IDE) // Plain INPUT: the pull-down resistor on the module keeps SIG at LOW while the switch is OFF. // Do NOT use INPUT_PULLUP here - it would work against the module's pull-down resistor. pinMode(ROCKER_PIN, INPUT); Serial.println("Rocker switch module on GPIO7 - one reading every 0.3 s"); } // The loop function repeats indefinitely void loop() { int level = digitalRead(ROCKER_PIN); // read GPIO7: 1 (HIGH) = switch ON, 0 (LOW) = switch OFF // The logic is NOT inverted: HIGH really means ON if (level == HIGH) { Serial.print("[ ON] GPIO7 = 1 (HIGH)"); // the switch links SIG to VCC (3.3V) Serial.println(" - \"I\" side pressed"); } else { Serial.print("[OFF] GPIO7 = 0 (LOW) "); // the pull-down resistor holds SIG at 0V Serial.println(" - \"O\" side pressed"); } // No debounce is needed here: the contacts bounce for only a few milliseconds, // and the readings are 300 ms apart, so the bounce does no harm to this output. delay(READ_INTERVAL); }

Detailed Instructions

  • First time with this board? Follow the Getting Started with ESP32 C3 Super Mini tutorial, so the ESP32 board package is ready in the Arduino IDE.
  • Wire it up: Put the ESP32 C3 Super Mini on the breadboard, keep the rocker module next to it, and add the three jumper wires from the table: SIG to GPIO7, VCC to 3.3V, GND to GND.
  • Connect the board: Plug it into your computer with a USB Type-C cable.
  • Open Arduino IDE: Then pick the ESP32 C3 Super Mini board and the COM port it uses.
  • Add the code: Copy the sketch above into a new sketch. No library is needed.
  • Upload: Click the Upload button and wait for "Done uploading".
How to upload ESP32 C3 Super Mini code on Arduino IDE
  • Open Serial Monitor: Set it to 115200 baud.
  • Test it: Start with the "O" side pressed. Press the "I" side, wait about two seconds, then press "O" again. The lines change from [OFF] to [ ON] and back:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
Rocker switch module on GPIO7 - one reading every 0.3 s [OFF] GPIO7 = 0 (LOW) - "O" side pressed [OFF] GPIO7 = 0 (LOW) - "O" side pressed [OFF] GPIO7 = 0 (LOW) - "O" side pressed [ ON] GPIO7 = 1 (HIGH) - "I" side pressed [ ON] GPIO7 = 1 (HIGH) - "I" side pressed [ ON] GPIO7 = 1 (HIGH) - "I" side pressed [ ON] GPIO7 = 1 (HIGH) - "I" side pressed [ ON] GPIO7 = 1 (HIGH) - "I" side pressed [ ON] GPIO7 = 1 (HIGH) - "I" side pressed [ ON] GPIO7 = 1 (HIGH) - "I" side pressed [OFF] GPIO7 = 0 (LOW) - "O" side pressed [OFF] GPIO7 = 0 (LOW) - "O" side pressed
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • Pro Tip: Every line says [OFF], whatever side you press? Check the VCC wire first: without power, the switch has nothing to pass on to SIG. Every line says [ ON]? SIG may touch the 3.3V wire. Nothing appears at all? In the Tools menu, set USB CDC On Boot to Enabled and upload once more.

Line-by-line Code Explanation

The above ESP32 C3 Super Mini code contains line-by-line explanation. Please read the comments in the code!

ESP32 C3 Super Mini Code - Blue On-board LED as a Pilot Light

Now the switch gets its light. The ESP32 C3 Super Mini has a small blue LED on GPIO8. It is active LOW: writing LOW turns it on, and writing HIGH turns it off. This sketch makes the LED copy the rocker, so it is lit while the switch is ON and dark while it is OFF. It also prints one line each time the position changes.

Because this sketch reacts to changes, a bounce must not count as a flip. A small millis() timer takes care of that: a new level is accepted only after it has stayed the same for 50 ms. A timer, unlike delay(), never stops the loop, so you can add WiFi or a sensor to this sketch later.

What the code does:

  • Sets GPIO7 as an input for the switch and GPIO8 as an output for the blue LED
  • Reads the switch once in setup(), sets the LED to match, and prints the start-up position
  • In loop(), restarts a 50 ms timer each time the raw level of GPIO7 moves
  • Accepts the new level only when 50 ms pass with no more movement
  • Writes LOW to GPIO8 for ON (LED lit) and HIGH for OFF (LED dark)
  • Prints the new state and the time since start-up, in seconds
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-rocker-switch-module */ // ESP32 C3 Super Mini - Rocker Switch Module: the blue on-board LED works as a pilot light // The LED is lit while the rocker is ON ("I" side) and dark while it is OFF ("O" side). // A new switch position is accepted only after it stays the same for 50 ms (debounce), // and one line is printed for every real change. No library is needed. // Power the module from 3.3V, NOT 5V: when the switch is ON, SIG gives out the VCC voltage. #define ROCKER_PIN 7 // The ESP32 C3 SuperMini pin GPIO7 connected to the SIG pin of the rocker switch module #define LED_PIN 8 // The ESP32 C3 SuperMini pin GPIO8 drives the small blue on-board LED #define LED_ON LOW // the on-board LED is active LOW: writing LOW turns it on #define LED_OFF HIGH // ... and writing HIGH turns it off #define DEBOUNCE_MS 50 // a new level must stay the same for 50 ms before we accept it int stable_state; // the last ACCEPTED switch level (HIGH = ON, LOW = OFF) int last_raw; // the level seen in the previous loop, bounces included unsigned long last_move_ms = 0; // the time (millis) when the raw level last moved // Make the LED copy the switch: lit for ON, dark for OFF void showOnLed(int state) { if (state == HIGH) digitalWrite(LED_PIN, LED_ON); // switch ON -> LOW on GPIO8 -> LED lit else digitalWrite(LED_PIN, LED_OFF); // switch OFF -> HIGH on GPIO8 -> LED dark } // The setup function runs once on reset or power-up void setup() { Serial.begin(115200); // start the Serial Monitor at 115200 baud (enable "USB CDC On Boot" in Arduino IDE) pinMode(ROCKER_PIN, INPUT); // plain INPUT: the module's own pull-down resistor keeps SIG LOW when OFF pinMode(LED_PIN, OUTPUT); // GPIO8 drives the on-board LED // Read the switch once at start-up, so the LED is right from the first moment. // GPIO7 is not a strapping pin, so a switch left ON at power-up does not change how the board starts. stable_state = digitalRead(ROCKER_PIN); last_raw = stable_state; showOnLed(stable_state); Serial.println("Pilot light on GPIO8 follows the rocker on GPIO7"); Serial.print("Start-up position: "); Serial.println(stable_state == HIGH ? "ON -> blue LED lit" : "OFF -> blue LED dark"); } // The loop function repeats indefinitely void loop() { int raw = digitalRead(ROCKER_PIN); // quick look at SIG, it may still be bouncing if (raw != last_raw) { // the level moved since the last loop (a flip, or a bounce) last_raw = raw; // remember the new raw level last_move_ms = millis(); // and restart the 50 ms timer } // Accept the new level only if it is different from the accepted one // AND it has not moved for at least 50 ms. This timer never blocks the loop. if (raw != stable_state && millis() - last_move_ms >= DEBOUNCE_MS) { stable_state = raw; // the change is real: save it showOnLed(stable_state); // update the pilot light if (stable_state == HIGH) Serial.print("ON -> blue LED lit (at "); else Serial.print("OFF -> blue LED dark (at "); Serial.print(millis() / 1000.0, 1); // time since start-up, in seconds with one decimal Serial.println(" s)"); } // Other work can go here (WiFi, a sensor, a web page...). Nothing above waits with delay(). }

Detailed Instructions

  • Same wiring: Nothing moves. The module stays on GPIO7, and the LED is already on the board.
  • Add the code: Paste the pilot-light sketch into a new sketch.
  • Upload: Click the Upload button.
  • Open Serial Monitor: Keep 115200 baud.
  • Test it: Flip the rocker a few times and watch the small blue LED on the board. Each flip gives exactly one line, even when the contacts bounce:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
Pilot light on GPIO8 follows the rocker on GPIO7 Start-up position: OFF -> blue LED dark ON -> blue LED lit (at 4.6 s) OFF -> blue LED dark (at 9.1 s) ON -> blue LED lit (at 12.8 s) OFF -> blue LED dark (at 21.3 s) ON -> blue LED lit (at 23.0 s)
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • Pro Tip: Press the "I" side first, then press the reset button (or plug in the USB cable). The LED lights at once and the first line says ON, because setup() reads the switch before loop() starts. GPIO7 is not a strapping pin, so the board still starts normally.

Line-by-line Code Explanation

The above ESP32 C3 Super Mini code contains line-by-line explanation. Please read the comments in the code!

Applications and Project Ideas

A rocker switch suits settings that should stay put and be easy to see. Some ideas for the ESP32 C3 Super Mini:

  • Do not disturb: mute the buzzer and the notification light of a small gadget while the switch is ON
  • Holiday mode: stop the alarms of a plant or room monitor while you are away
  • Thermostat enable: let a temperature sketch switch its relay only while the rocker is ON
  • Maintenance lock: while the switch is ON, a machine controller ignores its start button
  • Two light shows: pick between a calm and a party pattern for an LED strip
  • Remote status: show the rocker position on a web page hosted by the ESP32 C3 Super Mini

Video Tutorial

Challenge Yourself

Try these tasks to go one step further:

  • Easy: Turn the pilot light around: light the blue LED while the switch is OFF, like a "standby" lamp
  • Easy: Count how many times the switch went ON and print the total with each change
  • Medium: While the switch is ON, blink the LED once per second with millis() instead of keeping it lit - the ESP32 C3 Super Mini - LED - Blink Without Delay tutorial shows how
  • Medium: Every 10 seconds, print a short summary: the current position and the number of flips so far
  • Advanced: Read the rocker in setup() and join your WiFi network only when it is ON; light the LED once the connection is made
  • Advanced: Add the button module on GPIO6 and count its clicks only while the rocker is ON

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!