How to Use a Button

In this tutorial, we’re going to learn how to use a button with Arduino.

Definition

A component that when pressed responds with a full 5 volt output (by default, the “L” LED will be lit when pressed)

Schematic

Code

void setup()
{
    pinMode(7,INPUT);
    Serial.begin(9600);
}
void loop()
{
    if(digitalRead(7) == HIGH)
    {
        Serial.println("PRESSED");
    }
    else
    {
        Serial.println("NOT PRESSED")
    }
}

What this will print is a multitudes of “NOT PRESSED” lines. As soon as you press down on the button, it will print “PRESSED”.

Leave a comment

Your email address will not be published. Required fields are marked *