Day 5 Arduino Advent Calendar

 class=
Let's Get Started with the Day 5 Guide!

Arduino Advent Calendar Day 05 - Push Buttons

 

Congratulations for making it through to Day 5 of the Arduino AdventCalendar!

Today we're going to show you how to use buttons!

The button we're using today is a momentary pushbutton, and they're the same type of button you'd find inside a game controller, remote control or telephone. A momentary pushbutton is a type of switch that only works when pressed.

In this guide we'll read the state of our pushbutton using the DigitalRead() function, we will then look at the state of the button. When the button is pushed, we turn on the LED. 

You'll find in many pushbutton tutorials that they use a resistor to "pull up" or "pull down" the input of the pushbutton.

Pulling up means that they input reads as "HIGH" when the button isn't pressed and pulling down is the opposite. We need to do this as our Arduino's inputs will suffer from electromagnetic interference that will give the wrong reading. Having said this, we're not going to use a resistor to do this; we'll use a resistor inside the Arduino's chip.

We can activate this "pull up" resistor with the line of code: 

pinMode(buttonPin, INPUT_PULLUP);

Look how we just saved you 1 cent!

Let's build up the circuit over at guides.littlebird.com.au .

 
Let's Get Started with the Day 5 Guide!

We're happy to help!

If you find you're getting stuck with today's guide, hit up our team of highly trained Arduino ninjas on this forum thread.

Previous article Day 6 Arduino Advent Calendar RGB LED
Next article Day 4 Arduino Advent Calendar

Leave a comment

Comments must be approved before appearing

* Required fields