Switches

Wiring

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


Code
const int PIN_SWITCH = S2;
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