Arduino Nano 33 IoT - Slide Switch
This tutorial instructs you how to use Arduino Nano 33 IoT to read the position of a slide switch. The part is the DIYables Mini Slide Switch SS12D10. Its small handle stays where you push it, so it is a good way to give a connected gadget a setting: for example, a privacy switch that stops a sensor node from sending data to the cloud, or a "setup / run" switch that the sketch checks before it joins WiFi. In detail, we will learn:
- What is inside the SS12D10, and what each of its three pins must be connected to
- Why pin 3 must go to the 3.3V pin of the Arduino Nano 33 IoT, never to VUSB (5V)
- How to program the Arduino Nano 33 IoT to print one ON or OFF line for every move of the handle, with a 50 ms debounce check
- How to remove the pin 3 wire and read the same switch with INPUT_PULLUP, where ON and OFF swap levels

We suggest:
- Checking the Arduino Nano 33 IoT - Switch tutorial if your project needs a bigger ON/OFF switch that mounts in a hole in the wall of a box.
- Trying the Arduino Nano 33 IoT - DIP Switch tutorial when you want to set several ON/OFF options at once, or the Arduino Nano 33 IoT - Button Module tutorial for a key that springs back after each press.
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 and Its Pinout

The SS12D10 is a tiny two-position switch. A 5 mm handle sticks out of the top, and three pins come out of the bottom in a straight row. Slide the handle to one end and it stays there: the switch latches. A push button is different, because it jumps back as soon as you let go. The switch type is SPDT (single pole, double throw), also written 1P2T. That means one common pin, which is joined to one of the two other pins.
| Mini Slide Switch SS12D10 | |
|---|---|
| Switch type | SPDT (1P2T), 2 positions |
| Pins | 3 in one row |
| Pin pitch | 4.7 mm |
| Pin length | 6.9 mm |
| Handle | 5 mm |
| Body | about 12.8 x 6.7 x 18.2 mm |
| Mounting | vertical through-hole |
| Contacts | silver-plated brass |
| Contact rating | AC 125V 2A |
| Life | over 100,000 switching cycles |
| Working temperature | -25°C to 80°C |
The AC 125V 2A rating tells you how much the contacts can carry. Here they carry almost nothing: only the tiny current that flows into one input pin of the Arduino Nano 33 IoT.
How does it work? Under the handle, a small metal bridge always presses on the middle pin (pin 2, COM). When you move the handle, the bridge moves with it and also touches the outer pin on that side:
| Handle position | Pins joined inside | Pin left open | D2 level (3-wire wiring) |
|---|---|---|---|
| Toward pin 1 | pin 1 and COM | pin 3 | LOW (OFF) |
| Toward pin 3 | COM and pin 3 | pin 1 | HIGH (ON) |
No labels are printed on the switch, so count the pins from one end of the row:
- Pin 1 (outer pin): must be connected to a GND pin (0V) of the board
- Pin 2, COM (middle pin): must be connected to D2, the input pin that the code below reads
- Pin 3 (other outer pin): must be connected to 3.3V when you use three wires. With the 2-wire INPUT_PULLUP wiring, leave it empty
※ NOTE THAT:
Which outer pin is "pin 1"? It does not matter much. Both outer pins work the same way. If GND ends up on the other outer pin, the sketch still runs; it just reports ON at the opposite end of the handle. What really matters is that D2 goes to the middle pin.
Wiring Diagram
Three jumper wires are enough: the middle pin (COM) to D2, pin 1 to GND, and pin 3 to the 3.3V pin. No resistor is needed, because COM always connects D2 to either GND or 3.3V, so the pin never floats.

This image is created using Fritzing. Click to enlarge image
| Slide Switch Pin | Arduino Nano 33 IoT Pin |
|---|---|
| Pin 1 | GND |
| Pin 2 (COM) | D2 |
| Pin 3 | 3.3V |
If you plan to keep this circuit, think about screw terminals. To do that, mount the Arduino Nano 33 IoT on a Screw Terminal Expansion Board for Arduino Nano. The wiring stays the same. Only the wires now go to the screw terminals, as shown below.

This image is created using Fritzing. Click to enlarge image
※ NOTE THAT:
- Use the 3.3V pin for pin 3. Do not use VUSB (the 5V pin) or VIN. When the handle points to pin 3, COM passes that voltage straight into D2. The SAMD21 chip on the Arduino Nano 33 IoT works at 3.3V, and its pins are not 5V tolerant, so 5V on D2 can damage the board.
- Keep D2 as an INPUT. Never set it to OUTPUT: the switch ties it straight to 3.3V or GND, so an output pin could be shorted.
How To Program For Slide Switch
No library is needed. The Arduino Nano 33 IoT reads the slide switch with the built-in digitalRead() function, just like a button.
- The first step is to name the Arduino Nano 33 IoT pin that the COM pin is connected to:
- Inside setup(), call pinMode() with INPUT. A pull-up is not needed, because the switch itself drives D2 to 3.3V or to GND:
- Read the level with digitalRead(). HIGH means the handle is toward pin 3 (ON), LOW means it is toward pin 1 (OFF):
- The contacts bounce for a few milliseconds while the handle travels. So when the level is not the same as the last confirmed one, wait 50 milliseconds, read again, and accept the change only if it is still there.
Arduino Nano 33 IoT Code for Slide Switch
The sketch shows where the handle is, then adds one line for each real move. It starts with switch_state set to -1, a value that digitalRead() never returns. So the very first reading counts as a change, and the start position is printed by the same code. Because the Arduino Nano 33 IoT talks to the PC through its own native USB port, setup() also waits up to 3 seconds for the Serial Monitor. Without a PC, the sketch simply goes on.
Detailed Instructions
New to the Arduino Nano 33 IoT? Go through the Getting Started with Arduino Nano 33 IoT tutorial first, then come back here.
- Wire the components as shown in the diagram. Check that pin 3 is on 3.3V, not on VUSB.
- Connect the Arduino Nano 33 IoT board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Select the Arduino Nano 33 IoT board and its COM port.
- Paste the code above into a new sketch.
- Push the handle toward pin 3.
- Click the Upload button to compile the sketch and send it to the board.
- Open the Serial Monitor and choose 9600 baud.
- Slide the handle five times: toward pin 1, pin 3, pin 1, pin 3 and pin 1 again. Wait a moment at each end.
You get six lines: one for the start position and one for each of the five moves. If the first line is missing, the Serial Monitor connected a bit too late. That is not a problem; the next move prints a new line. If the level never changes, check that the D2 wire sits on the middle pin of the switch, not on an outer one.
Arduino Nano 33 IoT Code for Slide Switch - Two Wires and INPUT_PULLUP
Is the 3.3V pin already busy powering a sensor? Or do you want one wire less inside a small case? The SAMD21 chip has a pull-up resistor built into each input pin, and INPUT_PULLUP turns it on. Then pin 3 needs no wire. Just remove the pin 3 wire: COM stays on D2, and pin 1 stays on GND.

This image is created using Fritzing. Click to enlarge image
| Slide Switch Pin | Arduino Nano 33 IoT Pin |
|---|---|
| Pin 1 | GND |
| Pin 2 (COM) | D2 |
| Pin 3 | not connected |
Be careful: with this wiring, the meaning of HIGH and LOW is reversed.
- Handle toward pin 1: COM connects D2 to GND. D2 reads LOW, and the sketch prints ON.
- Handle toward pin 3: COM touches only the free pin 3. The internal pull-up lifts D2 to HIGH, and the sketch prints OFF.
Detailed Instructions
- Take the wire off pin 3 of the switch. Leave COM on D2 and pin 1 on GND.
- Upload the code above in place of the first sketch. The handle is still toward pin 1 from the last test.
- Slide the handle toward pin 3, then back toward pin 1.
The handle toward pin 1 now prints ON. In the 3-wire sketch, the same position printed OFF.
※ NOTE THAT:
Please note that the Arduino Nano 33 IoT pins A4 and A5 have built-in pull-up resistors for I2C communication. Although these pins can be used as digital input pins, it is recommended to avoid using them for digital input. If you must use them, do NOT use internal or external pull-down resistors for these pins
Additional Knowledge
3 Wires or 2 Wires?
| 3-Wire Wiring | 2-Wire Wiring | |
|---|---|---|
| Wires on the switch | pin 1, COM and pin 3 | pin 1 and COM |
| pinMode() | INPUT | INPUT_PULLUP |
| What makes D2 HIGH | pin 3, joined to 3.3V | the pull-up resistor inside the SAMD21 |
| Handle toward pin 3 | HIGH = ON | HIGH = OFF |
| Handle toward pin 1 | LOW = OFF | LOW = ON |
| Needs the 3.3V pin | yes | no |
It is evident that both ways read the switch equally well. The 3-wire wiring keeps the natural logic (HIGH = ON). The 2-wire wiring saves one wire and keeps the 3.3V pin free; you only have to swap ON and OFF in the code.
Project Ideas
A slide switch suits the jobs of a connected board well:
- A privacy switch: while it is OFF, the Arduino Nano 33 IoT keeps measuring but stops sending data to the cloud.
- A WiFi selector that the sketch reads once in setup(): one position joins the home network, the other joins the tutorial network.
- A display switch: show the readings on a local LCD, or keep the screen dark to save power.