0PricingLogin
Arduino & IoT Academy · Lesson

if/else: LED Follows the Button

Light an LED only while the button is held.

Make a Decision

Reading a button is great, but the magic is reacting to it. An if statement lets your board choose what to do based on the reading.

if Runs Conditionally

The code inside if only runs when its test is true. So you can light an LED only when the button is actually pressed.

if (state == LOW) {
  // button is pressed
}

All lessons in this course

  1. INPUT vs INPUT_PULLUP
  2. Reading a Button State
  3. if/else: LED Follows the Button
  4. Wire a Button on a Breadboard
← Back to Arduino & IoT Academy