IoTSimulator

Slide Switch: How It Works, Wiring, and Example Code

A simple SPDT slide switch used for Arduino on-off control, mode selection, and digital input testing.
M
Muhammad Ichsan
Slide Switch

This article is a guide about the Slide Switch. It shows how a maintained switch gives the Arduino a stable choice instead of a momentary press.

Slide switches are useful when a project needs a clear physical on/off or left/right selection input. That makes them a good fit for power choices, mode selectors, and simple manual overrides.

Description

Slide switch product view
Slide switch product view

The slide switch is a maintained switch, which means it stays in the chosen position until you move it again. That makes it different from a pushbutton, which only stays active while it is pressed.

Because it is a maintained switch, it is often used for power selection, mode switching, and simple control logic. It gives the Arduino a clear digital state instead of a changing analog value.

In the simulator, the slide switch is a three-pin SPDT switch, so the middle pin acts as the common contact and connects to either side depending on the slider position.

Features

Here are the main things to know about the Slide Switch:

FeatureWhat it means
Maintained positionStays where you place it until you slide it again.
SPDT layoutUses one common pin and two selectable terminals.
Digital inputBest for on/off or left/right style logic.
Simple wiringEasy to connect to a microcontroller pin with a pull-up.
Beginner friendlyGood for learning how switches map to code states.

The important part is that the switch gives you a stable state, so the code does not need to guess whether the user is still interacting with it. That is what makes it good for power switches and mode selectors.

How Does It Work?

How a slide switch connects the common pin

An SPDT slide switch has one common terminal in the middle and two outer terminals on the sides. When you slide the handle, the common pin connects to one outer pin or the other.

That means the Arduino can read the switch as a clear logic state. If you wire the common pin to an input and use a pull-up resistor, the pin reads one way in one position and the opposite way in the other position.

This makes the slide switch very useful for mode selection. A single physical movement can tell the sketch to choose between two behaviors, two screens, or two output states.

SPDT Behavior

SPDT stands for Single Pole Double Throw. In practice, that means one shared connection can be thrown to either the left side or the right side, depending on where the slider is placed.

State Logic

Because the switch holds its position, the Arduino can read it as a stable digital input. That is why it works well for on/off settings and mode selectors.

Arduino With Slide Switch

This circuit preview shows the slide switch connected to Arduino Uno. It is a clean example of a maintained digital input because the switch stays in place and gives the Arduino a stable state.

SCL
SDA
AREF
GND.1
D13
D12
D11
D10
D9
D8
D7
D6
D5
D4
D3
D2
D1
D0
IOREF
RESET
3V3
5V
GND.2
GND.3
VIN
A0
A1
A2
A3
A4
A5
1
2
3

Pin Connection

The pin map below matches the circuit preview. The middle pin acts as the common contact, and one outer pin goes to ground so the Arduino can read a stable on/off state.

Pin Connection Map
Switch Pin
2
Arduino Pin
D2
Explanation

Common contact that the Arduino reads.

Switch Pin
1
Arduino Pin
GND
Explanation

One selectable side of the switch.

Switch Pin
3
Arduino Pin
Not used
Explanation

The other selectable side can be used for a second state if needed.

With this wiring, the switch does not need any special library. The Arduino only needs a digital read, which keeps the code simple.

Code

This example reads the switch and prints which side is selected. It is a simple way to confirm that the wiring and pull-up logic are working.

C++ Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Once that works, you can use the switch to select between two modes, start and stop a feature, or change which output should run. That is the main strength of a slide switch: it gives the project a clear physical choice.

How The Code Works, Part By Part

Let's break the sketch into smaller pieces so the flow is easier to understand and easier to modify later.

Setup

The setup block starts Serial Monitor and enables the internal pull-up resistor. That makes the input stable without needing an external resistor in many simple builds.

C++ Source
1
2
3
4
5
6

Read State

The sketch reads the switch pin as a digital value. That gives you a clean HIGH or LOW state to work with.

C++ Source
1

Check Position

The code decides which message to print based on the current switch state. This is the point where the physical switch becomes a software choice.

C++ Source
1
2
3
4
5

Repeat

The short delay keeps the output readable while the sketch continues checking the switch position.

C++ Source
1
2

Wrapping Up

The slide switch is a simple but useful input part when you want a stable physical selector. It is one of the easiest ways to give an Arduino a lasting choice instead of a momentary press.

Once you understand the common pin, the two outer terminals, and the pull-up logic, you can use it confidently in mode selection and digital control projects. The result is usually very easy to debug because the switch position stays visible to the user.

New

Wait! We're building more...

Our laboratory is currently preparing a lot of exciting new projects using Slide Switch. Stay tuned for the upcoming massive update!

Projects Using Slide Switch

Explore practical implementations

No official projects found for this component yet.

Muhammad Ichsanul Fadhil
About Writer

Muhammad Ichsanul Fadhil

"I'm a developer and hardware enthusiast with a passion for IoT. I love experimenting with new components and writing down everything I learn to help others build their own projects."

Share this article

Share it with your favorite channel.