What if I use 230 ohm resistor with 5V input to Ground?

groundfungus:
Or ditch the pull down and wire the switch from ground to the input and enable the internal pullup.

pinMode(pin, INPUT_PULLUP);

The switch will read LOW when pushed.

What are the drawbacks of this method - it will consume more energy I guess?

Arduino GPIO pins have two modes (INPUT or OUTPUT).
When configured as an INPUT, the pin becomes a high impedance (100 Mohms) input)
If you are sensing a push button, the pin MUST be configured as an INPUT, therefore
you can short it directly to 5V or GND without using any power to speak of . What you CAN'T do is connect the push button IN BETWEEN 5V and GND and then push the button because you will short your 5V power supply. Thus, ANY DISCUSSION OF POWER CONSUMPTION OF AN I/O PIN CONFIGURED AS AN INPUT is completely irrelevant and non valid. Such a discussion would only be appropriate for a pin configured as an OUTPUT .

Do you understand the significance of a input impedance of 100 Mohms ?

If you are discussing the power consumption of a 10k ohm pullup resistor, it depends on WHAT you connect that input pin to. By itself , an INPUT pin with a 10k pullup is part of a voltage divider with 10k in the upper position and 100 Mohms in the lower position. Any discussion of input pin power consumption would have to be based on the circuit that you connect to that input pin.

"What are the drawbacks of this method - it will consume more energy I guess?"

Depending on how often the button is pressed, and how long it is held down, is the processor run 24/7 ?

With the natural order of things, I think you would be right. But I still suggest getting a varity pack of resistors.

What are the drawbacks of this method - it will consume more energy I guess?

Less power... IIRC, the internal pull-up is 20k-50k Ohms.

Note that power is only consumed when the switch is on. (That's true with pull-ups or pull-downs.)

From Ohm's Law 5V/250 Ohms is 20mA, and that's about the same current as an LED. No big deal, but pull-ups or pull-downs are usually in the range of 1K to 10K.

As far as energy, power is calculated as Voltage x Current, so 250 Ohms is 1/10th of a Watt.

it will consume more energy I guess?"

How long do you plan to hold the button down ? (effectively connecting a 230 ohm resistor across 5V and GND.

I = V/R = 5V/230 ohms = 0.0217 A (21.7 mA)
P = I x V = 0.0217 A x 5V = 0.1086 W = 109 mW (while the button is held down)

Can you spare 100 mW ? (for 1 second ?)

For the full lowdown on this question read this:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

"If you are sensing a push button, the pin MUST be configured as an INPUT, therefore
you can short it directly to 5V or GND "

I beg to differ:
If your switch will short it directly to 5V, then the other side of the coin is,
" short it to GND, leave it floating, or use a small pull down resistor".

The default being shorted to ground, nor leave it floating will not be a functional option.
So, use a small pull down resistor is the only viable option.
I could be mistaken tho.

raschemmel:
Arduino GPIO pins have two modes (INPUT or OUTPUT).
When configured as an INPUT, the pin becomes a high impedance (100 Mohms) input)
If you are sensing a push button, the pin MUST be configured as an INPUT, therefore
you can short it directly to 5V or GND without using any power to speak of . What you CAN'T do is connect the push button IN BETWEEN 5V and GND and then push the button because you will short your 5V power supply. Thus, ANY DISCUSSION OF POWER CONSUMPTION OF AN I/O PIN CONFIGURED AS AN INPUT is completely irrelevant and non valid. Such a discussion would only be appropriate for a pin configured as an OUTPUT .

Do you understand the significance of a input impedance of 100 Mohms ?

If you are discussing the power consumption of a 10k ohm pullup resistor, it depends on WHAT you connect that input pin to. By itself , an INPUT pin with a 10k pullup is part of a voltage divider with 10k in the upper position and 100 Mohms in the lower position. Any discussion of input pin power consumption would have to be based on the circuit that you connect to that input pin.

So what are you saying is that I can directly connect the 5V through switch into the Input pin because it have high resistance?

But why is the example linked here so complicated then?

Also what will happen if I press the button before the 'setup' function executes or if I mistakenly don't configure the pin as INPUT?

bsld:
Also what will happen if I press the button before the 'setup' function executes or if I mistakenly don't configure the pin as INPUT?

Arduino pins are defaulted to inputs, which is a safe state.

Consider wiring two inputs to each other. Nothing happens as both expect but don't receive.
Consider wiring two outputs to each other. The pins are now trying to source current into each other which is bad.

Default inputs is safe.

Also if your pushing the button prior to the setup function, the pin will sink current, but nothing will happen. The MCU is safe and will wait for your code to tell it to do something with it's current pin state.

This explains further on pins and why pull-ups/pull-downs are necessary.

The default being shorted to ground, nor leave it floating will not be a functional option.
So, use a small pull down resistor is the only viable option.
I could be mistaken tho.

Think about it.
The input pin represents a 100 Mohm resistor to ground.
The pullup /pulldown resistor is out of the circuit UNLESS the button is pressed.
This means the pullup/pulldown resistors are not conducting any current unless you press the button.

CASE -A (230 ohm pullUP resistor)
button open => no current
button pressed => (230 ohm resistor across 5V and GND => 21mA/0.1W consumed

or use a small pull down resistor".

I think you mean use a LARGE pulldown resistor. (230 ohm is already way too SMALL)
A pullup/pulldown resistor should be 10k >= optimum <= 50k

230 is a value NO ONE with any electronics experience would ever consider using unless it was LITERALLY the ONLY OTHER resistor they had available. PERIOD

CASE-B(230 pullDOWN resistor)
button open => no current
button pressed => (230 ohm resistor across 5V and GND => 21mA/0.1W consumed

Consider wiring two outputs to each other. The pins are now trying to source current into each other which is bad.

This topic is about an INPUT pin. The above comment is not relevant to this topic.

Also what will happen if I press the button before the 'setup' function executes or if I mistakenly don't configure the pin as INPUT?

That's EXACTLY WHY no one would ever consider using such a low value as a pullup/pulldown resistor.

raschemmel:
Think about it.
The input pin represents a 100 Mohm resistor to ground.
The pullup /pulldown resistor is out of the circuit UNLESS the button is pressed.
This means the pullup/pulldown resistors are not conducting any current unless you press the button.

CASE -A (230 ohm pullUP resistor)
button open => no current
button pressed => (230 ohm resistor across 5V and GND => 21mA/0.1W consumed

I think you mean use a LARGE pulldown resistor. (230 ohm is already way too SMALL)
A pullup/pulldown resistor should be 10k >= optimum <= 50k

230 is a value NO ONE with any electronics experience would ever consider using unless it was LITERALLY the ONLY OTHER resistor they had available. PERIOD

CASE-B(230 pullDOWN resistor)
button open => no current
button pressed => (230 ohm resistor across 5V and GND => 21mA/0.1W consumed

This topic is about an INPUT pin. The above comment is not relevant to this topic.

That's EXACTLY WHY no one would ever consider using such a low value as a pullup/pulldown resistor.

What about my first question - can I directly connect the 5V through switch into the Input pin and will it work that way?

Because you've said that the input pin have it's own resistors.

Assuming you haven't enabled the internal pull-up resistors? It will work, but not well. They have very high impedance as inputs but that also means they are very sensitive. So if you leave a pin "floating" (not connected to anything when the button isn't pressed) it will give off random values. Often messing with your program.

Because you've said that the input pin have it's own resistors.

That isn't exactly what I said. I said the input has an equivilent input impedance of 100 Mohms. If you use internal pullups they are 50k ohms.
With an input impedance of 100 Mohms, 5V connected directly to the pin would draw

I= V/R = 5V/100 Mohms = 0.00000005 A (50 nA)

Can you handle that ?

Assuming you haven't enabled the internal pull-up resistors? It will work, but not well. They have very high impedance as inputs but that also means they are very sensitive. So if you leave a pin "floating" (not connected to anything when the button isn't pressed) it will give off random values. Often messing with your program.

A floating pin will be read as a "0" (LOW).
An input should never be left floating. A pullup or pulldown resistor (10k or larger) should be used.

I beg to differ:
"Think about it.
The input pin represents a 100 Mohm resistor to ground.
The pullup /pulldown resistor is out of the circuit UNLESS the button is pressed.
This means the pullup/pulldown resistors are not conducting any current unless you press the button.
"

The input pin represents a 100 Mohm resistance, not necessarily to ground, but to input signals. If this ls left floating, there can be triggers above and below the threshold to represent a high, and a low signal.

The pullup/pull down resistor is only out of the circuit when the button is pressed.

The pullup/pulldown resistors are providing the voltage level only while the button is not pressed. Then the button overrides them once pressed.
As I see it.

The input pin represents a 100 Mohm resistance, not necessarily to ground, but to input signals.

You're misinformed.

The definition of input impedance is the resistance seen to GND . The resistance seen from the input pin to ground is about 100 Mohms.

@raschemmel, then that would mean that a digital input that is not connected to anything would always read a low? Not what I had understood before. Is that right?

then that would mean that a digital input that is not connected to anything would always read a low?

No that is not right. You have misunderstood what raschemmel said. A floating input can read anything due to pickup.

@raschemmel, then that would mean that a digital input that is not connected to anything would always read a low?

There was a discussion about this in another thread about a year ago so out of curiousity
so I wrote a loop to read some floating inputs and print the values to the serial port and it was always low . That doesn't mean that would always be the case but that's what I saw. I think you have to keep in mind that 100 Mohms is not your typical pulldown resistor.

There seems to be a lot of misunderstanding going on here. I am going to back away for now, and check back when the smoke clears. Good luck.

There is no misunderstanding.
I have been working in electronics for over 30 yrs and Mike has over 40 yrs experience. The definition of input impedance hasn't changed and it's still a bad idea to leave uC inputs floating. If there is any misunderstanding it is at your end.

To calculate the input impedance, short the input terminals together and reduce the circuit by determining the equivalent circuit with only one component.

In this case, the one component is a 100 Mohm resistor. (ZL (from the pin to GND))

Input Impedance

Is it a bad idea to leave micro-controller inputs floating ?

Problem:
Leaving a pin configured as an input floating is dangerous simply because you cannot be sure of the state of the pin. Like you mentioned, because of your circuit, your pin was sometimes LOW or sometimes in no-man's land or could sometimes go to HIGH.

Result:
Essentially, the floating input WILL definitely cause erratic chip operation or unpredictable behaviour. I have noticed some chips froze by simply moving my hand closer to the board (I wasn't wearing a ESD wrist band) or some would have different startup behaviour each time the board would powerup.

Why:
This happens simply because if there is external noise on that pin, the pin would oscillate, which would drain power as CMOS logic gates drain power when they switch states.

Solution:
Most micros nowdays have internal pullups as well, so that could prevent this behaviour from occuring. Another option would be to configure the pin as an output so it does not affect the internals.