(Reference) Switches

Switches

image-20200710132427002

Wiring

image-20200711010114011

Operations

  • Similar to pushbuttons, switches open or close a circuit
  • We are going to look at maintained switches that continue to close or open a circuit indefinitely
  • We will typically just call these components “switches”

Connections

image-20200711010114011

image-20200711010308308

Code

const int PIN_SWITCH = D2;

void setup() {
   pinMode(PIN_SWITCH, INPUT);  //configure
   Serial.begin(9600);
}

void loop() {
	//read button state
   int switchVal = digitalRead(PIN_SWITCH); 
   
    if (switchVal == HIGH) {
     Serial.write("Switch HIGH");
   }
   else {
     Serial.write("Switch LOW");
   }
 }

Credit

  • Sparkfun has some great illustrations on this for a deep dive into switches
  • Images created with Fritzing

Updated: