i need info about current and a push button use

hello guys, i created this topic just for protection and to make sure about my knowledge and to correct if i am mistaken so my question is : i want to put push buttons and connect them to arduino pins, so the buttons are of course a 10k resistor that will be connected to GND and to one of the 2 pins of button and same button to arduino and the other pin of the button will be connected to +5V the +5V is from output of a voltage regulator that is connected to a 12V - 3AH lead acid battery so i need to make sure about the current that will be going threw the push button and into the arduino pins is that safe for arduino pins ? as we know 40mA is the maximum current that a pin can take

You already have a 10k resistor between your 5V and the Arduino pin, its pretty safe even from overvoltage as a result.

You know external resistors are unnecessary if the internal pull-up resistors are enabled?

  pinMode (pin, INPUT_PULLUP) ;

Will configure the pin with an (approx) 30k pull-up, so you only need a button from pin to ground.

MarkT: You already have a 10k resistor between your 5V and the Arduino pin, its pretty safe even from overvoltage as a result.

You know external resistors are unnecessary if the internal pull-up resistors are enabled?

  pinMode (pin, INPUT_PULLUP) ;

Will configure the pin with an (approx) 30k pull-up, so you only need a button from pin to ground.

aha but i don't know how to work with it in a script with debouncing and stuff but the 10k is to pull down the button, so how is it between the arduino pin and button ?!

The best advice I can give here is:

A) Stop using pull downs B) Using "internal" pullups instead of pulldowns only mean that when a button is pressed, a pin is LOW instead of HIGH. It's held in a HIGH state when the button is not pressed. And it saves you having to provide external resistors. (No, there are no internal "pull down" options)

After that, it's just a simple matter of reversing the pin state logic.

Also... Pins in an input state are very high impedance and therefore draw "negligible" current from a power supply. The pullup resistor will draw more current than the pin itself. Use ohms law to figure out what current will be drawn from your supply with VOLTS = 5V and RESISTANCE = (22K to 30K) OHMS.

I've been doing this to debounce/space out in time my button presses/held down buttons:

// is the button pressed, and has it been 1/3 of a second since the last press?

if ( (digitalRead(button1) == LOW) && (millis() - button1PressTime)>=333) ){ 

button1PressTime = millis(); // save the time of the press for next comparison

// do action for a button press
}

After that, it's just a simple matter of reversing the pin state logic.

I'm confused about that. According to the documentation, if I use:

pinMode(button1, INPUT);
digitalWrite(button1, HIGH);

Then that turns on the internal pullup resistor. But so does this:

pinMode(button1, INPUT_PULLUP);

However, this page: http://arduino.cc/en/Reference/Constants says that:

Pins Configured as INPUT_PULLUP

The Atmega chip on the Arduino has internal pull-up resistors (resistors that connect to power internally) that you can access. If you prefer to use these instead of external pull-down resistors, you can use the INPUT_PULLUP argument in pinMode(). This effectively inverts the behavior, where HIGH means the sensor is off, and LOW means the sensor is on. See the Input Pullup Serial tutorial for an example of this in use.

I'm unsure what they mean. When they say "inverts the behavior", are they only talking about the fact that the switch is now wired to ground, or does setting the pull-up resistors in this way cause it to behave any differently?

I think they mean "switch" not "sensor". And the technical term is active-low, which I think is more explanatory - your code has to realise the the input is LOW when the switch is pressed, rather than HIGH if it were wired to Vdd and an external pull-down was employed.

OK, so a switch press is still a LOW, digitalRead(button) still returns a 0 for pressed switch and a 1 for an unpressed switch. It seems like the only difference between those two methods is one less line of code to type.

It seems like the only difference between those two methods is one less line of code to type.

And, one less resistor to solder.

And, one less resistor to solder.

No, because both methods turn on the internal Pull Up resistor.

One method used an

external pull down resistor

,
and the second method used the internal Pull Up resistor. ← the preferred method.

Not what I was talking about, which was what you quoted. Both used the internal pull-up resistor, active low. I have my question answered about the confusing description about "inverted", now I'm just wondering why there are two methods to activate the internal pull-up resistor, and if there is any difference between the two methods.

pinMode(button1, INPUT);
digitalWrite(button1, HIGH);
pinMode(button1, INPUT_PULLUP);

polymorph: Not what I was talking about, which was what you quoted. Both used the internal pull-up resistor, active low. I have my question answered about the confusing description about "inverted", now I'm just wondering why there are two methods to activate the internal pull-up resistor, and if there is any difference between the two methods.

pinMode(button1, INPUT);
digitalWrite(button1, HIGH);
pinMode(button1, INPUT_PULLUP);

no, AFAIK ( from what I've read weeks ago ;) ) , there is no difference. The second method was not implemented in the first versions of the arduino IDE , that's all.

Edit : found in the "changes" page http://arduino.cc/en/Reference/Changes

Changes in Arduino 1.0.1 Added INPUT_PULLUP argument to pinMode() function. The INPUT mode now explicitly disables the pullup resistors.

Thanks!