The SPDT switch typically has three terminals:
Pin Name | Description |
---|---|
Common (C) | The input terminal that connects to one of the two output terminals. |
Normally Open (NO) | The terminal that connects to the common terminal when the switch is activated. |
Normally Closed (NC) | The terminal that connects to the common terminal when the switch is not activated. |
An SPDT switch can be used to toggle between two LEDs using an Arduino UNO. Below is an example circuit and code:
// Define the pin connected to the SPDT switch
const int switchPin = 2;
// Define the pins connected to the LEDs
const int led1 = 3; // LED connected to Normally Open (NO)
const int led2 = 4; // LED connected to Normally Closed (NC)
void setup() {
pinMode(switchPin, INPUT_PULLUP); // Set switch pin as input with pull-up resistor
pinMode(led1, OUTPUT); // Set LED1 pin as output
pinMode(led2, OUTPUT); // Set LED2 pin as output
}
void loop() {
int switchState = digitalRead(switchPin); // Read the state of the switch
if (switchState == LOW) {
// If the switch is toggled to NO, turn on LED1 and turn off LED2
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
} else {
// If the switch is toggled to NC, turn on LED2 and turn off LED1
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
}
}
Q: Can I use an SPDT switch to control AC devices?
A: Yes, as long as the switch is rated for the AC voltage and current of your application.
Q: What is the difference between SPDT and DPDT switches?
A: An SPDT switch has one input and two outputs, while a DPDT (Double Pole Double Throw) switch has two inputs and four outputs, allowing for more complex switching configurations.
Q: How do I debounce an SPDT switch?
A: You can use a capacitor and resistor in a hardware debouncing circuit or implement a software debounce routine in your microcontroller code.