IOT Virtual Lab
Home
Simulation Window
Go Back
Interfacing of Arduino with Push button :
ARDUINO CODE
/* Button Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2. The circuit: * LED attached from pin 13 to ground * pushbutton attached to pin 2 from +5V * 10K resistor attached to pin 2 from ground * Note: on most Arduinos there is already an LED on the board attached to pin 13. */ int buttonState = 0; void setup() { pinMode(2, INPUT); pinMode(LED_BUILTIN, OUTPUT); } void loop() { // read the state of the pushbutton value buttonState = digitalRead(2); // check if pushbutton is pressed. if it is, the // buttonState is HIGH if (buttonState == HIGH) { // turn LED on digitalWrite(LED_BUILTIN, HIGH); } else { // turn LED off digitalWrite(LED_BUILTIN, LOW); } delay(10); // Delay a little bit to improve simulation performance }
Start Simulation