Arseniy Nechaev
Published © GPL3+

Reading the State of a Button

A tutorial on how to read button states.

BeginnerProtip2,046
Reading the State of a Button

Things used in this project

Story

Read more

Schematics

download_(2)_DuGj10CkoR.png

Code

Untitled file

C/C++
int buttonState = 0;
void setup() {
  // put your setup code here, to run once:
  pinMode(8, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  buttonState = digitalRead(8);

  if (buttonState == HIGH){
    Serial.println("ON");
    
  } else{
    Serial.println("OFF");
  }
}

Credits

Arseniy Nechaev
6 projects • 12 followers
I am 12 years old, and a newbie to engineering. I started doing this because I love to look at circuits, PCBs, and inside electronics.
Contact

Comments

Please log in or sign up to comment.