Slide switch
Two positions, held where you leave it.
- 3 pins
- In 34 projects
- In 28 lessons
The Slide switch in brief
What it is, and where it sits on the bench.
A slide switch is the small three-legged SPDT switch in most kits: sliding the knob joins the middle leg, the common pole, to one outer leg or the other. Mokxi’s part does exactly that, with pin 2 tied through a 50 milliohm contact to pin 1 or pin 3 and the unselected throw left genuinely open, so anything hanging off it floats the way it would on a breadboard. No pin is an input or an output: the contact passes whatever is on either side in either direction, so it works as a logic-level input or a supply selector. To read it from an Arduino Uno or ESP32, wire pin 2 to a GPIO and the outer legs to ground and to the supply, using 3.3 volts on an ESP32, never 5. The common mistake is wiring only one throw and expecting the other position to read as a clean 0 or 1, when that pin is floating unless a pull resistor holds it. There is no contact bounce and no travel time between the throws.
- Family
- Inputs
- Pins
- 3
3 pins
Named as the editor names them, so a wire lands where you expect it.
How to use a slide switch with an Arduino
The middle leg goes to a digital pin and one outer leg to GND. Set the pin to INPUT_PULLUP in setup(), and digitalRead() gives LOW with the slider on the grounded side and HIGH with it on the other, where the pin is held up only by the pull-up. That is how the elevon mixer here picks between its two modes on pin 4, with the third leg left unwired.
Leave out INPUT_PULLUP and the unwired position reads Floating instead of HIGH, because nothing drives the pin at all. Wiring the third leg to 5 V instead gives a driven HIGH in both positions and needs no pull-up at all. Either way, read the switch in loop() rather than once in setup(), so flipping it while the sketch runs changes the mode.
The same wiring works on an ESP32 or a Pico; if you wire the third leg to a supply there, use 3.3 V, never 5 V.
const int MODE_PIN = 4;
void setup() {
pinMode(MODE_PIN, INPUT_PULLUP);
}
void loop() {
bool elevonMode = digitalRead(MODE_PIN) == HIGH;
}What is true about the Slide switch, here
In its help article’s own words: what the simulation gets right, and where it stops.
Modeled
No pin is treated as an "input": a slide switch passes whatever is on one side through to the other, in either direction, which is what makes it just as useful as a supply selector as it is as a logic-level input.
Not modeled
No contact bounce. A real slide switch chatters for a millisecond or so on the way across, but nothing in the firmware library needs it modeled, and a silent approximation beats a wrong one. The pushbutton is where bounce is modeled, because a debounce lesson actually needs it there. Nor is there any travel time: the pole leaves one throw and arrives at the other in the same instant, where a real slider is genuinely open for a moment in between. There is no contact resistance drift, no wear and no current rating.
From Slide switch (SPDT), in full.
See the Slide switch in a project
34 built-in projects use it. Each opens in the editor, already wired.
Where it turns up in a lesson
28 lessons place it in their own circuits.
The twelve week course
3 lessons
Learn articles
25 lessons
- Ohm's Law, in a Circuit You Can Run
- Shifting a Byte In, One Edge at a Time
- Blink an LED with a 555 Timer, No Microcontroller
- Diodes for Reverse Polarity Protection
- NPN Transistor as a Switch: a 2N2222 and an Arduino
- The Flyback Diode, and the Spike It Stops
- MOSFET vs BJT: Which Transistor to Switch With
- Digital Electronics on Chromebooks: Labs by Unit
- Half Adder and Full Adder: Truth Table to Breadboard
- Flip-Flops Explained: SR Latch, D and JK Flip-Flops
- Circuit Lab Division B: Middle School Starter Guide
- TSA Electrical Applications: Practice Circuits
- Arduino MOSFET Module: Why the IRF520 Is Half On
- Leverless Controller Build: Buttons, Pins and Code
- SOCD Cleaning Explained, With Code
- Design Your Sim Racing Button Box in the Browser
- 3D Printer Firmware: Homing, PID, G-code, Runout
- DIY Stream Deck and Camera Slider With Arduino
- Arduino Eurorack CV Quantizer With a PWM DAC
- A4988 Pinout: Pins, Microstep Table and Vref
- Arduino DRV8825: Wiring, Code and Microstepping
- Virtual Electronics Lab for College Classes
- Run an Electronics Lab for Online Classes
- NPN Transistor Switch Simulator
- 555 Timer Simulator: an LED Blinker
The boards it is shown on
Each of these 3 boards has a built-in project with the Slide switch in it.
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Slide switch
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.