Skip to content

Using buttons with Arduino (no pull-up resistor)

   

This is a sample code for using buttons in Arduino.
It's not well known, but when you use a pull-up, you can easily use the buttons with no pull-up resistance.
If you connect the Ground to the second port of the Degital (by pressing the button), you will be aware of this.

const int buttonPin = 2;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop(){
//ボタンが押されているとbuttonPinがGNDに落ちるのでLOWになる
if (digitalRead(buttonPin) == LOW) {
Serial.println("PushPush");
} else {
Serial.println("Not Push");
}
delay(1000);
}
view raw ButtonTest.ino hosted with ❤ by GitHub