CNAP
03 / Templates · beginner

DIP SWITCH 8

Open in Playground

Read all 8 switches of a DIP-8 package as a byte. Each closed switch pulls its Arduino pin LOW via INPUT_PULLUP. Flip switches on the canvas and watch the binary value update in the Serial Monitor.

beginnerswitchdigital inputserialDIPbinary
Circuit
Code
sketch.inoArduino C++
19 lines
// DIP Switch 8 — read all 8 switches as a byte
const int PINS[8] = {2, 3, 4, 5, 6, 7, 8, 9};

void setup() {
  for (int p : PINS) pinMode(p, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  byte val = 0;
  for (int i = 0; i < 8; i++) {
    if (digitalRead(PINS[i]) == LOW) {  // LOW = switch closed
      val |= (1 << i);
    }
  }
  Serial.print("DIP = 0b");
  Serial.println(val, BIN);
  delay(200);
}
Components
  • Arduino Uno
    01
  • DIP Switch 8 (wokwi-dip-switch-8)
    02
Wiring
Component PinArduino Pin
1BPin 2
2BPin 3
3BPin 4
4BPin 5
5BPin 6
6BPin 7
7BPin 8
8BPin 9
1A–8A (all tied together)GND (bottom row)