03 / Templates · beginner
DIP SWITCH 8
Open in PlaygroundRead 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
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);
}- Arduino Uno01
- DIP Switch 8 (wokwi-dip-switch-8)02
| Component Pin | Arduino Pin |
|---|---|
| 1B | Pin 2 |
| 2B | Pin 3 |
| 3B | Pin 4 |
| 4B | Pin 5 |
| 5B | Pin 6 |
| 6B | Pin 7 |
| 7B | Pin 8 |
| 8B | Pin 9 |
| 1A–8A (all tied together) | GND (bottom row) |