Electronic – arduino – How to bring a digital input pin to high state

arduinodigital-logicmbedmicrocontroller

This sounds really very easy, but I'm afraid to try it because I don't want to fry my microcontroller.

I'll use an Arduino for an example, but it should be the same for all microcontrollers.

Anyway, say you have a switch and you want for when you press the switch to bring a digital pin to high(1) and when it's not pressed, to low(0). Would this require resistors? Or would you just straight wire from 3.3v into the input pin?

Or to further simplify what I'm asking. If for some reason you wanted a certain digital input pin to always be high, would you just stick a wire from 3.3v into the digital pin? Or would you need a resistor somewhere in there?

Best Answer

To get at your question about if you can plug power directly to the pin with no resistor and have it always be high... yes, that does work.

When you have your microcontroller set to input mode you can treat the pin like there is a very large resistor inside. So using ohms law, V/R=I with V=3.3 and R=very large, lets say 10megohm gives you a current of 0.33 micro amps. The inputs are designed to act like such a high impedance so that it has a very small effect on anything externally.