In the schematic diagram, you have LED1 connected to GPIO27 and LED2 connected to GPIO22.
In the wiring example you show the YELLOW LED connected to GPIO27 and the RED LED connected to GIPO22. Ergo… LED1=YELLOW and LED2=RED
The code though initializes them as LED1 to 22 and LED2 to 27 which does not match the above logic - as we see that RED is connected to 22
I mean, this code works, but led1 is defined in the code as GPIO22 which is the RED LED per the wiring example and it is NOT the RED LED that turns on when the switch is pressed
if micro_switch.is_pressed: # If the micro switch is pressed
print('LED1 ON') # Print a message to the console
led1.on() # Turn on LED1
led2.off() # Turn off LED2
So, why does the code work? is this another example of a “LOW” being sent to turn an LED on? The ‘is_pressed’ is horribly confusing here - especially in light of the comment “if the micro switch is presed”
Wiring Example Breadboard
The power rails are switched compared to the one I received in the kit (mine has the ground rail at the bottom edge). Almost didn’t catch this when wiring it up.
Turn off the LED lit when micro switch not pressed
Suggest adding an appropriate line to the exception part of the code so that Ctrl-C doesn’t leave an LED on. (I added led1.off() and that worked)
Purpose of the pull-up resistor if you set it to false?
Why do we put in a pull-up resistor if we set it to false in the code?
micro_switch = Button(17, pull_up=False)
Please explain what setting it to false does.
And is GPIO17 getting a HIGH signal when the micro switch is “at rest” (lever not being pressed) or is it getting a LOW in the resting state?
If we set pull_up=True, and wired the red and yellow LEDs to the GPIO pins as shown in the schematic (vs the wiring example), would the ‘if micro_switch.is_pressed’ work more logically? Actually turning on the YELLOW light when lever is pressed?
Pin Numbering on Schematic
The pin numbering on the schematic seems odd. The pins on the micro switch are labeled, C, NO, NC. It seems like C would be 1, NO would be 2, and NC would be 3…?
After investigation, the issue you’re experiencing is due to the wiring not matching the circuit design. Here’s the detailed analysis and solution:
Root Cause:
Schematic labeling error: The micro switch pin labels “231” in the schematic are incorrect. They should be “123”. This may have caused you to wire according to the wrong pin labels.
NC/NO pins connected in reverse: This course circuit is designed as a pull-down circuit (when the switch is not pressed, the pin is pulled to ground through a pull-down resistor, reading LOW; when pressed, the pin connects to HIGH). The code is also written for pull-down logic (is_pressed() detects HIGH as pressed).
However, your current wiring is:
NC (Normally Closed) connected to 3V3: When not pressed, NC is closed, so the pin connects directly to 3V3, reading HIGH → is_pressed() returns True (incorrectly detected as pressed)
NO (Normally Open) connected to GND: When pressed, NO closes, connecting the pin to GND, reading LOW → is_pressed() returns False (incorrectly detected as not pressed)
This is why you see the yellow LED lit when pressing the switch and the red LED lit when releasing it — exactly the opposite of what’s expected.
Solution:
Please swap the NC and NO pin connections:
NO (Normally Open) to 3V3: When not pressed, it’s open, the pin is pulled to ground through the pull-down resistor reading LOW → is_pressed() returns False (correct)
NC (Normally Closed) to GND: When pressed, NO closes, the pin connects to 3V3 reading HIGH → is_pressed() returns True (correct)
After swapping, the circuit logic will work as expected — the red LED will light up when the switch is pressed, and the yellow LED when released.
Additionally, the micro switch pin labels “231” in the schematic should be corrected to “123”, and we will update the documentation accordingly.
If you still have any issues after making these adjustments, please don’t hesitate to contact us.
For clarification, I wired it exactly like the Wiring Example (making sure my positive and ground rails were used correctly) and ran the code exactly like it is written. The Wiring Example has the NC pin going to 3.3V. And the code does, indeed, have the RED LED lit when lever is not pressed (as expected per the lesson)
BUT the code has LED1 going to GPIO22 (which, in the wiring example, is the RED LED), why does the code set the RED LED to “on” when the lever is pressed (but the YELLOW LED is actually what turns on)? Why does that part “work” when it seems, logically, like it would not?
You are absolutely right — this was caused by a mismatch between our code and the wiring. We have now synchronized the schematic, wiring diagram, code, and effect description, and the documentation has been updated.
The correct setup is: the red LED (led1) is connected to GPIO22, and the yellow LED (led2) is connected to GPIO27. When you press the Micro Switch, the yellow LED (led2) lights up.
You are correct that changing pull_up to True reverses the detected switch state and makes the LEDs work as expected.
Since the circuit already includes an external 10 kΩ resistor and a 104 capacitor, the switch level is already defined by the hardware, so the internal pull resistor isn’t needed. The real fix is to tell the code which level means “pressed” — we’ve updated it to explicitly define LOW as the pressed state:
Initialize the micro switch (LOW when pressed)
micro_switch = Button(
17,
pull_up=None,
active_state=False,
bounce_time=0.05
)
Here, pull_up=None means no internal pull-up/pull-down is used, and active_state=False means LOW is the pressed state.
We will also rename LED1 and LED2 to RED_LED and YELLOW_LED to make their functions clearer.
Thank you again for helping us identify and correct this issue.
That worked! Thank you for the changes and explanations.
When you next work on the wiring example graphic:
The microswitch pins are actually spaced out so that there is a breadboard row between each pin (the graphic currently has all three pins side by side - one row after another)
change out the breadboard so that it matches the one that comes in the kit (where the power rails are reversed - bottom set has positive on top and negative on bottom while top set of rails has positive on top and negative on bottom)
Sidenote: I really like that you added the resistor values on the wiring example - I can see that being very useful for people who are color blind.
About the placement of the micro switch
We’ve confirmed that inserting the micro switch into columns 40, 41, and 42 is fine. On a breadboard, each short column is isolated from the others, so this is a normal way to insert it — no need to worry.
About the direction of the breadboard’s power rails
The difference you observed does exist — our breadboard is a generic (off-the-shelf) product, and the direction of its power rails is opposite to how they are drawn in the Fritzing model. We’ve passed this on to our technical colleagues to evaluate whether we can switch to a breadboard that matches the model, but whether it can ultimately be changed is still uncertain.
If you have any further questions, please feel free to reach out.
Apologies. Let me clarify… the leads on the microswitch that came in the kit are further apart (2 rows apart rather than 1). So, 40, 42, 44 would work. The Wiring Example has them going into three side by side rows which is NOT doable.
SideNote: it is my understanding that the COLUMNS on the breadboard are A-E and F-J and the ROWS are numbered. At least, that’s how the letters and numbers are printed on the breadboard I received (and yes, the terminology gets confusing when you turn it sideways as we all do).
Re: Breadboard
Actually, many of these lessons have a Wiring Example that DOES match the breadboard I received in the kit but many don’t. It is a mish-mash. Perfect world would be all of them match the breadboard in the kit but most important I think would be that they are all standardized one way or the other (with maybe a routine IMPORTANT note on each wiring example to double check that your breadboard power rails match the graphic and if it does not to adjust accordingly).
From the lessons I have done so far:
Power Rails in Wiring Example DO match my breadboard:
1.1.5
1.3.1
1.3.3
2.1.1
2.1.4 - 2.1.5
Power Rails in Wiring Example DO NOT match my breadboard:
1.1.1 - 1.1.4
1.1.6 - 1.1.7
1.2.1 - 1.2.2
1.3.2
2.1.2 - 2.1.3
Regarding the spacing of the Micro Switch, you are right — it should be 40, 42, 44, and we will revise the connection diagram as soon as possible.
As for your observation that some example breadboard power rails match yours while others do not, you are very observant — that is indeed the case. The ones that match yours were flipped 180° in Fritzing before the diagram was drawn, so the power rails look the same. This was indeed an oversight on our part; we have noted it and will fix it in the future.
Thank you very much for every suggestion you have raised — they are all very helpful to us. Our tutorials have gone through many revisions and updates, so there may indeed be some minor issues. If you find any new ones, please feel free to let us know.