Unit 11 – Arduino and the Button

Arduino Button Tutorial if Statement

So, you come a long way! Was it fun? That is very important. Let’s continue and I show you how to connect and program a button.

What is a button?

A button can close a circuit when it’s pushed. If it is released the circuit is open again. One could say, it switches off by itself. Usually it is done by a build in spring.

You already know the first part of the circuit. It is a LED with a resistor. But this time we will use the outer rows of the breadboard to provide the plus (5V) and minus (GND). That has many advantages since we often need to connect many parts to plus and minus.

The image shows, how the holes on the edge of a breadboard are connected. This are rows. Let’s use the blue one to connect the GND and the red one for 5V.


Circuit Part 1

Arduino Button if statement

The first part of the circuit is done, the second consists of a resistor and a button. If you use a button, you always need to use an additional resistor, too. It is called drop down resistor and helps Arduino to decide whether the button is pressed or not.

Circuit Part 2

Arduino Button if Statement Part 2

Let’s check the circuit, again. We have a 100 kOhm (kilo ohm) resistor connected with the button. The connection between both is connected to a green cable which ends in the pin 11 of the Arduino. The other side of the resistor is connected to the GND (minus). It is the black cable. Through a red cable the other side of the button is connected to the plus (5V).

If the button is not pressed, over the 100kOhm resistor the pin of the Arduino is just connected to the GND. If we push the button, it is also connected to the plus, but without a resistor placed in the line. Current is lazy and always looks for the easiest was. Since the button is pressed, there are two to choose. One with resistor to the GND and one without a resistor to 5V. How would you decide if you are between two bus stations? The one is hill up (with resistor), the other is hill down. Well, I would go for the hill down bus stop 😉

Arduino Button function pull down resistor

Check, whether your parts are connected correctly and now let’s code!

1 thought on “Unit 11 – Arduino and the Button”

  1. Pingback: Unit 12 – The Button and the if-Statement - StartHardware - Tutorials for Arduino

Leave a Reply

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