simulate this circuit – Schematic created using CircuitLab

Beginner here, trying to learn enough to start using a microcontroller.

  1. If the I/O pins are internally high, wouldn't pressing one of the buttons put voltage on the ground wire, making it no longer ground? Including Vss?

  2. I added R1 = 100Ω based on the STM8S003F3 datasheet max "Total current out of VSS ground lines (sink)" = 80 mA, and R2 = 270 Ω based on max "Output current source by any I/Os and control pin" = -20 mA. Am I doin' it rite? Is an additional resistor needed to limit current through (decoupling capacitor) C1?

  • 1
    \$\begingroup\$ Your schematic doesn't show which node you've defined to be ground. \$\endgroup\$ – The Photon Mar 27 '15 at 20:09
  • \$\begingroup\$ Sorry... I actually can't find the symbol in the editor. But I thought it was always the negative terminal on the battery. \$\endgroup\$ – Brandon Lockaby Mar 27 '15 at 20:26
  • 1
    \$\begingroup\$ Why on earth do you have a resistor connected to VSS? VSS/ground pins for ICs should be connected straight to ground. \$\endgroup\$ – Adam Haun Mar 27 '15 at 20:44
  • 2
    \$\begingroup\$ You normally don't need a resistor on either the Vdd/Vcc or Vss/ground pins of an integrated circuit unless the datasheet says so. Digital ICs don't need any supply current limiting, and analog ICs usually have their own internal bias circuits. \$\endgroup\$ – Adam Haun Mar 27 '15 at 21:25
  • 1
    \$\begingroup\$ Wow, get rid of R1. That will not help at all. \$\endgroup\$ – George Herold Mar 27 '15 at 22:08

Ground is not 0V.

Ground is merely a point of reference from which all other voltages can be measured.

Note: A voltage is a potential difference between two points. When you measure 5V you are measuring a 5V difference between two points.

It is entirely up to you what point in your circuit you choose as ground. Normally it is the point of "least potential" (such as the - terminal of your battery), but not necessarily.

So your "ground" is always "ground" because that is what you have chosen it to be. The voltage at ground, with respect to ground will always be 0V, since nothing can have any difference to itself.

When you press one of your buttons (with those two resistors removed, please) the lower side of the internal resistor (I assume that is what you mean in your question) is connected to ground, thus making that point measure 0V. When the button is released there is no connection to ground, so the voltage at that point is the supply voltage minus whatever is dropped by the resistor caused by any current flowing through it (typically a very small amount for an input pin).

  • \$\begingroup\$ I agree that the 100ohm resistor should be replaced with the wire. However, the other resistor can only be removed if the uC pins are configured as inputs (and they should be pulled up or down to avoid undetermined state, unless they are internally pulled up or down). If the pins are configured as outputs, there should be a pull up / pull down resistor. This will ensure that there is no "short" when you output "HI" on the pin which is connected to "LOW" / ground. \$\endgroup\$ – Nazar Mar 27 '15 at 20:36
  • \$\begingroup\$ @Naz You should have one per pin, not just one global one like that. With the single resistor, if you have one pin as output-high and another as output-low and press both buttons you will still get a short. \$\endgroup\$ – Majenko Mar 27 '15 at 20:38
  • \$\begingroup\$ That's right - one per pin. And you do not need to make a 20mA current. This is the maximum it can handle. You can use 10k resistor which will give you <0.5mA. This is a very common value to use. \$\endgroup\$ – Nazar Mar 27 '15 at 20:43
  • \$\begingroup\$ And to answer question 1: with current diagram, when you press one of the buttons, where will be 4.5V on the right of R2 and 0V on the left of R2 measured with respect to the negative battery terminal. Thus, pressing the button will not put voltage on ground. \$\endgroup\$ – Nazar Mar 27 '15 at 20:50
  • 1
    \$\begingroup\$ You do not need a resistor in series with the capacitor. As you will learn later, the resistor will decrease the time for the capacitor to charge - thus, mitigate the initial purpose of the capacitor. \$\endgroup\$ – Nazar Mar 27 '15 at 21:07

One important concept that you are missing is when saying the inputs are internally "HI" is that they are not directly connected to the Vcc. Instead, they are "pulled up" which means connected to Vcc through a resistor.

enter image description here

So, when the button is not pressed there is no current flow and the voltage on the internal resistor on both sides is equal to Vcc. When you press the button (and if R2 is absent), you force a ground on the pin. Thus, pressing the button will put ground on the pin, and not voltage on ground. The Vcc will remain on one end of the internal resistor, and ground will be on the pin and the end of the resistor that is connected to it.

The rest of the answers are in the comments of the Majenko's answer.

  • \$\begingroup\$ Thanks. I think I'm missing something simple. If +5V is on both sides of the resistor, I would expect +5V to be on the pin. \$\endgroup\$ – Brandon Lockaby Mar 27 '15 at 21:42
  • \$\begingroup\$ Exactly, that is why it is called "pulled up" - pulled to the high voltage. After you press the button, you force the ground to be on the pin and the bottom of the pull-up resistor. Now current flows through the resistor and you can make it small enough so it will be insignificant by increasing the resistor's value. Now, imagine if there was no pull-up resistor and the pin was connected directly to 5V: as soon as you press the button, you would connect 5V to ground resulting in a short circuit. Something would start smoking. \$\endgroup\$ – Nazar Mar 30 '15 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.