A DIP (Dual Inline Package) switch is a manual electric switch that is packaged in a standard dual in-line package. This particular DIP switch has 8 individual switch positions, allowing for a combination of settings to be selected. The 8 Position DIP Switch is commonly used to configure hardware settings, select options on a printed circuit board, or for prototyping work. It is a convenient way to make binary choices without the need for jumpers or soldering.
Pin Number | Description |
---|---|
1 | Switch 1 |
2 | Switch 2 |
3 | Switch 3 |
4 | Switch 4 |
5 | Switch 5 |
6 | Switch 6 |
7 | Switch 7 |
8 | Switch 8 |
9 | Common (Ground) |
Each switch pin (1-8) corresponds to one of the 8 positions on the DIP switch. The common pin (9) is typically connected to ground.
// Define the pin numbers connected to the DIP switch positions
const int dipPins[8] = {2, 3, 4, 5, 6, 7, 8, 9};
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set all the DIP switch pins as inputs
for (int i = 0; i < 8; i++) {
pinMode(dipPins[i], INPUT_PULLUP);
// Using the internal pull-up resistors
}
}
void loop() {
// Read the state of each switch position
for (int i = 0; i < 8; i++) {
int switchState = digitalRead(dipPins[i]);
// Print the state of each switch
Serial.print("Switch ");
Serial.print(i + 1);
Serial.print(": ");
Serial.println(switchState == HIGH ? "OFF" : "ON");
// When switch is ON, it connects the pin to GND (LOW)
}
// Add a delay before the next reading
delay(1000);
}
This example code initializes an Arduino UNO to read the state of each switch in the 8 Position DIP Switch and prints the state to the Serial Monitor. Each switch is connected to a digital pin on the Arduino, and the common pin is connected to ground. The internal pull-up resistors are used to ensure a default HIGH state when the switch is open (off).