Shop OBEX P1 Docs P2 Docs Learn Events
To ground when connected to a pin — Parallax Forums

To ground when connected to a pin

cameronsmithcameronsmith Posts: 2
edited 2011-11-03 11:25 in BASIC Stamp
Hi Guys,

I'm new at this so please try and explain in simple language. Why does the circuit has to go to ground when it's connected to the input pin of the basic stamp? Isn't the basic sending the signal to ground anyway?

Please see the diagram below.

Thanks!

push-button.jpg
420 x 227 - 7K

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2011-11-03 08:13
    cameronsmith,

    Welcome to the forum!!

    Current will follow the least path of resistance. When the switch is open, the least path of resistance is through the resistor to ground. If the pin is configured as an input, it will read this as a "0". When the switch is closed, the least path of resistance is through the switch. In this case the resistor acts as a current limiter to prevent a direct short to ground. If the pin is configured as an input, it will read this as a "1".
  • FranklinFranklin Posts: 4,747
    edited 2011-11-03 08:21
    Also if the pin is an input and there is no resistor the voltage on the pin is unknown and could "float" between 0 and 1.
  • cameronsmithcameronsmith Posts: 2
    edited 2011-11-03 08:27
    Hi Beau,

    Thank you for the welcome,

    From the diagram I would think that when the switch is open no current can flow because the is a break in the circuit. So, when the switch is down then the current can flow. So, if that is the case why would you ever need the resistor?

    Or did I read the diagram wrong, do you mean when the switch is down that it is connected to the input pin. When the switch is up it's just connected to earth. If that is the case how can you tell the difference from what I assumed and from what is correct :S

    Thanks,

    Cameron.
  • ercoerco Posts: 20,256
    edited 2011-11-03 11:02
    To use a pin as an input, you must connect it either to ground or to +5V to read it reliably. Per Franklin, you can't let it "float" (not connected to anything) or that will cause the end of the world :) . The 10K resistor connects the pin to ground when the switch is not pressed, so it will be at 0 volts. When the button is pressed, just half a milliamp of current passes through the 10K resistor (5V/10000 ohm=0.0005) and fairly obviously, the pin is connnected directly to 5V.
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2011-11-03 11:25
    cameronsmith,

    Just because the pin is an input doesn't mean that current doesn't flow through it. In fact it does, so in order for the pin to detect a "0" current must flow from the ground through the resistor and into the pin where the external state can be determined.

    So far everybody has basically stated the same thing... if an input pin is 'floating' it's still taking the least path of resistance, however in this configuration it is most sensitive to external electrical noise which can cause the reading to be seemingly random or 'floating' . At some finite point the definition of 'floating' becomes 'fixed' depending on where you define a threshold... by forcing an alternative path of 'least' resistance (a 10k resistor in this case) you create an immunity or attenuation to any external noise that would normally affect the I/O pin. Still when you close the switch the switch provides an even lower path of resistance over-riding the 10k resistor.
Sign In or Register to comment.