41099 Chap.5 Digital input: pull resistors, logic levels and debounce
Digital input: pull resistors, logic levels and debounce
What this chapter covers
- 01
An input with only a switch attached has no defined voltage while the switch is open
- 02
External pull down, external pull up and the internal resistor compared side by side
- 03
Inverted readings, and why the fix is usually software rather than rewiring
- 04
Active low output wiring, where a low level lights the indicator
- 05
Contact bounce, and a timing window that accepts one edge and refuses the rest
Explain why a naive toggle works about half the time, and what the timestamp fixes
- 1State how many times the stored state flips for one physical press.
- 2Explain why the outcome looks random to the user.
- 3Give the timing test that removes the extra edges, and say why it is written as a difference.
Key terms
- Floating input
- An input pin with no defined connection, whose reading is unpredictable.
- Pull up resistor
- A resistor tying an input to the supply so an open switch reads a high level.
- Pull down resistor
- A resistor tying an input to ground so an open switch reads a low level.
- Active low
- A wiring arrangement in which the low output level is the one that turns a device on.
- Contact bounce
- The rapid chatter of a mechanical switch as its contacts settle.
- Settling window
- The interval after an accepted edge during which further edges are ignored.
Digital input: pull resistors, logic levels and debounce FAQ
Why does a button without a resistor give readings that change when a hand moves nearby?
Because while the switch is open the pin is connected to nothing and is electrically floating, so it picks up whatever is around it. The reading flickers, responds to proximity and settles differently on each restart. This is neither a faulty board nor a faulty program; it is a missing resistor, and the resistor exists to give the pin a defined level during the open half of the cycle.
A button works but everything happens backwards. Should the circuit be rewired?
Usually not. A pull up arrangement, internal or external, reads high while the switch is open and low while it is pressed, which is the opposite of a pull down arrangement. The wiring is normally correct and the condition in the program needs to be inverted. The course materials demonstrate this with a conditional and then invite you to achieve it without one.
What separates a misconfigured pin from a faulty switch when the reading is stuck low?
Release the switch and measure the pin voltage. With the internal resistor in use the pin should sit near the supply voltage while the switch is open. A reading near the supply means the configuration took effect and the switch is at fault, perhaps wired across the wrong pair of its own legs. A reading near zero means the internal pull-up was never enabled.
Why not simply use a very long settling window?
Because a long window also refuses genuine presses that arrive inside it, so a user pressing twice quickly gets one response. Contact settling takes a few milliseconds, so a window of a few tens of milliseconds is already generous. Choosing several hundred milliseconds trades a rare fault for a permanent limitation, and the reasoning is what is being assessed.
Does an indicator wired to light on a low output need different current calculations?
No. The supply, the resistor and the forward voltage are still in the same series loop, so the current is unchanged. What changes is that the pin now sinks the current rather than sourcing it, and that every write to that pin inverts in the program. Being able to say that the electrical design is untouched is the point of the exercise.
Assessment move
Draw the input arrangement and write the level it produces when open and when closed, before writing any condition. Treat an unexplained reading as a wiring question first and a code question second. Rehearse inverting a button's sense on request, because that is a standard live modification.
Working through Digital input: pull resistors, logic levels and debounce in 41099? Sia is AskSia’s AI Engineering tutor — ask any 41099 Digital input: pull resistors, logic levels and debounce question and get a clear, step-by-step explanation grounded in how 41099 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.