CNAP
03 / Templates · beginner

SLIDE SWITCH

Open in Playground

SPDT slide switch wired between GND and 5V. The common pin reads LOW or HIGH depending on switch position. Click the switch on the canvas to toggle it — the Serial Monitor shows the state.

beginnerswitchdigital inputserialSPDT
Circuit
Code
sketch.inoArduino C++
13 lines
// Slide Switch — read switch position
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);
}
Components
  • Arduino Uno
    01
  • Slide Switch (wokwi-slide-switch)
    02
Wiring
Component PinArduino Pin
Pin 1 (left position)GND
Pin 2 (Common)Pin 4
Pin 3 (right position)5V