ESP32 S3 UNO - Slide Switch
Toy cars, pocket torches and battery boxes often have a tiny lever on the side that you push left or right. That lever is a slide switch. Move it once and it stays put, so it is a good fit for a setting that should not change by itself, like "sound on" or "test mode". In this guide, the ESP32 S3 Uno watches such a switch on header pin D7 and tells you in the Serial Monitor which side the lever is on.
Your path through this page:
- Look inside the DIYables SS12D10 and see which pins join for each lever position
- Build a 3-wire circuit with no resistor, with pin 3 on 3.3V
- Upload a sketch that prints the start position and then every move, with a 50 ms debounce
- Remove one wire and let the internal pull-up of GPIO14 do the work instead

No library is needed. Both sketches use only pinMode() and digitalRead(), which come with the ESP32 core in Arduino IDE.
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 Slide Switch
The DIYables Mini Slide Switch SS12D10 is a small switch with two positions. A short plastic handle sticks out of the top of the metal body, and three pins come out of the bottom in one straight row. It is a latching switch: the handle stays on the side where you leave it. A push button works another way, because it jumps back as soon as you lift your finger.
Inside the body, a small metal bridge moves with the handle. It always touches the middle pin, and it also touches the outer pin on the handle's side. The middle pin takes part in both positions, so it is called COM (common).

No labels are printed on the switch. Count the pins from one end:
- Pin 1: an outer pin. On this page it always goes to GND.
- Pin 2 (COM): the middle pin, the common one. It goes to the input pin D7 (GPIO14).
- Pin 3: the other outer pin. It goes to 3.3V in the 3-wire circuit and stays free in the 2-wire circuit.
| Handle position | Pins joined inside | Pin left open |
|---|---|---|
| Toward pin 1 | pin 1 and pin 2 (COM) | pin 3 |
| Toward pin 3 | pin 2 (COM) and pin 3 | pin 1 |
| Mini Slide Switch SS12D10 | |
|---|---|
| Contact type | SPDT (1P2T), 2 positions |
| Pins | 3 in one row, 4.7mm pitch |
| Terminal length | 6.9mm |
| Handle length | 5mm |
| Body size | about 12.8 x 6.7 x 18.2mm |
| Mounting | vertical, through-hole |
| Contacts | silver-plated brass |
| Contact rating | AC 125V 2A |
| Life | more than 100,000 switching cycles |
| Working temperature | -25°C to 80°C |
The 125V 2A rating tells you how much the contacts can carry. In this project the switch only passes a tiny signal current into GPIO14, so it has a very easy job.
ESP32 S3 Uno Pinout
Here is the pinout of the ESP32 S3 Uno form board. This project needs three spots: the 3.3V pin and a GND pin on the power header, and D7 on the digital header. The code does not write 7 for D7. It uses the chip's own number for that pin, which is GPIO14.

Wiring Diagram
Three jumper wires are all this circuit needs. Pin 1 sits on GND and pin 3 sits on 3.3V, so COM, and with it D7, is always tied to one of them. The input never floats, and you do not need a pull-up or pull-down resistor.

This image is created using Fritzing. Click to enlarge image
| Slide Switch Pin | ESP32 S3 Uno Pin |
|---|---|
| Pin 1 | GND |
| Pin 2 (COM) | D7 (GPIO14) |
| Pin 3 | 3.3V |
Jumper wires can come loose when you move the project. A Screw Shield V2 or a Proto Screw Terminal Block Shield solves this. Plug it into the ESP32 S3 Uno and screw the wires in. Below is the wiring diagram with the Screw Shield V2.

This image is created using Fritzing. Click to enlarge image
WARNING
Pin 3 belongs on the 3.3V pin. Never connect it to 5V or VIN. When the handle points to pin 3, COM passes that voltage straight into GPIO14. The ESP32 S3 Uno GPIOs are 3.3V only and are not 5V tolerant, so 5V there can damage the pin or even the chip.
※ NOTE THAT:
Keep D7 as an INPUT in your code. Never set it to OUTPUT. The switch ties the pin hard to 3.3V or to GND, and an output pin that drives the other level would push a large current through the switch.
Why D7? On this board GPIO14 is a plain I/O pin with no boot strapping job. The handle can be in either position while you reset the board or upload a sketch.
How To Program For Slide Switch
The switch already pushes D7 firmly to 3.3V or GND, so the sketch has little to do: read one pin and decide what the level means.
- Give the pin a name. The ESP32 core counts in GPIO numbers, so header D7 is written as 14:
- In setup(), make it a normal input. No internal pull-up is needed, because the switch drives the pin by itself:
- Read the level and turn it into ON or OFF. HIGH means COM touches pin 3, the 3.3V side:
- Filter the bounce. The metal bridge rattles for a few milliseconds while it slides. When a reading differs from the last one, wait 50 ms and read again. Only a change that is still there counts as a real move.
ESP32 S3 Uno Code - Slide Switch (3 Wires)
This sketch puts the four steps together. Right after a reset, it prints where the handle is. After that it stays quiet, and it only writes a new line when you really move the handle.
Detailed Instructions
- Board not set up yet? Add the ESP32 core to Arduino IDE with ESP32 S3 Uno - Getting Started.
- Wire the switch as the table shows: pin 1 to GND, the middle pin to D7, pin 3 to 3.3V.
- Connect the ESP32 S3 Uno to your computer with a USB Type-C cable.
- Choose the board ESP32S3 Dev Module and its COM port in Arduino IDE.
- Copy the sketch, paste it into Arduino IDE and press Upload.

- Open the Serial Monitor at 9600 baud. Press the RESET button on the board once, so you can see the start lines.
- Move the handle from side to side a few times:
- Check: one move gives one line. When you leave the handle alone, no new lines appear.
ESP32 S3 Uno Code - Slide Switch with INPUT_PULLUP (2 Wires)
Want fewer wires, with no 3.3V wire at all? Just remove the pin 3 wire. GPIO14 has a pull-up resistor inside the chip, and INPUT_PULLUP turns it on. It keeps D7 HIGH whenever COM is not joined to GND.

This image is created using Fritzing. Click to enlarge image
| Slide Switch Pin | ESP32 S3 Uno Pin |
|---|---|
| Pin 1 | GND |
| Pin 2 (COM) | D7 (GPIO14) |
| Pin 3 | not connected |
With this wiring, the meaning of the levels turns around:
- Handle toward pin 1: COM is joined to GND, so D7 reads LOW. The sketch calls this ON.
- Handle toward pin 3: COM touches the empty pin, the pull-up wins, and D7 reads HIGH. The sketch calls this OFF.
Detailed Instructions
- Pull out the wire on pin 3. The GND and D7 wires stay where they are.
- Upload this sketch the same way as the first one.
- Open the Serial Monitor at 9600 baud, press RESET, then slide the handle back and forth:
- Notice: the handle side that meant OFF in the first sketch now means ON. This is normal for the pull-up logic. If you want the old meaning back, swap the two words in printPosition().
Video Tutorial
Additional Knowledge
Slide switch, push button or ON/OFF switch?
The ESP32 S3 Uno folder has tutorials for all three. They are all simple switches, but they suit different jobs:
| Slide switch (this page) | Push button | ON/OFF switch | |
|---|---|---|---|
| Stays where you leave it | yes | no, it springs back | yes |
| Pins | 3 (pin 1, COM, pin 3) | 4 legs in two joined pairs | 2 |
| Can work with no resistor and no pull-up | yes, with 3 wires | no | no |
| Best for | choosing a mode or a setting | a short action, like "start" | a big, easy-to-reach ON/OFF control |
You can read more in ESP32 S3 Uno - Button and ESP32 S3 Uno - Switch. Need several settings in one small part? A DIP switch is a row of tiny slide switches, see ESP32 S3 Uno - DIP Switch.
Ideas for the slide switch
- Mute switch: stop all beeps while the handle is OFF, together with the ESP32 S3 Uno - Piezo Buzzer tutorial.
- Effect selector: blink an LED in one position and fade it in the other, with code from ESP32 S3 Uno - Fade LED.
- Test mode: print extra debug lines to the Serial Monitor only while the handle is ON.
- Unit selector: show a temperature in °C on one side and in °F on the other.
Function References
FAQ
Why must pin 3 go to 3.3V on the ESP32 S3 Uno?
When the handle points to pin 3, COM, and so GPIO14, gets the same voltage as pin 3. The ESP32 S3 Uno pins accept 3.3V at most. With 5V on pin 3, the pin could be damaged. 3.3V gives a clean HIGH reading.
Do I need a resistor for the slide switch?
No. In the 3-wire circuit, the switch connects D7 to 3.3V or to GND at all times, so the pin never floats. In the 2-wire circuit, the internal pull-up of GPIO14 takes the place of the 3.3V wire.
Should I use the 3-wire or the 2-wire version?
Both read the switch well. The 3-wire version reads the natural way: HIGH is ON. The 2-wire version saves a wire and the 3.3V pin, but LOW means ON. Choose the one that fits your project, and use the sketch that matches the wiring.
Why does the code use 14 and not 7?
In the ESP32 core for Arduino IDE, the pin number in code is the GPIO number of the chip. Header pin D7 of the ESP32 S3 Uno is GPIO14, so the sketch writes #define SLIDE_SWITCH_PIN 14.
My ON and OFF are the wrong way round. What is wrong?
Nothing is broken. The switch has no labels, so either outer pin can be "pin 1". Swap the GND and 3.3V wires on the two outer pins, or swap the words "ON" and "OFF" in the code.
Can the slide switch turn a mains lamp on and off?
Its contacts are rated AC 125V 2A, but this tutorial uses it only as a signal switch for the ESP32 S3 Uno. Never bring mains voltage near the board or the jumper wires. To control a big load, let the board read the switch and drive a relay module.
Can I add more slide switches?
Yes. Give each switch its own input pin and write the GPIO number of that pin in the code (see the pinout image). D4 or D5 work well. Do not use D0 and D1, because they carry the USB serial data. Also avoid D6 (GPIO3) and D9 (GPIO46): they are boot strapping pins, and a switch that holds them HIGH or LOW during reset can stop the board from starting. More inputs wait in the two extra rows of holes after you solder headers: GPIO35 to GPIO42, GPIO15 and GPIO16 are good choices. GPIO0 and GPIO45 are strapping pins too, so leave them free. Skip GPIO47 and GPIO48 as well: they are output only, and on some modules (with "V" in the name, like R8V or R16V) they run at 1.8V instead of 3.3V.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port in Arduino IDE | missing USB driver or a power-only cable | Install the CP210x or CH340 driver, try a cable that carries data, or hold BOOT and press RESET |
| Always OFF with the 3-wire sketch | pin 3 is not on 3.3V, or the code uses 7 | Connect pin 3 to 3.3V and use 14 for D7 |
| ON and OFF are swapped | the outer pins are the other way round | Swap the GND and 3.3V wires, or swap the words in the code |
| Random ON/OFF lines | 3-wire sketch with only 2 wires, or a loose COM wire | Use the INPUT_PULLUP sketch when pin 3 is free, and check the D7 wire |
| Two lines for one move | contact bounce | Raise BOUNCE_TIME from 50 to 80 |
| No start lines in the Serial Monitor | the sketch started before the Monitor was open | Press the RESET button on the board |
| Garbled text in the Serial Monitor | wrong baud rate | Pick 9600 baud in the Serial Monitor |