Interfacing Slide Switch and Led with Arduino:
ARDUINO CODE
/* ----------------------------------------------------------- Objective: Read the state of a slide switch and control an LED based on the switch position. Components: - Slide Switch - LED + 100 Ω current-limiting resistor - Arduino Uno Working: The slide switch outputs either HIGH (5V) or LOW (0V). Arduino reads this digital state from pin 10. If HIGH, the LED connected to pin 9 turns ON; otherwise, it stays OFF. ----------------------------------------------------------- */ const int switchPin = 10; // Pin connected to slide switch const int ledPin = 9; // Pin connected to LED void setup() { pinMode(switchPin, INPUT); // Configure switch pin as input pinMode(ledPin, OUTPUT); // Configure LED pin as output } void loop() { int switchState = digitalRead(switchPin); // Read switch state (HIGH or LOW) if (switchState == HIGH) { digitalWrite(ledPin, HIGH); // Turn LED ON } else { digitalWrite(ledPin, LOW); // Turn LED OFF } }
Start Simulation
Click the slideswitch!