0Pricing
Arduino & IoT Academy · Lesson

Reading a Button State

Use digitalRead to know if a button is pressed.

Ask the Pin a Question

Now that a pin is listening, you can ask it what it sees. The function digitalRead checks a pin and tells you its current state.

It Returns HIGH or LOW

digitalRead gives back just two answers: HIGH or LOW. That is perfect for a button, which is only ever pressed or not.

int state = digitalRead(2);

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