5V To GND when button pushed?

Hey there!

When the button is pressed, is there not going to be an overload of current going into pin 2? In my understanding, there is no resistance from 5V to Pin 2 (apart from the wire's resistance.)

Thank you in advance.

The input resistance of an ‘input’ is ~100Meg (100,000,000) ohms.

There will be negligible input current flow.

The inputs are essentially the gate of a MOSFET, so only leakage current would flow.

larryd:
The input resistance of an ‘input’ is ~100Meg (100,000,000) ohms.

There will be negligible input current flow.

Ahhhhhh okay that makes sense. Does the input pin measure voltage before and after this resistor? (Just wondering how the digital pin actually reads voltage levels.)

No.
A pin can be connected to 5volt or ground, or anything in between, and will take NO current.
The only current flowing is from 5volt through a closed switch, through the pull down resistor, to GND.
<= 1.5volt (0.3VCC) on a digital pin is a LOW, and >=3volt (0.6VCC) is a HIGH.

There is an easier way to connect a button to the Arduino.
Just connect the button between pin and ground, WITHOUT resistor.
Then declare the pin in setup with internal pull up.

pinMode(switchPin, INPUT_PULLUP); // switch between pin and ground

Now an open switch is read HIGH, and a closed switch is read LOW.
Leo…

As mentioned, an input is “essentially the gate of a MOSFET”.

The MOSFET detects the presents of a HIGH/LOW situation.

Excessive current could flow if the pin mode accidentally gets set to output and the switch is closed when the output is low. But, as shown, no problem, so long as the pins input mode is left as is in the default mode of input. This can happen in any connection scheme so always be aware of how you setup your pins with pinMode();

You can also simplify by removing the resistor and moving the wire that is presently on the +5v pin to GND and turning on the internal pull-up resistor with:

pinMode(2, INPUT_PULLUP);

Just note that you get an inverted result, that is you get a FALSE result when the switch is closed. You can easily invert this with the ! operator:

pin = ! digitalRead(2);

Wawa:
No.
A pin can be connected to 5volt or ground, or anything in between, and will take NO current.
The only current flowing is from 5volt through a closed switch, through the pull down resistor, to GND.

There is an easier way to connect a button to the Arduino.
Just connect the button between pin and ground, WITHOUT resistor.
Then declare the pin in setup with internal pull up.

pinMode(switchPin, INPUT_PULLUP); // switch between pin and ground

Now an open switch is read HIGH, and a closed switch is read LOW.
Leo..

Thank you for your response!

Wawa:
A pin can be connected to 5volt or ground, or anything in between, and will take NO current.

Does the pin not even take a tiny amount of current? How does it read what voltage is present?

No overload. If the resistor is any value from about 1000 ohms to about 50000 ohms and the mode of pin 2 is set to INPUT, this will work just fine.

Of course, if you would work with inverted logic and set the mode of pin 2 to INPUT_PULLUP, the resistor and perhaps some wires would be unnecessary.

The switch would then be wired from pin 2 to ground (GND).

Bonus: This would work regardless of whether your Arduino is 5.0 volts or 3.3 volts.

I think is time to do some reading on basic electronics.

After you master these basics, progress to the BJT transistor then to MOSFETs.

Lots of good stuff on youtube.

Also, if you are really interested here is your next assignment:
Arduino links of interest.

How to use this forum:
https://forum.arduino.cc/index.php?topic=149014.0

Listing of downloadable 'Arduino PDFs' :
Either Google >>>- - - - > arduino filetype: pdf
Or
https://www.google.ca/search?q=arduino+filetype%3A+pdf&rlz=1C9BKJA_enCA739CA739&oq=arduino+filetype%3A+pdf&aqs=chrome..69i57j69i65.1385j0j7&hl=en-US&sourceid=chrome-mobile&ie=UTF-8

Listing of downloadable 'C++ PDFs' :
Either Google >>>- - - - > C++ filetype: pdf
Or
https://www.google.ca/search?q=c%2B%2B+filetype%3A+pdf&rlz=1C9BKJA_enCA739CA739&oq=c%2B%2B+filetype%3A+pdf&aqs=chrome..69i57.22790j0j7&hl=en-US&sourceid=chrome-mobile&ie=UTF-8

Arduino cheat sheet:

Watch these:
Arduino programming syntax:

Arduino arithmetic operators:

Arduino control flow:

Arduino data types:

Why MOSFET gate resistors:

Some things to read

Reading a schematic:
https://learn.sparkfun.com/tutorials/how-to-read-a-schematic

Language Reference:
https://www.arduino.cc/en/Reference/HomePage

Foundations:

How and Why to avoid delay():
http://playground.arduino.cc/Code/AvoidDelay

Demonstration code for several things at the same time.
http://forum.arduino.cc/index.php?topic=223286.0

Multitasking:
Part 1:

Part 2:

Part 3:

Micro Controllers:

Useful links:

Arduino programming traps, tips and style guide:
http://www.gammon.com.au/forum/?id=12153

Call for useful programming discussions

Jeremy Blume:

Arduino products:
https://www.arduino.cc/en/Main/Products

Motors/MOSFETs
http://www.gammon.com.au/motors

Switches:
http://www.gammon.com.au/forum/?id=11955

Share tips you have come across, 500+ posts:

Images from above:
https://www.google.com/search?q=“Share+tips+you+have”+larryD+site:https://forum.arduino.cc&prmd=nmvi&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiJw-zu68ncAhXPGTQIHWCDCNwQ_AUIFCgE&biw=1024&bih=653

Debug discussion:

A pin set to INPUT uses such a tiny bit of current that you would have a very difficult time trying to measure it.

BambooPanda:
Does the pin not even take a tiny amount of current? How does it read what voltage is present?

The only pin current is a tiny bit of leakage current in the pin protection diodes and the mosfets.
So low that it can be ignored.
Leo..

Okay! Thanks a lot everyone

I can highly recommend Michael Margolis' "Arduino Cookbook" (O'Reilly). He explains how to use common sensors, display devices and input/output methods as well as the components and circuits needed for proper operation along with code examples and full explanations! [I do not know him.] This book should help any newcomer to get started quickly!

herbschwarz:
I can highly recommend Michael Margolis' "Arduino Cookbook" (O'Reilly). He explains how to use common sensors, display devices and input/output methods as well as the components and circuits needed for proper operation along with code examples and full explanations! [I do not know him.] This book should help any newcomer to get started quickly!

Thank you very much! Checking it out right now! I think my main problems have just been that I don't know the Arduino hardware sufficiently - I'll focus on that in the book/on YT :slight_smile:

BambooPanda:
Does the input pin measure voltage before and after this resistor? (Just wondering how the digital pin actually reads voltage levels.)

The pin responds to the voltage of the pin w.r.t. ground and Vcc. The input transistors are a pair of complementary nMOS and pMOS FETs which form an inverter circuit. The gates are connected to the pin,
but the gate is isolated from the rest of the device by a few dozen atoms thick layer of silicon dioxide.

The electric field across the oxide attracts charged particles in the FET's channel to form (or not form)
a conducting layer.

Silicon dioxide is an extremely good insulator so no DC current flows from the pin itself (well you'd have to pay quite a lot of money for the test gear capable of measuring that small a current, usually in the femtoamp or
picoamp range).

This low current is the reason unconnected pins can have their voltage floating around in response to nearby
circuitry.

The extreme thinness of the gate oxide is what allows a few volts to control things - 1V across 20nm of oxide is equivalent to 50kV across 1mm of oxide - that's an immense electric field strength! Hence the name "field effect transistor"