How GPIO pins work? Why there is no short circuit?

Hi! I wonder how the GPIO pins work in arduino. I am sending an technical photo, can someone explain to me why there is no short circuit?

Welcome to the forum

When the switch is closed there is a short circuit between 5V and GND, but there is a 10K resistor that limits the current that flows so no damage occurs

Why you need to connect the gnd to the button? Why is this required? On the internet simulation it works without a resistor and connection to GND. I connect the gnd to the button because i see on youtube tutorial.

The aim is to keep the Arduino input pin at a known level (HIGH or LOW) at all times rather than disconnected when the switch is open which leaves the pin floating at an unknown voltage.

A floating pin may pick up signals from the electrical environment but of course that cannot happen with a simulation

Can I not connect the gnd to the button and write a function in the code that checks if the state is high, and if not, it sets that the state is low? If so, is there a guide for that?

I am a bit afraid that I will make a short circuit on the arduino board

Sorry, but I don't understand the circuit that you are proposing

In practice you don't need an external resistor. Use INPUT_PULLUP in pinMode() for the input pin to activate the built in pullup resistor, then wire the switch to take the pin to GND when it is closed. In the code test for LOW meaning that the switch is closed otherwise it is not closed

"Short" usually implies and unwanted connection, but not always. Technically it just means a direct (zero resistance) connection.

It's OK to "short" an input to ground or +5V, and in your circuit the input is shorted to 5V when the switch/button is closed (on).

It's also OK to short two inputs together, but there is almost never a reason for two inputs on the same processor chip to get the same input.

Also when the switch is on, one end of the resistor is connected to 5V and the other end to ground, so a small current flows through the resistor (per Ohm's Law).

When the switch is off the input is "pulled down" through the resistor. Both ends of resistor are at ground potential. The input pin has very-very high resistance so the 10K resistor "dominates" and with (almost) no voltage across the resistor (almost) no current flows.

It's NOT OK to short an output to 5V or ground, or to short two output pins together. i.e. If the output is shorted to ground and you write a high, it can't go high, excess current flows and you can fry your Arduino.

Your circuit is correct and should work.
What is does?

  • if S1 is open - it ties down the D13 pin to GND, but via this R1, 10K: it is fine: CMOS inputs (GPIOs) do not need real current to draw in. This D13 will see a low (0).

  • if S1 is closed - you pull the D13 to 5V, it will see a high (1). OK, there is also a (small) current from 5V via R1 to GND.

All correct.

Regarding GPIOs:

  • on most of the MCU chips, all is CMOS. So, an input has a very high (internal) resistance. It will not really draw any current as an input.
    So, you can tie a high (1) or low (0) via large external resistors, e.g. this R1 as 10K. The same if you would put an R in series with S1 from 5V.
    Due to fact that a CMOS input does not draw "any" current: there is no voltage drop ("Ohm's Law"): no current = no voltage drop, even the Rs have 10K. No current out from CMOS input if you let it open (S1 is not closed): it sees a low (0).

  • GPIO outputs
    These are a bit different (even a CMOS output, but now an active "switch" (transistor) inside:
    If GPIO output is set to high (1) - the current flows from 5V (the chip 5V) out of the pin. It tries to drive (tie up) the output signal to 5V.
    If low (0), the other transistor ("complementary logic" = CMOS) is now closed: the current flows from the outside (external) into the GPIO pin (it draws now the current and tries to tie down signal to GND).

Just to bear in mind: CMOS input gates (pins) have a FET. They do not drain "any" current (they do not need to take current to do something, they just act on the voltage seen). Due to "no current" = no voltage drop ("Ohm's Law"). So, you can tie down via 10K (R1) to GND, no voltage drop: pin sees a GND voltage (low, 0).

A pull-up in your case is not needed:
When S1 is open - D13 is pulled to GND via R1 (it sees low).
When S1 is closed - D13 gets 5V (and a bit of current flows externally via R1 to GND). D13 sees high.

A pull-up is needed if D13 (your input pin) can be "floating". This would happen if you would not have R1. In this case, S1 open but no R1 - D13 would be completely open (not connected to anything, "floating").
CMOS inputs, due to their very high input resistance (not draining "any" current), can be charged when left open: they could change to see a 0 or 1, just due to very tiny external charge there. So, CMOS inputs should never be left open, "floating".

All fine with your schematics.
Just to bear in mind that a mechanical S1 can bounce: your input D13 can see low and high in a very high repetition rate when you close or open S1: it "bounces". you have to "debounce" the signal (wait a bit until stable S1 seen).

All OK with your circuit.

"Shortcut"? not really, but there is a connection from 5V via R1 to GND when S1 is closed. Not a shortcut for input D13, but an external current flow is there (more power consumption in total for the board).

Oh, "shortcut", just to add:
As long as your D13 remains (and is) an input: all fine (no shortcuts).

But if you configure D13 as an output and you set this output to low (0) - "ohhhh yes, now you have a shortcut!"

Be carful with your schematics: when you configure D13 as output (via SW) and it would try drive a low (0) - it creates a shortcut (and will blow up your pin!):

When changing from input to output config: the internal pin logic is changed to connect from a high-resistance input gate to a low resistance output driver.
Due to fact, that S1 connects the 5V without any current-limiting resistor to D13 output (when configured as output) - an "endless current" (not limited by an Rx) will flow over the internal active "low-transistor" (complementary logic) to GND. It will burn this transistor!

So, a good practice is to use always "current-limiting" resistors (external) between 5V and a pin.
Never tie a signal directly (here as 5V) to a pin. Always use a series resistor, e.g. 10K as well (in series with S1 from 5V).

This avoids a damage of your MCU pin. When pin (D13) is an input: this 10K from 5V to D13 does not matter: no current, the D13 sees still high (a one, 5V,as for low with R1). But when D13 is an output, and no Rx there: it tries to die down the 5V to GND (when GPIO out set to low). This would burn your chip.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.