qq push buttons without resistors?

Hi, I'm new to Arduino and my first project is a binary LED clock. Now I want to hock two buttons to the I/O Pins to set the time. The tutorial to buttons connects the 5V directly to the I/O Pin. Just a button in between without any resistor. Is that really safe? Won't that damage the board in the long run?

The chip itself has a "Pull-up resistor" built into each pin, which can be activated in software.

But after you activate it, the button needs to be connected to ground, not 5v. And instead of reading when the pin goes HIGH, you'll want to check when it goes LOW.

To enable the Pull-up Resistor internally, you just need to do 2 simple things in your setup, first, make the buttonPin an input (like normal), and then use digitalWrite(buttonPin, HIGH); to enable the resistor.

Lol it's late, not sure I explained that well, but for example, this will turn on an LED for as long as you push the button:

int buttonPin = 10;  // change to whatever you want
int ledPin = 13; // just using for example
void setup()
{
     pinMode(ledPin, OUTPUT);     // LED as output
     pinMode(buttonPin, INPUT);    // button as input
     digitalWrite(buttonPin, HIGH); // turns on pull-up resistor after input

}

void loop()
{

     while(digitalRead(buttonPin) == LOW)   // when pin goes LOW
         {
             digitalWrite(ledPin, HIGH);           // turn on LED
          }
    digitalWrite(ledPin, LOW);        // well, turns led off!

}

One side of the button goes to your buttonPin, and the other side goes directly to GROUND. (Not 5v) That'll be safe for long run :)

Many excuses - but I could not refrain... This loop will also work

void loop() { digitalWrite(ledPin, ! digitalRead(buttonPin)); }

Just a button in between without any resistor. Is that really safe? Won't that damage the board in the long run?

Not really a matter of safety. A digital input pin is a very high input resistance and can only be damaged by applying voltages over +5vdc or any negitive voltage. The problem with wiring a +5vdc switched voltage to a input pin is that the pin will read noise and invalid logic levels when floating when the switch is not being pushed.

A external pull-down resistor for the pin would work fine without modifying the code, or as already posted using the pin's internal pull-up would work fine if you modify the code for a active low switch input.

Lefty

... only be damaged by applying voltages over +5vdc or any negitive voltage.

This is a general misconception found in many places. Chip designers have done their best that CMOS circuits will no longer suffer when touched by a human finger loaded with 10 kilovolts.

The compensating current flows through protection diodes into the power supply (or into ground when negative).

However those diodes have now become the weak spot. they are genarlly rated for some 100 uA and would definitely suffer above 1mA. The designer generally uses resistors to reduce that current, not to reduce (harmless) voltage.

A series resistor would be more "safe" in case 5V isn't really 5V but gets shorted to some other external voltage, like 12V. In this case the series resistor will limit the current going into the pin and might save your AVR from an untimely death.

Since it is a high-impedance input you can add a fair amount of resistance (1k or so) and not really change the behavior much. Just make sure that any pullup/down resistors are at least 10x this much (as a guideline) so you still get nice clean high and low voltages (the series resistor will form a voltage divider with the pullup/down).

And as others have mentioned, connecting the switch to GND and using the built-in pullup is more common.

-- Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

This is a general misconception found in many places.

If you think this is a misconception then go ahead and try it, it is the most reliable way I have found of damaging a chip. just a volt or two greater than the supply is often enough.

No. Please, please read and understand what I have written (and what is in all basic textbooks about current and voltage). I (and others) have often connected 12 and 24 volts signals to inputs of 5 volt devices, using a 220k resistor.

The drawback is the low-pass chracteristic of this approach considering the 5pF input capacity of input pin and PCB, which will filter signals above 100kHz, which however can even be a good thing in many cases. Note that the analog input has a much lower input impedance than the digital ports, and you should not use a serial 220 k there...

Voltage deviders can be designed to a much lower impedance, at the cost of (unneeded) current spoil in the mA scope. This however is neccessary above the 100kHz level, which means I2C, high speed RS232, e.t.c. where impedances around 2k2 are recommandable.

I (and others) have often connected 12 and 24 volts signals to inputs of 5 volt devices, using a 220k resistor.

No one is disputing your statement that by adding an external series resistor one can apply higher then Vcc to a Arduino I/O pin, heck I've seen in the past a PIC application note where they wired 120vac to a input pin (with a rather large series resistor!) to utilize the 60hz for a timing reference.

What we are saying to the OP was that wiring a higher then Vcc voltage directly to a I/O pin (without any external current limiting resistance) will take out the I/O pin, plain and simple.

What was it you though we didn't understand again?

Lefty

There is no "we" :-) Each poster here has it's own profile...

My personal problem for 50 years is that I would like people to UNDERSTAND things, and not to just follow "rules-of-thumb". Sometimes I overdo....

Thank you very much! :) Now I can go on with my code. THANKS