Electronics question about resistor/button combo

I'm doing the Button Arduino example and I've got a likely technical question on why the whole resistor needs to be used.

This video from the Maker Shed is very good and starts explaining why at 2:25, but I've still got questions.

First of all, I think it would make perfect sense (like the narrator in the video says wouldn't make sense) to simply hook the pin up to 5v and put the button in between.

After that, he goes on to explain that when the button is unpressed, the electricity comes out of the pin and into the ground. I thought the pin was sensing the electricity coming in. Again, when the button is pressed, it comes out and goes into the 5v. You'd think the 5v is the one sending out the energy. (I understand that a resistor is used because when the button is closed it is easier to go through the button instead of the resistor).

Is this because the pin also measures electricity getting "sucked out" of it, and if you don't anything hooked up to it when the button is open, it varies with the random noise it's sensing?

I suppose this likely has to do with the deep subject of what direction does the electricity flow (from the + to - or vise versa). I have searched on that topic and have found some answers, but maybe not enough, as I must ask this question. So I'll see what people say and provide some feedback to what I know.

Thanks! :)

Its to do with the floating nature of arduino input pins. They need to be held high or low by some means. The resistor is a "pull down" (to low - 0v) and the switch pulls it high (5v). The dumbed down video glosses over the important bits and gets bogged down in electron flow which confuses the issue. Do a google search on 'pull down resistor' or the converse 'pull up resistor'.

The impedance (or resistance if you like) of an arduino input pin is close to infinite (about 100 mega ohm) so the current flow into the pin can be largely ignored and you can assume its just detects the high or low state without drawing current.

Without the resistor the state of the arduino input would be determined by stray voltages (noise) which can literally be pulled from the air.

The instructor is very untidy in most of his explanations; sometmes he says electricity sometimes electrons :slight_smile:

There are no LGM in the chip which “mesure” things but CMOS transistors, and there is no way around to learn how an input and an outout of the chip work for any advanced work with microcontrollers…

You can start with this sketch here:

the complete truth looks a little bit more like this. http://www.ami.ac.uk/courses/ami4822_dsi/u03/images/originals/Fig3.3.gif The “parasitic capacitors” (of around 2 pF) enter the scene when you do things above 1MHz - very unlikely with an Arduino.

Adafruit does a good job at explaining button switches and pull-up/pull-down resistors.

http://www.ladyada.net/learn/arduino/lesson5.html

:)

Thank you, your responses were helpful. I understand the concept of a pull-up/down resistor now. The only thing I don't fully understand is the current flow of an input pin.

From pluggy:

The impedance (or resistance if you like) of an arduino input pin is close to infinite (about 100 mega ohm) so the current flow into the pin can be largely ignored and you can assume its just detects the high or low state without drawing current.

Could someone please explain this more simply or something? Does this mean you just throw the pin in the middle of a circuit and it detects what kind of current is going by/through it? More like "seeing what's on the other end" -- ground or 5v to be attracted to? This makes it seem like a magnet that adjusts/flips around to an outside magnet that it is presented to, rather than a water wheel that turns slowly or quickly depended on a stream of water that is shot at it. Or is it more complicated than that? The mention of resistance makes it seem so.

Thanks! :)

All this is more complicated, and metaphors will not really help. I gave you a simplified (!) circuit above. There are no LGM inside but an FET, and without having learnt at least a little bit about FETs it will of course make not much sense.

There is no communication without transfer of energy, the higher the environmental temperature and the density of information the more power is needed. This is the basic law of information transfer, there is even a simple formula for it :slight_smile:

So some current has to flow in any case, which however is low, and proportional to the frequency of the signal. This is - so to speak - the basic law for CMOS devices. There is also a simple (simplified) formula for this :slight_smile:

Oops, I think this is not really what you wanted to know. It seems to make things even more complicated…

For the highest abstraction you can assume there is NO “electricity” going into or out of a pin configured as INPUT and NO PULL-UP. (But note that this is basically wrong!)

When such a pin is not connected to anything that is related to the positive or negative supply voltage it will not know whether it should be HIGH (near to + ?) or LOW (near to ground ?) This leads to ambigous and changing readings!! (There are more issues when you consider the true electrical situation…)

So you ALWAYS have to tie a CMOS input to some defined voltage. As there is NO ELECTRICITY flowing (a simplification!!) the value of a resistor used for that connection can be very high. 1 megohms is fine. Typical values you often see are 10k, which however is funny at the first glance.

When you connect this resistor to + you call it “pull-up”, when you connect it to ground, you call it “pull-down”.

That 10k (or another reasonable value) can make sense when you use this resistor ALSO as the counterpart of a device connected to the other polarity (e.g. a “switch”). But a “switch” is also not an “ideal” element (HIGH/LOW): it has a resistance when closed (RC, generally some milli Ohms, but can be much more!) and opened (RO, generally some 10 megohms, but can be much less!). In many cases also a wet human finger is involved, that will provide a path to ground, around some hunders kilo ohms.

The pull-up or pull-down should be (rule of thumb) > 5* RO and < 5*RC.
If there is no room in that range any longer (e.g. a “switch” working between 100 ohms and 1,000 Ohms.) you have to be more careful in your selection of pull-ups or pull-downs.

There isn't a short cut to learning basic electrical theory. Once you've got the relationship between voltage, current and resistance clear in your head, most arduino stuff falls into place.

In answer to the current flow into an input pin, to put it in other words, the current flowing into an input pin is so low it can be ignored, its the rest of the circuit that uses the current. The arduino can be assumed to consume no current on an input pin and its sole purpose is to detect the voltage on the pin, the voltage is a product of what the rest of the circuit is doing - back to basic electrical theory.....

Ok I'm pretty sure I've got it now. :P ::) Thanks for your extra explanations. Yes, it seems the answer is quite complicated. Sorry deSilva; I did try to look at your schematics but I only slightly understand them or the components you were talking about. I'll learn that eventually I guess.

Sorry for your troubles; I just thought this was important for learning how even simple things work. Thanks!