IOT Virtual Lab
Interfacing Push Button and Led with Arduino:
ARDUINO CODE
const int switchPin = 10; // Pin connected to slide switch const int ledPin = 9; // Pin connected to LED void setup() { pinMode(switchPin, INPUT); // Set switch pin as input pinMode(ledPin, OUTPUT); // Set LED pin as output } void loop() { int switchState = digitalRead(switchPin); // Read switch state if (switchState == HIGH) { digitalWrite(ledPin, HIGH); // Turn on LED } else { digitalWrite(ledPin, LOW); // Turn off LED } }
Start Simulation
Click the slideswitch!