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 lower 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.
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.
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 ;-)
Check, whether your parts are connected correctly and now let’s code!