Electronic – arduino – Do I need to use a resistor with a microswitch to limit current for an Arduino Uno

arduinocurrentresistorsswitches

I'm using an Arduino Uno to control a small robot and I'm starting to add micro-switches as bump-sensors. I know that when I'm creating a circuit with LEDs I need to use resistors to limit the current so I don't mess up the Arduino, but do I need to do the same with the micro-switches? If so, how do I calculate the necessary resistance?

If it makes a difference, my micro-switch is Pololu #1405, Snap-Action Switch with 15.6mm Bump Lever 3-pin, SPDT, 5A. The Arduino outputs 5V and has a maximum of 40mA.

EDIT: I've done some more research and I found a page that seems to describe exactly what I want to do (http://arduino.cc/en/tutorial/button), don't know how I missed it before. So if I'm understanding the situation correctly, the only resistor I need is the pull-up/down one between the switch and ground, but none between the switch and the pin that's reading the switch.

Best Answer

You do not need a resistor, as long as you set up the pin to be input. The current protection resistors are necessary only in cases where the Arduino pin is used as a current source, i.e. output. If the pin is used as an output pin, you may need a current-limiting resistor, depending on what is connected to the pin. Usually we don't connect switches to outputs though (except for unusual cases when the switches need power, switches are actually circuits, etc).

For an input pin you may want a pull-up or a pull-down resistor. However, all AVR chips have built-in pull-ups. After you configured the pin as an input pin, you activate the pull-up resistor by digitalWrite(HIGH) to that pin, or, as @mpflaga points out, on the newer Arduino toolchain, you can set the input mode and pullup using pinMode(in_pin, INPUT_PULLUP); line. See here for more information on pull-up/pull-down resistors.

If you want a discrete pull-up resistor (i.e. not use the built-in one, though I don't know why you would do that) the circuit would look as follows:

schematic

simulate this circuit – Schematic created using CircuitLab

The pin will read high when the switch isn't pressed, and low when it is.

Related Topic