In this project we'll be adding a new input device -- the pushbutton (or just "button"). A button is just a very simple switch – electric current can flow through it only when it is pressed.
Take one of the buttons out of your I/O (Input/Output) RaspberrySTEM Cell so we can take a closer look at how a button works. This is a representation of most basic pushbuttons – they have four “legs” that can be attached to your breadboard and wired to the circuit and then one button in the center of the device that can be pushed (“closed”) or released (“open”):
Internally, the left side of the button (the two legs on the left) are connected together, and the right side of the button (the two legs on the right) are connected together:
When we insert a button into a circuit, it has one of two operations:
When the button is left unpressed, it creates an open circuit, no electric current can flow through the button and nothing happens.
When the button is pressed, the button acts as a wire and closes the circuit – electric current can then flow through the button.
So, if we go back to our first breadboard circuit containing a simple resistor and LED that is always illuminated, we should be able to add a switch that we can then use to control the LED turning on and off (by pressing the button).
Let’s build that circuit now…
Here’s what the schematic will look
like:
To build the circuit, let's start with the circuit we built in the last project -- RASPBERRY PI POWER:
Step #1: Remove wire from LED to ground.
We’re going to be adding the button into the circuit between the LED and ground, so the first step will be to remove the wire that connects the LED to ground.
This is what the breadboard should look like at this point:
Step #2: Provide connectivity from the LED to the button.
The next step is to provide connectivity between the second lead of the LED and the button. You can wire the button directly to the LED, but to space the parts out a little more, we're going to first add an additional wire (one of the the half-inch green wires).
This is what the breadboard should look like at this point:
Step #3: Place button on the breadboard.
Next, we’ll place the button on the breadboard. Note that the button should be oriented so that the two sides of the button sit on different connect strips, as follows:
![]() |
![]() |
CORRECT | WRONG!!! |
One side of the button should sit in the same connect strip as the green wire from the LED. This will provide connectivity from the LED through the green wire and to the button, as follows:
Note: In our diagram
above, you'll notice that the button sits across a notch in the
breadboard. This isn't absolutely necessary -- the button could
sit with both left legs in the same connect strip and both right legs
in the same connect strip. But, because buttons take up a lot of
space on the breadboard, we find it easier to position them across a
notch in many cases. You can decide how you want to wire your
buttons, but keep in mind that either way will work.
Step #4: Connect the other side of the button to ground.
Finally, we can complete the circuit by connecting the other side of the button to ground, like this:
At this point, your LED should not be lit. Remember, while we have a potentially complete circuit, there is still a lack of physical connection through the button until the button is pressed. In other words, there is a break in the circuit inside the button (this is how a button works) and the way to complete the circuit is to press the button.
If you press the button, you should see the LED illuminate.
In this project, we controlled the flow of electric current through the circuit by inserting a switch (the button) between the LED and ground. That said, the switch didn't need to be inserted at that point in the circuit for it to work -- we could have inserted the switch anywhere in the circuit and it would have worked the exact same way. Remember, if the flow of electric charge is broken anywhere in the circuit, the circuit will fail to operate. So, our decision to insert the button where we did was completely arbitrary.
Congratulations - you’ve just built the same circuit used in most simple flashlights!
In the next project, we’ll add software into the equation, and will start using "GPIOs" to control our output.