Baffled by pullout resistor in SIK example #5

Hello,

I’m new to this and having a great time plowing through the SIK examples, specifically #5 in the SIK manual (starting on page 36 here: http://dlnmh9ip6v2uc.cloudfront.net/dat … dpi-01.pdf

In the example code, it explains it like this (which baffles me):

But wait - what happens when you’re not pushing the button?

In this state, the pin is disconnected from everything, which

we call “floating”. What will the pin read as then, HIGH or LOW?

It’s hard to say, because there’s no solid connection to either

5 Volts or GND. The pin could read as either one.

To deal with this issue, we’ll connect a small (10K, or 10,000 Ohm)

resistance between the pin and 5 Volts. This “pullup” resistor

will ensure that when you’re NOT pushing the button, the pin will

still have a weak connection to 5 Volts, and therefore read as

HIGH.

So, I’m probably not understanding the words correctly, but it seems to me that if the button is OFF, it would be sending 0 volts? and how does adding a resister make it so that it is a weak connection to 5 volts? Why not a wire straight to the 5v connection?

I can sense my ignorance like a weird cloud, and would be grateful if anyone could illuminate me! :slight_smile:

lee

The button is just a simple switch, it connects its two terminals together when pushed and there is NO connection between its two terminals (‘open’) when not pushed.

Measure the resistance with your DMM on the Ohm scale (you have a DMM right? if not then DO BUY one as this is absolutely necessary instrument to have to work with electronic) across the terminals of the switch.

Then wire the switch and pull-up resistor as per the SIK #5 and measure the Voltgae at the input pin with the switch pushed and not pushed.

think of an open pin in nature as being tri state. the three states being positive, neutral(will float), and negative.

Electrons stream FROM a negative source (meaning all circuits pressure originates from a negative pole origin) flowing across (whatever is in the way, lol) toward the positive (lack of electrons, a vacuum) pole.

To make a reliable 2 state control (switch) on a toilet (flush) you command by steel rod and physical connection. contol cant do anything but what you want it to.

But if that toilet had poor linkage design. and flushed on its own sometimes, wrong links and design let it flap either way…I guarantee you would use a little spring or rubber band to pull something to one side so you could sleep at night again…

(analogy).

Resistor pulls our floating tri-state switch to one side (high or low) so it only flap in two configurations. the Arduino logic is like many more tiny switches, so they only read or write in 2-states (1 or 0)(on or off) you give them 1/2 answers or any fraction of a yes or no, they know you is lying and they aint gonna even talk to you no moh.

Why not connect a pin directly to Vcc, or 5 volt in your case? But use a fairly high value resistor. If it is an input, then it isn’t a problem. As the circuit will let hardly any current pass throug the pin. But lets say your program (accidentally) turns that pin into an output, and sets it low to GND. Now you short circuited the pin and alot of current flows into it. Likely burning the pin circuitry. But with say a 10k resistor, the current will be limited to about 5v/10,000.=0.5 ma. That it can handle.

Thanks so much for the great responses. Sorry for the delay in responding–I just wanted to wait until I had the quality time to sit and study this and everything y’all said. Also, I thought I’d come to understand it, so I wanted to run an experiment to test my theory–which turned out to be wrong. I’d like to ask y’all each questions about your responses individually, but first please take a look at what I did, which may help to explain my state of complete newbie-ness :slight_smile:

I thought the pullout resistor existed to ensure that only a LOW signal got sent to the pin. So I figured, okay, I’ll replace the pullout resistor with a straight wire connection to the 5v power, and I changed all the “LOW”'s in this code to “HIGH”:

if (((button1State == HIGH) || (button2State == HIGH))  // if we're pushing button 1 OR button 2
      && !                                               // AND we're NOT
      ((button1State == HIGH) && (button2State == HIGH))) // pushing button 1 AND button 2
                                                        // then...
  {
//this part I left as HIGH, of course.
    digitalWrite(ledPin, HIGH);  // turn the LED on

Well, it did work, but what’s weird is I changed the code before removing the pullout resistors, and it STILL WORKED.

So I think I’m wrong, but I’m not sure how I’m wrong :slight_smile:

Questions (if it pleases you to answer them):

@Watr: Your suggestion sounded wonderful, so I got out my DMM and promptly discovered that I was even more of a newb than I realized. Care to give some more detailed (novice) guidance? On the Ohm part of the multimeter, I have the choices to set the dial to 2000k, 200k, 20k, 2000, or 200. How do I know which one to use? I tried 200 and when I put the red on the 5v side of the switch, and the black on the grounded part, the light came on. It didn’t when I had it set to 2000k. I’m pretty sure that means something, but I’m not sure what. After you’re done laughing, I’d LOVE to understand this better.

@CircuitBurner: I’m having trouble grasping how the switch can have three states. It’s closed, or open, right? How can it be three? That being said, I’m heavily pondering your analogy about the spring on the toilet flapper, and in fact that’s what prompted me to do the experiment above.

@Valen: the safety aspect is one I hadn’t considered, and is very good information. I shall have to program carefully :-). Is that the only reason though? The other stuff I’ve read seems to suggest it’s not just a simple safety issue. Or am I thinking one thing is two different things?

Any further feedback would be greatly appreciated! I’m sure I can do this!

lee

For measuring some as simple as a switch, which would in theory have resistance of zero Ohm when closed and infinite Ohms when open, the DMM scale doesn’t matter too much. In practice, the 200 Ohm scale is proper to measure the switch.

Try googling “how to use a digital multimeter” to find a few tutorials that would be helpful to you.

CircuitBurner was talking about the ‘states’ of the digital IO pin not the switch. When an IO pin is setup as an output it typically has two states, high or low. Some digital logic have a third state which is high-impedance or not driven to a high or low. This is used when more than one digital device can drive a line such as on a data buss (think of multiple memory chips and the data can flow in both direction to be written to memory or read from memory).

This third ‘hi-Z’ is also present when an IO pin is setup as an input.

Look through and read the many threads here on SparkFun’s forums. Many electronic basics are explained. Also, read the info on SparkFuns main web site as there is lots of good beginner info there as well.

Good luck and have fun learning.

Thanks waltr, I am doing all those things now.

Quick question though…why does the circuit still work when I make the code changes I mentioned? I just did it again to make sure I’m not insane, and the conditionals work exactly the same when testing for HIGH as they do for LOW.

???

As mentioned, this kind of switch either connects its two terminals or leaves them disconnected. If the switch is connected between the I/O pin and ground, it will either connect the I/O pin to ground (so the processor will read a LOW) or not connect it to anything (that’s the problem state; depending on the processor, it is not guaranteed what it will read in this case).

Adding a pullup resistor (between the I/O pin and Vcc) guarantee the processor reads a HIGH when the switch is in the open (disconnected) state. As for why we need the resistor, think about what will happen when the switch is closed. In that case, the resistor will have one side connected to Vcc and the other, through the switch, to ground. If the resistor is big enough (say 10K) some current will flow through it, but not enough to cause any damage. If the resistor has a very small value, or is just a short, a lot of current will flow. This could damage the resistor, or more likely will cause the power supply to shut down or overheat.

/mike