CNAP

Slide Switch Reference

SPDT (single-pole, double-throw) slide switch. Click the switch on the canvas to toggle it.

Pin names

NameDescription
1Pin 1 (left position)
2Common — connects to pin 1 or pin 3 depending on switch position
3Pin 3 (right position)

Attributes

This component has no configurable attributes.

Usage

Wire pin 1 to GND, pin 3 to 5V, and the Common pin to a GPIO configured as INPUT. The GPIO reads LOW or HIGH depending on which side the switch is set to.

const int SW = 4;

void setup() {
  pinMode(SW, INPUT);
  Serial.begin(9600);
}

void loop() {
  int state = digitalRead(SW);
  Serial.println(state == HIGH ? "Switch: ON" : "Switch: OFF");
  delay(300);
}

Examples

DescriptionAttrs
Default switch{}

See also

  • Pushbutton — momentary press instead of a maintained position
  • DIP Switch 8 — eight slide switches in one package