ESP32 C3 Super Mini - Slide Switch

The ESP32 C3 Super Mini is about the size of a thumbnail, so it often ends up in very small boxes: a pocket BLE tag, a desk sensor, a tiny WiFi button. Such a gadget usually needs one setting that you change with a fingertip and that does not change back by itself - "beep" or "silent", "online" or "offline". The DIYables Mini Slide Switch SS12D10 is a good match. It is almost as small as the board, and its handle stays where you push it. Here, the C3 reads the switch on GPIO4 and tells you in the Serial Monitor whether it is ON or OFF.

In this tutorial, you'll learn:

ESP32 C3 Super Mini reads an SS12D10 slide switch on GPIO4 and prints ON or OFF

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×Mini Slide Switch SS12D10
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 Mini Slide Switch

The SS12D10 is a two-position switch that you move with the tip of a finger. A short plastic handle sticks out of the top, and three through-hole pins come out of the bottom in one row. Slide the handle to one end and it stays there - the switch is latching. A push button does the opposite: its spring lifts it back as soon as you let go. In parts lists, this type is called SPDT (single pole, double throw), or 1P2T.

Key Features:

  • Contact type: SPDT (1P2T), 2 positions
  • Pins: 3 in a row, 4.7 mm apart, 6.9 mm long
  • Handle: 5 mm long
  • Body size: about 12.8 x 6.7 x 18.2 mm
  • Mounting: vertical, through-hole
  • Contacts: silver-plated brass
  • Rating: AC 125V 2A
  • Lifetime: more than 100,000 switching cycles
  • Operating temperature: -25°C to 80°C

The 125V 2A rating is the most the contacts can carry. In this project, only a tiny signal current flows into GPIO4, so it is far below that limit.

Why the Slide Switch is Great for Beginners:

  • You can see the setting at a glance - the handle shows which side is chosen
  • It keeps its position, so your code never needs to remember the last press
  • With three wires, the input pin is always HIGH or LOW, so there are no random readings
  • No library is needed, only pinMode() and digitalRead()

Slide Switch Pinout

Nothing is printed on the switch. Just remember: the middle pin is always COM, and the two outer pins are pin 1 and pin 3.

  • Pin 1: outer pin. Connect this pin to GND of the ESP32 C3 Super Mini
  • Pin 2 (COM): the middle, common pin. Connect it to GPIO4. It carries the voltage of whichever outer pin the handle joins it to
  • Pin 3: outer pin. Connect it to the 3.3V pin (leave it free in the 2-wire version)

Inside the body, a small metal bridge always touches COM. It also touches the outer pin on the side where the handle is:

  • Handle toward pin 1: pins 1 and 2 are connected, pin 3 is open
  • Handle toward pin 3: pins 2 and 3 are connected, pin 1 is open
SS12D10 slide switch pinout - outer pin 1, middle COM pin 2, outer pin 3 and the two handle positions

※ NOTE THAT:

Slide switch, ON/OFF switch or button? All three give you HIGH or LOW on one pin. The ON/OFF switch is a bigger panel switch with two pins, made to turn a whole device on and off. The button and the button module spring back, so they suit short events like "next" or "start". Need four or eight settings at once? A DIP switch is a row of tiny slide switches in one block.

Wiring Diagram between Slide Switch and ESP32 C3 Super Mini

Plug the ESP32 C3 Super Mini and the slide switch into the same breadboard. Then run one wire from the hole next to each board pin to a hole in the column of the matching switch pin: GND to pin 1, GPIO4 (written as 4 in the code) to COM, and 3.3V to pin 3. No resistor is needed, because COM always touches either GND or 3.3V, so GPIO4 never floats.

Why GPIO4? It is not a strapping pin (GPIO2, GPIO8 and GPIO9 are), and it sits on the same side of the board as 3V3 and GND, so all three wires stay short.

The wiring diagram between ESP32 C3 Super Mini slide switch

This image is created using Fritzing. Click to enlarge image

Slide Switch Pin ESP32 C3 Super Mini Pin
Pin 1 GND
Pin 2 (COM) GPIO4
Pin 3 3.3V

※ NOTE THAT:

Two rules keep the board safe:

  • Pin 3 goes to 3.3V, never to 5V. With the handle toward pin 3, COM passes the pin 3 voltage straight to GPIO4. The ESP32-C3 pins are made for 3.3V only, and 5V can damage them.
  • GPIO4 stays an input. Never set it to OUTPUT while the switch is connected. The switch ties the pin directly to 3.3V or GND, so an output level that disagrees would cause a short.

Good to know: leave GPIO20 and GPIO21 free for this project. They are the serial RX and TX pins of the board. For a build that lasts, solder the wires to the switch legs instead of only pushing them on.

ESP32 C3 Super Mini Code - Slide Switch (3 Wires)

The sketch tells you where the handle is the moment the board starts. After that it stays quiet, and it prints one new line only when you move the handle.

What the code does:

  • Sets GPIO4 as a plain INPUT - the switch itself pulls the pin up or down
  • Reads the handle once in setup() and prints the start position
  • Checks GPIO4 over and over in loop()
  • When the level looks different, waits 50 ms for the contacts to settle and reads once more
  • Prints "ON" for HIGH (handle toward pin 3) or "OFF" for LOW (handle toward pin 1), but only if the change is still there
  • Ignores a short glitch that is gone after the wait
/* * 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-slide-switch */ // ESP32 C3 Super Mini - Slide Switch (3 wires): print the ON/OFF position of the DIYables Mini Slide Switch SS12D10 // No library is needed. // Wiring: pin 1 -> GND, pin 2 (COM, the middle pin) -> GPIO4, pin 3 -> 3.3V // Use 3.3V for pin 3, NOT 5V: COM passes this voltage straight to GPIO4, and the ESP32-C3 pins are 3.3V only. // The handle always joins COM to one of the outer pins, so GPIO4 is always driven HIGH or LOW. // That is why this circuit needs no pull-up or pull-down resistor. // handle toward pin 3 -> COM joined to 3.3V -> GPIO4 reads HIGH -> "ON" // handle toward pin 1 -> COM joined to GND -> GPIO4 reads LOW -> "OFF" #define SLIDE_SWITCH_PIN 4 // The ESP32 C3 SuperMini pin GPIO4 connected to the COM pin (pin 2) of the slide switch #define BOUNCE_TIME 50 // how long the metal contacts may bounce after the handle moves, in milliseconds int confirmed_level; // the last CONFIRMED level of GPIO4 (HIGH or LOW) // Print the handle position in words, based on the level of GPIO4 void printPosition(int level) { if (level == HIGH) // COM is joined to pin 3, which is wired to 3.3V Serial.println("The slide switch is ON (GPIO4 = HIGH)"); else // COM is joined to pin 1, which is wired to GND Serial.println("The slide switch is OFF (GPIO4 = LOW)"); } // 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) delay(1000); // short wait so the USB serial port is ready and the first lines are not lost // Plain INPUT: the switch itself drives the pin to 3.3V or to GND. // Never set this pin to OUTPUT - the switch ties it straight to 3.3V or GND, which would cause a short. pinMode(SLIDE_SWITCH_PIN, INPUT); Serial.println("ESP32 C3 Super Mini: slide switch test on GPIO4"); confirmed_level = digitalRead(SLIDE_SWITCH_PIN); // read the handle once, so the start position is known Serial.print("Handle at boot -> "); // label for the first line printPosition(confirmed_level); // then the start position, ON or OFF } // The loop function repeats indefinitely void loop() { int reading = digitalRead(SLIDE_SWITCH_PIN); // quick look at GPIO4 if (reading != confirmed_level) { // the pin looks different from the last confirmed level delay(BOUNCE_TIME); // the handle just moved: wait 50ms until the contacts stop bouncing reading = digitalRead(SLIDE_SWITCH_PIN); // read again, now that the contacts are steady if (reading != confirmed_level) { // the change is still there after the wait, so the handle really moved confirmed_level = reading; // save the new confirmed level Serial.print("Handle moved -> "); // label for a change printPosition(confirmed_level); // then the new position, ON or OFF } // if the second reading equals confirmed_level, the first one was only a bounce: ignore it } }

Detailed Instructions

  • New to ESP32 C3 Super Mini? Do our Getting Started with ESP32 C3 Super Mini tutorial first, so the ESP32 board package is ready in the Arduino IDE.
  • Make the circuit: Put the board and the switch on the breadboard, then add the three wires from the table: pin 1 to GND, COM to GPIO4, pin 3 to 3.3V.
  • Connect the board: Plug the ESP32 C3 Super Mini into your computer with a USB Type-C cable.
  • Open Arduino IDE: Select the ESP32 C3 Super Mini board and its COM port.
  • Copy the sketch: Paste the code above into a new sketch. There is no library to install.
  • Upload: Click the Upload button and wait until it is done.
How to upload ESP32 C3 Super Mini code on Arduino IDE
  • Open Serial Monitor: Set it to 115200 baud. To see the start line again, press the RST button on the board.
  • Move the handle: Start with the handle toward pin 1, then slide it across three times. You get one line per move:
∞
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
ESP32 C3 Super Mini: slide switch test on GPIO4 Handle at boot -> The slide switch is OFF (GPIO4 = LOW) Handle moved -> The slide switch is ON (GPIO4 = HIGH) Handle moved -> The slide switch is OFF (GPIO4 = LOW) Handle moved -> The slide switch is ON (GPIO4 = HIGH)
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • Pro Tip: If ON shows up when the handle points at pin 1, the GND and 3.3V wires are swapped. It does no harm: swap the two outer wires, or swap the two messages in the code. If the reading never changes, check that the middle pin, not an outer one, goes to GPIO4. An empty Serial Monitor usually means USB CDC On Boot is Disabled in the Tools menu - enable it and upload again.

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 - Slide Switch with INPUT_PULLUP (2 Wires)

Want one wire less, and no 3.3V wire at all? Every GPIO of the ESP32-C3 has a pull-up resistor inside, and INPUT_PULLUP turns it on. So you can just remove the pin 3 wire. GND and GPIO4 stay as they are.

The wiring diagram between ESP32 C3 Super Mini slide switch INPUT_PULLUP

This image is created using Fritzing. Click to enlarge image

Slide Switch Pin ESP32 C3 Super Mini Pin
Pin 1 GND
Pin 2 (COM) GPIO4
Pin 3 Not connected

Be careful, the logic is now upside down:

  • Handle toward pin 1: COM is joined to GND, GPIO4 reads LOW, and the sketch prints ON
  • Handle toward pin 3: COM touches nothing, the pull-up holds GPIO4 HIGH, and the sketch prints OFF

What the code does:

  • Sets GPIO4 as INPUT_PULLUP, so the pin rests at HIGH when COM is open
  • Uses the same start-up read and 50 ms bounce check as the first sketch
  • Treats LOW as ON and HIGH as OFF
/* * 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-slide-switch */ // ESP32 C3 Super Mini - Slide Switch (2 wires, INPUT_PULLUP): print the ON/OFF position of the DIYables Mini Slide Switch SS12D10 // No library is needed. // Wiring: pin 1 -> GND, pin 2 (COM, the middle pin) -> GPIO4, pin 3 -> not connected // There is no 3.3V wire. The pull-up resistor inside GPIO4 holds the pin HIGH while COM touches nothing. // Because of this, the logic is the OPPOSITE of the 3-wire version: // handle toward pin 1 -> COM joined to GND -> GPIO4 reads LOW -> "ON" // handle toward pin 3 -> COM is open -> the pull-up makes GPIO4 read HIGH -> "OFF" #define SLIDE_SWITCH_PIN 4 // The ESP32 C3 SuperMini pin GPIO4 connected to the COM pin (pin 2) of the slide switch #define BOUNCE_TIME 50 // how long the metal contacts may bounce after the handle moves, in milliseconds int confirmed_level; // the last CONFIRMED level of GPIO4 (HIGH or LOW) // Print the handle position in words, based on the level of GPIO4 void printPosition(int level) { if (level == LOW) // LOW means COM is joined to pin 1 (GND): with a pull-up, LOW is the active state Serial.println("The slide switch is ON (GPIO4 = LOW)"); else // HIGH means COM is open and only the internal pull-up holds the pin up Serial.println("The slide switch is OFF (GPIO4 = HIGH)"); } // 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) delay(1000); // short wait so the USB serial port is ready and the first lines are not lost // INPUT_PULLUP turns on the resistor inside GPIO4 that pulls the pin up to 3.3V. // Without it, GPIO4 would "float" (random readings) whenever the handle is toward pin 3. // Never set this pin to OUTPUT - the switch can tie it straight to GND, which would cause a short. pinMode(SLIDE_SWITCH_PIN, INPUT_PULLUP); Serial.println("ESP32 C3 Super Mini: slide switch test on GPIO4 (INPUT_PULLUP, 2 wires)"); confirmed_level = digitalRead(SLIDE_SWITCH_PIN); // read the handle once, so the start position is known Serial.print("Handle at boot -> "); // label for the first line printPosition(confirmed_level); // then the start position, ON or OFF } // The loop function repeats indefinitely void loop() { int reading = digitalRead(SLIDE_SWITCH_PIN); // quick look at GPIO4 if (reading != confirmed_level) { // the pin looks different from the last confirmed level delay(BOUNCE_TIME); // the handle just moved: wait 50ms until the contacts stop bouncing reading = digitalRead(SLIDE_SWITCH_PIN); // read again, now that the contacts are steady if (reading != confirmed_level) { // the change is still there after the wait, so the handle really moved confirmed_level = reading; // save the new confirmed level Serial.print("Handle moved -> "); // label for a change printPosition(confirmed_level); // then the new position, ON or OFF } // if the second reading equals confirmed_level, the first one was only a bounce: ignore it } }

Detailed Instructions

  • Change the wiring: Take the pin 3 wire off the 3.3V hole. Keep the GND and GPIO4 wires.
  • Upload: Paste this sketch into the Arduino IDE and click Upload.
  • Open Serial Monitor: Keep 115200 baud and press the RST button once.
  • Try it: This time, start with the handle toward pin 3 and slide it across four times:
∞
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
ESP32 C3 Super Mini: slide switch test on GPIO4 (INPUT_PULLUP, 2 wires) Handle at boot -> The slide switch is OFF (GPIO4 = HIGH) Handle moved -> The slide switch is ON (GPIO4 = LOW) Handle moved -> The slide switch is OFF (GPIO4 = HIGH) Handle moved -> The slide switch is ON (GPIO4 = LOW) Handle moved -> The slide switch is OFF (GPIO4 = HIGH)
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • Pro Tip: Leave pin 3 empty in this version. If pin 3 went to GND, both handle positions would read LOW, and the sketch could never see OFF.

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 slide switch is the right part for a setting that you choose once and then leave alone. Some ideas for the ESP32 C3 Super Mini:

  • Online or offline: read the switch in setup() and only start WiFi when it is ON, to save battery
  • Silent mode: mute the buzzer of an alarm or a timer without changing the code
  • Celsius or Fahrenheit: pick the unit for a temperature sensor display
  • Setup mode: with the switch ON at power-up, open a WiFi hotspot for the settings page
  • BLE tag on/off: stop a small Bluetooth beacon from sending without pulling out the battery
  • Data logger: start and stop saving readings with one slide

Video Tutorial

Challenge Yourself

Practice what you learned with these tasks:

  • Easy: Light the onboard blue LED (GPIO8) while the switch is ON - see ESP32 C3 Super Mini - LED - Blink for LED code
  • Easy: Count how many times the handle has moved and print the number with each line
  • Medium: Add a second slide switch on GPIO3 and print one of four modes: 00, 01, 10 or 11
  • Medium: Make an LED blink fast when the switch is ON and slowly when it is OFF, without using delay()
  • Advanced: Read the switch only once in setup() and join your WiFi network only when it is ON
  • Advanced: Show the switch position on a web page hosted by the ESP32 C3 Super Mini

Language References

※ 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!