# How does an MCU detect current drop in an active-low button?

I'm confused as to how an active-low push button detects a change in voltage. Below is a model of a conventional setup of one of these buttons I found.

When the switch is open (like in the image), there is some current, I, flowing into the MCU.
But when the switch is closed, wouldn't the current just flow to both the GND and the MCU like in a parallel circuit? (because the electrons have the same amount of potential energy so the voltage is still the same?)
If so, how does the MCU detect when the button has been pressed if there is constantly current flowing into it?

I'm a novice with microcontrollers and electronics, so please don't hesitate to point out the obvious!
Thanks.

• The MCU doesn't detect current. It detects voltage. And the MCU pin draws almost zero current, so ask yourself, if the switch in your diagram is open, what is the voltage drop across the resistor if zero or almost zero current flows through it? And what voltage appears at the MCU pin as a result of this if 5V is on the other side of the resistor? Commented Apr 13, 2021 at 21:08
• But isn't the voltage also the same when the button is open/closed? Commented Apr 13, 2021 at 21:11
• It isn't. When the switch is closed, the pin is connected directly to GND and since the MCU pin uses GND as a reference to measure voltage against the pin will read 0V. When it is open is the situtation is as described above. Commented Apr 13, 2021 at 21:11

When the switch is open (like in the image), there is some current, I, flowing into the MCU.

Yes.

But when the switch is closed, wouldn't the current just flow to both the GND and the MCU like in a parallel circuit?

No. When the switch is closed, there is a short between the mcu pin and ground. So current will flow out of the mcu to ground, and through the resistor to ground.

If so, how does the MCU detect when the button has been pressed if there is constantly current flowing into it?

Current flows into the MCU when the switch is open, and the voltage on the MCU pin is high. Current flows out of the MCU when the switch is closed, and the voltage on the MCU pin is ground.

Most MCU's these days are CMOS, and the current into or out-of a CMOS input (in steady state) is quite tiny. It is the voltage at the gates of the input mosfets which determine whether the MCU is detecting a "high" or a "low" input.

• MCUs have CMOS logic inputs these days. There will be (virtually) no current flowing in or out of the input pin, whether or not the button is pushed or not. My assumption is that the few nanoamps of leakage current or currents to move charge to change the voltage due to input pin capacitance does not count, so that is why I said virtually no current. Commented Apr 13, 2021 at 22:13
• @Justme That's fine. It wasn't me who voted your answer down. I agree that the input pin of a cmos device sources/sinks very little current in steady state. A little more than that when switching. Commented Apr 13, 2021 at 22:34
• I didn't think it was you - It's just that this answer gives an impression that there is some significant current flowing in/out of MCU pin on purpose which is used for detecting pin state, while the main thing is the voltage, and any currents via IO pin are just non-idealities of real world components. In a MCU text book for beginners, it would be considered ideal and said that no current flows. Commented Apr 13, 2021 at 22:40
• I made an edit to incorporate you point. Commented Apr 13, 2021 at 22:46
• @MathKeepsMeBusy But even if there was current flowing from the MCU pin to GND, wouldn't the MCU still experience 5V? If not, what does it experience, and how does it detect this? Commented Apr 21, 2021 at 21:28

There are a lot of false assumptions.

No, current does not flow in or out of MCU input pin. No, MCU does not detect flow of current.

The only thing the MCU can detect is voltage.

Pushing the button connects GND to MCU input so there is 0V. Sure, current would flow via resistor and button.

When buttons is not pushed, no current flows and thus resistor keeps MCU input at VCC.

• "No, current does not flow in or out of MCU input pin." No - current certainly does flow into and out of a logic input pin, such as an MCU I/O pin in input mode. This is input leakage current (I_IH and I_IL), with common values being +/- 2..10 uA. This is often a significant characteristic and must be taken into account in input circuit calculations. Commented Apr 13, 2021 at 22:21
• @TonyM Sure, there is leakage. Also current due to changing voltage in the input pin capacitance. We both know that, and I do think that the concept of leakage current should be taken into discussion when the question is as simple as how an MCU can read a pushbutton. It might become relevant if the pull-up resistor would be 10 Mohm instead of 10 kohm. Common values are also near 1uA, at very high temperatures. Commented Apr 13, 2021 at 22:21