SPDT Micro Limit Switch Turns LED ON/OFF

Description: When an SPDT Micro Limit Switch is pressed down it turns an LED ON and when it’s released the LED turns OFF.

Notes: The 10k Ohm Resistor needs to be connected to the SPDT Limit Switch as it acts as a pull-down resistor.

Supplies:

1 – Breadboard 400 Points
1 – Arduino Nano
1 – SPDT Micro Limit Switch
1 – LED
1 – 220 Ohm Resistor
1 – 10k Ohm Resistor

Arduino Code:

int switchpin = A4;
int redLED = 5;

void setup() {
  
  pinMode(switchpin, INPUT);
  pinMode(redLED, OUTPUT);

  Serial.begin(9600);

}

void loop() {

  int sensorValue = analogRead(A4);

  Serial.println(sensorValue);

  if (analogRead(A4) > 100) {
  digitalWrite(redLED, HIGH);

}

  else digitalWrite(redLED, LOW);
  delay(10);

}

Leave a Comment

16 − = 8