whatsapp

whatsApp

Have any Questions? Enquiry here!
☎ +91-9972364704 LOGIN BLOG
× Home Careers Contact
Back
SINGLE POLE DOUBLE THROW SWITCH INTERFACING WITH ARDUINO mifratech
SINGLE POLE DOUBLE THROW SWITCH INTERFACING WITH ARDUINO mifratech

SINGLE POLE DOUBLE THROW SWITCH INTERFACING WITH ARDUINO

Reading values from SPDT switches, or any switches, as a matter of fact, is one of the most essential skills to grasp in the realm of micro controllers. It is one of the simplest digital inputs to read, albeit slightly more complex than a button switch. The Single Pole - Double Throw (SPDT) switch has a common pin in the middle and then two other pins that, depending on the location of the switch, are either connected to the common (center) pin or not. This can be applied to virtually any project requiring two inputs of opposite nature.

Step 1: Tools and Supplies

·         Arduino 101 or Arduino Uno

·         SPDT switch

·         Breadboard

·         Jumper Wires

·         Blue LED

·         Yellow LED

·         2 pieces of 100Ω resistor

Step 2: How an SPDT Switch Works?

 

Switches are composed of two conductors that may or may not in contact with each other depending if it is a normally-open or normally-closed switch. Normally open switches make an open circuit in it's "normal" or default configuration. While, a normally closed switch is the opposite wherein a closed circuit is the default configuration of the switch. When a switch position is changed the two conductors are connected or disconnected for normally-open and normally-closed switches, respectively.

 

Step 3: Circuitry

 

The power will be supplied by the Arduino to power both the LEDs and the switch, therefore we will need to use the power rail to distribute the 3.3V power in parallel to all three electrical components.

·         Connect the 3.3V power from the Arduino to the red power rail of the breadboard using a red jumper wire.

·         Connect the GND pin from the Arduino to the black rail on the breadboard with a black jumper wire.

Connecting the switch to power and the Arduino

·         Connect the middle pin of the SPDT switch to pin 8 on the Arduino

·         Connect one of the outer pins to the red power rail on the breadboard

·         While the remaining outer pin will be connected to the black power rail on the breadboard

Connecting the LEDs to the Arduino

·         Connect the negative pin of both the LEDs (flat side of the LEDs) to a common ground on the black rail of the breadboard

·         Connect the positive pin of each of the LEDs to a 100Ω resistor separately.

·         Then, connect each of these resistors in series to pin 5 and 6 respectively.

Step 4: Code

Code Explanation

void setup() {

// put your setup code here, to run once:

// set the switch input, pin 8, as an INPUT pinMode(8, INPUT);

// set both the LED pins, pin 5 and 6 as OUTPUTs pinMode (5, OUTPUT); pinMode (6, OUTPUT); }

void loop() { // put your main code here, to run repeatedly: // read the value of the SPDT switch intswitchValue = digitalRead(8);

if (switchValue == 1){ // if the switch is in Position 1, then turn ON the pin 5 LED digitalWrite (5, HIGH); // make sure that the other LED in pin 6 is OFF digitalWrite (6, LOW); } else{ // if the switch is in Position 0, then turn ON the pin 6 LED digitalWrite (6, HIGH); //make sure that the other LED in pun 5 is OFF digitalWrite (5, LOW); } }

 

Popular Coures