4 Way Slide Switch 2.54mm Pitch (Pack of 2)
4 Way Slide Switch 2.54mm Pitch (Pack of 2)
The 4 Way Slide Switch 2.54mm Pitch is a type of electronic switch component designed for use in various IoT projects and applications. This component consists of two identical switches, each featuring a 4-way slide mechanism that allows for simple and intuitive control over digital circuits. With a compact design and 2.54mm pitch, this switch is ideal for use in breadboards, perfboards, and PCBs.
The primary function of the 4 Way Slide Switch 2.54mm Pitch is to provide a means of controlling the flow of electrical signals in a circuit. The switch features four positions, allowing the user to select one of four possible states or configurations. This makes it ideal for applications that require multiple settings or options, such as mode selection, signal routing, or configuration choices.
50V DC
0.5A per pole
50m
100M
-20C to 70C
-30C to 80C
40C, 90% RH
The 4 Way Slide Switch 2.54mm Pitch is suitable for a wide range of IoT applications, including |
Mode selection in electronic devices
Signal routing and configuration in digital circuits
Configuration choices in IoT devices
Prototype development and testing
Educational projects and DIY electronics
The package includes two 4-way slide switches, each with a 2.54mm pitch. The switches are identical and can be used in a variety of applications.
4 Way Slide Switch 2.54mm Pitch (Pack of 2) Component Documentation
Overview
The 4 Way Slide Switch 2.54mm Pitch is a compact, SP4T (Single Pole Four Throw) slide switch designed for electronic projects that require multiple circuit connections. This component is ideal for IoT applications, robotics, and other projects that require reliable switching mechanisms.
Pinout and Technical Parameters
Pinout:
+ 4 ways (COM, NC1, NC2, NO1, and NO2)
+ 2.54mm pitch
Operating Voltage: 30V DC
Operating Current: 0.5A per contact
Insulation Resistance: 100M min. at 500V DC
ContactResistance: 20m max.
Operating Temperature: -40C to 85C
Storage Temperature: -40C to 125C
Code Examples
The following code examples demonstrate how to use the 4 Way Slide Switch in various contexts:
Example 1: Arduino Uno - Simple Switching
In this example, we'll use the 4 Way Slide Switch to control four LEDs connected to digital pins 2-5 on an Arduino Uno board.
```c
const int ledPins[] = {2, 3, 4, 5}; // LED pins
const int switchPin = A0; // Analog input pin for switch
void setup() {
for (int i = 0; i < 4; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(switchPin, INPUT);
}
void loop() {
int switchState = analogRead(switchPin);
switch (switchState) {
case 0: // Switch position 1
digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[1], LOW);
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[3], LOW);
break;
case 1023: // Switch position 2
digitalWrite(ledPins[0], LOW);
digitalWrite(ledPins[1], HIGH);
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[3], LOW);
break;
case 512: // Switch position 3
digitalWrite(ledPins[0], LOW);
digitalWrite(ledPins[1], LOW);
digitalWrite(ledPins[2], HIGH);
digitalWrite(ledPins[3], LOW);
break;
case 255: // Switch position 4
digitalWrite(ledPins[0], LOW);
digitalWrite(ledPins[1], LOW);
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[3], HIGH);
break;
}
delay(50);
}
```
Example 2: Raspberry Pi - Python Script
In this example, we'll use the 4 Way Slide Switch to control four relays connected to a Raspberry Pi's GPIO pins.
```python
import RPi.GPIO as GPIO
import time
# Set up GPIO mode
GPIO.setmode(GPIO.BCM)
# Define relay pins
relay_pins = [17, 23, 24, 25]
# Define switch pin
switch_pin = 18
# Set up relay pins as outputs
for pin in relay_pins:
GPIO.setup(pin, GPIO.OUT)
# Set up switch pin as input
GPIO.setup(switch_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
try:
while True:
switch_state = GPIO.input(switch_pin)
if switch_state == GPIO.HIGH:
# Switch position 1
GPIO.output(relay_pins[0], GPIO.HIGH)
GPIO.output(relay_pins[1], GPIO.LOW)
GPIO.output(relay_pins[2], GPIO.LOW)
GPIO.output(relay_pins[3], GPIO.LOW)
else:
# Switch position 2, 3, or 4
if switch_state == 0:
# Switch position 2
GPIO.output(relay_pins[0], GPIO.LOW)
GPIO.output(relay_pins[1], GPIO.HIGH)
GPIO.output(relay_pins[2], GPIO.LOW)
GPIO.output(relay_pins[3], GPIO.LOW)
elif switch_state == 1:
# Switch position 3
GPIO.output(relay_pins[0], GPIO.LOW)
GPIO.output(relay_pins[1], GPIO.LOW)
GPIO.output(relay_pins[2], GPIO.HIGH)
GPIO.output(relay_pins[3], GPIO.LOW)
else:
# Switch position 4
GPIO.output(relay_pins[0], GPIO.LOW)
GPIO.output(relay_pins[1], GPIO.LOW)
GPIO.output(relay_pins[2], GPIO.LOW)
GPIO.output(relay_pins[3], GPIO.HIGH)
time.sleep(0.1)
except KeyboardInterrupt:
# Clean up GPIO on exit
GPIO.cleanup()
```
Note: These code examples are for illustration purposes only and may require modifications to work with your specific project requirements.