Go Down

Topic: Input Question (Read 231 times) previous topic - next topic

Brian60

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?

septillion

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.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

slipstick

#2
Apr 17, 2018, 12:17 pm Last Edit: Apr 17, 2018, 12:22 pm by slipstick
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

Brian60

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?

Grumpy_Mike

Quote
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.


Brian60

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

Go Up