03 / Templates · beginner
SLIDE SWITCH
Open in PlaygroundSPDT 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
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);
}- Arduino Uno01
- Slide Switch (wokwi-slide-switch)02
| Component Pin | Arduino Pin |
|---|---|
| Pin 1 (left position) | GND |
| Pin 2 (Common) | Pin 4 |
| Pin 3 (right position) | 5V |