Let’s take a look inside the pushbutton to better understand how and why it changes the circuit when you press it. In this activity, you will:
In this activity, you will connect new parts, as well as make use of parts from a previous activity.
(1) Resistor - 220 Ω (red-red-brown-gold)
(1) Resistor - 10 kΩ (brown-black-orange-gold)
(1) Jumper wire - black
(1) Pushbutton
You will be using the alligator clip leads again in this activity. The 3 LED circuits are not used in this activity, but will be used again in the next one.
Remember from the Parts list in the Build & Test a Pushbutton activity’s Parts section that it has a pin map with pins 1, 2, 3, and 4? Since you will be probing various pairs of those pins with the micro:bit continuity tester, here it is again for reference.
This script will use the CYBERscope to probe the electrical connections when the button is pressed and not pressed.
Here is the pushbutton’s theory of operation. That’s the electronics-speak way of saying “how it works.”
Here are continuity tests you can perform to verify the pushbutton’s theory of operation. First, verify that the 1,4 pair is not connected to the 2,3 pair unless the pushbutton is pressed (and held to get your measurement).
Next, verify that the 1,4 and 2,3 pairs of pins are interconnected regardless of whether the pushbutton is pressed or not:
Looking inside the pushbutton, the legs that stick out of both sides of the pushbutton’s body are actually wires that pass all the way through. One of the wires forms legs 1 and 4, and the other forms legs 2 and 3. The button has a metal bar attached underneath and a springy material that keeps it floating above the two wires. When you press the button, the metal bar comes to rest atop the two wires.
Since legs 1 and 4 are actually part of a single wire, they are always electrically connected, so a micro:bit continuity test will always display the checkmark. The same applies to legs 2 and 3.
When the button is not pressed, current cannot conduct between the 1,4 and 2,3 legs, so its connection is called open or an open circuit. When the button is pressed, current can conduct between the 1,4 and 2,3 legs, and the connection is called closed. Since this pushbutton is open when it is not pressed, it is called a normally open pushbutton. Though your kit does not have them, normally closed pushbuttons also exist, where their connection is closed when it is not pressed, and open when it is pressed.
When the button is not pressed, legs 1 and 4 are insulated from 2 and 3. So probing any of these pairs of pins will result in the micro:bit continuity tester’s LED display showing the not connected X: (4, 3), (4, 2), (1, 2), (1, 3). When you press and hold the pushbutton, the micro:bit continuity tester displays the connected checkmark instead.
In addition to checking pushbutton functionality with continuity tests, sometimes the voltage it applies to the micro:bit needs to be checked. In prototype tests and machine repairs, this is one of the first tests when pressing a button does not produce the desired result.
measure_P6_volts_with_cyberscope.hex [3]
Release the pushbutton and verify that the measurement returns to a value close to 0 V.
When this pushbutton is pressed, it is in its active state. If you think of GND as a “low” voltage, and 3.3 V as a “high” voltage, a pushbutton that sends a 3.3 V high signal when you press it is considered active high. When a pushbutton is not pressed it is in a 0 V, low resting state.
The 10 kΩ resistor connected to GND in the circuit below is called a pull-down resistor. Because the 10 k resistor is connected to ground, it “pulls down” the pushbutton to a GND = 0 V resting state voltage when the button is not pressed. The circuit also applies that resting state voltage to P6. On the other hand, when the button is pressed, the circuit applies 3.3 V to P6.
Without the pull-down resistor, a microcontroller’s I/O pin that’s set to input could “float” in response to nearby electric fields, such as the static electricity that builds up on people as they shuffle along the floor. That is why a floating input often switches from sensing 0 to 1 and back to 0 for no apparent reason. It’s also why a resistor that pulls the resting state voltage (either down to GND or up to 3.3 V) is so important.
When the button is pressed, it is in its active state. P6 becomes connected to 3.3 V through the 220 Ω resistor, and that is called active-high. A small amount of current also passes through the 10 kΩ resistor, but not through the 220 Ω one. That’s because as an input, an I/O pin is invisible to the circuit. It does not supply or draw any voltage or current. All it does is sense if voltage is above 2.3 V or below 1.0 V.
A pushbutton circuit can also be built with reversed 3.3 V and GND connections. In other words, the jumper wire could be connected to GND and the 10 kΩ resistor could be connected to 3.3 V. With the 10 kΩ resistor connected to 3.3 V, it is called a pull-up resistor because the resting state (not-pressed) voltage would be “pulled up” to 3.3 V. Its active state, while pressed would be 0 V, or active-low.
For prototyping, that 220 Ω resistor protects the microcontroller against a variety of circuit mistakes. (The 220 Ω resistor maybe could be replaced by a simple wire, but that’s typically for a final design.) The most common scenario is a script that makes a pin an output that sends 3.3 V through a wire to GND = 0 V. Without that 220 Ω resistor to “resist” the flow of current, some microcontrollers I/O pins can become damaged by trying to supply too much current.
DO NOT TRY THIS WITH YOUR MICRO:BIT!
There is currently a pushbutton on the breadboard with no voltage, I/O pin, or pull resistor connected. Create an active-low pushbutton with a pull-up resistor. Write a script to test the circuit. Hints:
Imagine that you want a light to blink red when nothing is sensed but to stop when an object is present, much like an automatic door opens when you step on a mat, but is closed the rest of the time. Write a script so that your new pushbutton pull-up circuit flashes the red LED without a pushbutton press and turns off when you press the pushbutton.
Solution:
Hint: Combine scripts from this activity and Build and Test a Pushbutton.
# pushbutton_pullup_with_red_LED from microbit import * state = 0 display.off() pin9.set_pull(pin9.NO_PULL) while True: state = pin9.read_digital() print("state = ", state) sleep(250) if state == 1: pin15.write_digital(1) sleep(250) pin15.write_digital(0) sleep(250)
Links
[1] https://learn.parallax.com/sites/default/files/content/Python/breadboard/hex/continuity_tester.hex
[2] https://python.microbit.org/v/2
[3] https://learn.parallax.com/sites/default/files/content/Python/button/measure_P6_volts_with_cyberscope.hex
[4] https://cyberscope.parallax.com
[5] https://learn.parallax.com/tutorials/language/python/sense-pushbutton-presses/build-and-test-pushbutton/script-and-tests