Two LEDs show SPDT Limit Switch status with Raspberry Pi Pico

Description: Two LEDs show the status of an SPDT Limit Switch connected to a Raspberry Pi Pico. When the Limit Switch is open, the green LED is ON and the red LED is OFF.  And when Limit Switch is closed the red LED is ON and the green LED is OFF.

Two LEDs show SPDT Limit Switch status with Raspberry Pi Pico

Supplies:

1 –  Breadboard 400 Points
1 – Raspberry Pi Pico
1 – SPDT Limit Switch
2 – LEDs
1 – 220 Ohm Resistor

Arduino Code:

#define Lswitch 0 

int led_red = 22; 
int led_green = 28;

void setup() {
  
  Serial.begin(9600); 
  pinMode(Lswitch, INPUT_PULLUP); 
  pinMode(led_green, OUTPUT);
  pinMode(led_red, OUTPUT); 
  
}

void loop() {
  
    while( (digitalRead(Lswitch) == LOW)  ) {
    Serial.println("door is closed"); 
    digitalWrite(led_red, HIGH);
    digitalWrite(led_green, LOW);
    
  }
  
    while( (digitalRead(Lswitch) == HIGH)  ) {
    Serial.println("door is open"); 
    digitalWrite(led_red, LOW);
    digitalWrite(led_green, HIGH); 

  }
}

Leave a Comment

1 + 6 =