Reading the State of a Button

Reading the State of a Button © GPL3+

A tutorial on how to read button states.

  • 253 views
  • 0 comments
  • 2 respects

Components and supplies

Necessary tools and machines

Hands

Apps and online services

About this project

I decided to make this tutorial for newbies. I myself get annoyed with pushbuttons because you have to hold them down for current to flow through.

Code

Untitled fileC/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");
  }
}

Schematics

download_(2)_DuGj10CkoR.png
Download (2) dugj10ckor

Comments

Similar projects you might like

You've Been Using a Button Wrong this Whole Time

Project tutorial by SMM2

  • 9,677 views
  • 1 comment
  • 6 respects

Dimming Lights with PWM using Push Button

Project tutorial by Phuong Vo

  • 6,306 views
  • 4 comments
  • 14 respects

Arduino - Use Reset Button Like a Push Button

by RoHa

  • 5,666 views
  • 0 comments
  • 13 respects

What to Wear? Twitter Button

Project showcase by Arduino “having11” Guy

  • 3,079 views
  • 0 comments
  • 6 respects

Storing the Charge State with Arduino

by PCBWay and Silícios Lab

  • 942 views
  • 0 comments
  • 8 respects

RGB LED Button Controller

Project showcase by Re

  • 13,566 views
  • 2 comments
  • 17 respects
Add projectSign up / Login