A toggle switch is a class of electrical switches that are manually actuated by a mechanical lever, handle, or rocking mechanism. Toggle switches are widely used in various applications ranging from industrial equipment to consumer electronics. They provide a simple and effective way to open or close an electrical circuit, allowing for the control of power and signal flow in a system.
Pin Number | Description | Notes |
---|---|---|
1 | Common terminal (COM) | Connects to the circuit's power or signal source |
2 | Normally Open (NO) terminal | Connected to COM when the switch is in the ON position |
3 | Normally Closed (NC) terminal | Connected to COM when the switch is in the OFF position (only present in SPDT and DPDT switches) |
Note: The pin configuration may vary depending on the type of toggle switch (e.g., SPST, SPDT, DPST, DPDT).
Q: Can I use a toggle switch with an Arduino? A: Yes, toggle switches can be used with an Arduino to control digital inputs.
Q: How do I know if my toggle switch is on or off? A: Typically, the ON position is when the lever is pushed towards the terminals, but this can vary. Check the switch's datasheet for the specific ON/OFF orientation.
Q: What is the difference between SPST and DPDT switches? A: An SPST switch has one circuit that can be opened or closed, while a DPDT switch can control two separate circuits and has two positions to route each circuit differently.
Below is an example of how to use a toggle switch with an Arduino UNO to control an LED.
// Define the pin numbers
const int switchPin = 2; // Toggle switch connected to digital pin 2
const int ledPin = 13; // Onboard LED connected to digital pin 13
void setup() {
pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as an input with internal pull-up resistor
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
}
void loop() {
// Read the state of the toggle switch
int switchState = digitalRead(switchPin);
// If the switch is in the ON position (assuming LOW is ON)
if (switchState == LOW) {
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
}
Note: The INPUT_PULLUP
mode is used to enable the internal pull-up resistor, which ensures a default HIGH state when the switch is open (OFF position). When the switch is closed (ON position), the pin is pulled LOW.
Remember to adjust the pin numbers and logic according to your specific circuit and switch type.