CNAP

DIP Switch 8 Reference

Eight independent SPST slide switches in a single DIP package, each with an A and B terminal.

Pin names

NameDescription
1a–8aSwitch 1–8, terminal A
1b–8bSwitch 1–8, terminal B

Each numbered switch connects its a and b terminal when closed (ON), and disconnects them when open (OFF).

Attributes

This component has no configurable attributes.

Usage

Wire each B terminal to a GPIO configured with INPUT_PULLUP, and each A terminal to GND. A closed switch pulls its pin LOW; an open switch reads HIGH (pulled up internally).

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);
}

Examples

DescriptionAttrs
Default 8-way DIP switch{}

See also

  • Slide Switch — single SPDT switch instead of 8 independent SPST switches
  • Membrane Keypad — scanned matrix input for more than 8 inputs