Programming Examples
Arduino program to connect a led through push button
Arduino program to connect a led through push button and use the if else StatementÂ
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
}
Output