Input Question

This might be a very basic question but I can't seem to find an answer in the getting started section.

If you take the bog standard turn on/off an led sketch and then add the switch as is illustrated, so that say led is on pin 10 (output) and a switch to pin 8 as an input. You pass 5v to pin 8 from the onboard supply to send it high or low and turn on or off the led on 10.

What I would like to know is can this 5volts (or less) be from an outside source? Say I had a 5 volt battery (negative connected to arduino ground) and a switch connected to pin 10 instead of the onboard 5v would this work or would I see smoke emanate from the arduino?

That will work IF you have a pull down resistor connected.

But most of the time it's easier to connect the input to GND to activate it and use the internal pull up resistor.

Brian60:
What I would like to know is can this 5volts (or less) be from an outside source? Say I had a 5 volt battery (negative connected to arduino ground) and a switch connected to pin 10 instead of the onboard 5v would this work or would I see smoke emanate from the arduino?

Isn't pin 10 the output pin with the LED connected to it? You can't do input and output on the same pin. Or did you mean something else?

I think the problem is in your basic description. You don't pass 5V from the input pin to the output pin to light the LED. They are completely separate. You read the value of the input pin (which may be high or low) and then in the code you make a decision based on that value whether to set the output pin high (5V) or low (0V) to light the LED or not.

Steve

slipstick:
Isn't pin 10 the output pin with the LED connected to it? You can't do input and output on the same pin. Or did you mean something else?

I think the problem is in your basic description. You don't pass 5V from the input pin to the output pin to light the LED. They are completely separate. You read the value of the input pin (which may be high or low) and then in the code you make a decision based on that value whether to set the output pin high (5V) or low (0V) to light the LED or not.

Steve

Yep, thats what I meant to describe - newby for ya! I only mentioned the output as pin 10, it could be any of the pins really. I had read on an independent site that you risked damaging the board if you used an outside voltage to do the switching, but I can't work out why, after all there is no difference reading 5v from the board to a pin or 5v from off the board . Or am I wrong?

read on an independent site that you risked damaging the board if you used an outside voltage to do the switching,

You probably misunderstood that. It is when you apply a voltage outside the voltages that are powering the board.

Thank you all for the useful answers, I shall have a go at the connection and see what happens.