Using a LED on button input

I want to use LEDs on inputs i will be using for buttons and sensors, to make it easier to troubleshoot without setting up serial monitor. What i mean is using a LED + resistor in parallel on the input pin. Other than the small power draw, can i run into other problems? Like getting different readings? I plan to use it mainly for digitalRead but i'm curious about analog as well.

It depends on the ability of each switch or sensor to supply enough current to both the LED and the input circuit. Every sensor is different. It's better to develop individual test sketches for each type of sensor and switch to verify the operation and connection.

Should work with most push/pull outputs.
May not work at all with open collector outputs.
Is likely to mess with analog outputs.

aarg:
It depends on the ability of each switch or sensor to supply enough current to both the LED and the input circuit. Every sensor is different. It's better to develop individual test sketches for each type of sensor and switch to verify the operation and connection.

I'm still a newbie by all means but i am pretty convinced arduino is the one supplying the current here. Or, are you talking about the resistivity of the wiring+sensor ensamble? I don't understand, especially given a straight-forward situation like using a button.

An input pin does NOT supply any current.

This will not work at all with a regular button assembly as there is no current source for the LED.

wvmarle:
An input pin does NOT supply any current.

This will not work at all with a regular button assembly as there is no current source for the LED.

I get it, it will probably work with sensors, it won't work with buttons.

But it seems i still don't understand how inputs work. I mean, some current has to pass from that pin to the ground for arduino to read it. What am i missing here?

petronel:
I get it, it will probably work with sensors, it won't work with buttons.

But it seems i still don't understand how inputs work. I mean, some current has to pass from that pin to the ground for arduino to read it. What am i missing here?

The current in/out of an input pin is measured in nano-amps. But the pull up resistor that you need with a switch draws current to ground or Vcc - you can also add a resistor and LED in parallel with that and not affect the input in any way as long as the switch can handle the LED current.

aarg:
The current in/out of an input pin is measured in nano-amps. But the pull up resistor that you need with a switch draws current to ground or Vcc - you can also add a resistor and LED in parallel with that and not affect the input in any way as long as the switch can handle the LED current.

Sorry for being so thick-headed, i still don't understand what you mean by "as long as the switch can handle the LED current", i mean most switches are rated at least a few amps which is way more than arduino can output.

This could work with a switch, but a sensor would have to be able to supply the LED current without damage.
Digital input only, not analog.
ledIn.png

ledIn.png

Indeed, in case of a switch it would work, but the power is not supplied by the Arduino but by your 5V power supply.

JCA34F:
This could work with a switch, but a sensor would have to be able to supply the LED current without damage.
Digital input only, not analog.
ledIn.png

However this is not the advisable way to wire a switch. :astonished:

It should be the "other way up". The switch should connect between the input pin and ground, the LED and series resistor connect to 5 V and the pull-up resistor is provided by setting pinMode for that pin to INPUT_PULLUP so you do not need one added.

Exactly the same arrangement will then work for an open-collector sensor output; this is actually how most digital logic has been arranged and has the advantage that you do not need to run the 5 V power out to switches with the danger, however minor, of it being shorted to ground.

@Paul__B:
I agree 100%, but ask 1000 noobs to wire a switch and see how 999 of them do it (+V to switch to input pin). Seems they just can't "get" low side switching. :slight_smile:

Thanks a lot for the help guys, i tested just now both with external pull-down and internal pull-up and they work fine. I'll stick with the second option for convenience.

JCA34F:
Seems they just can't "get" low side switching. :slight_smile:

Especially if they keep getting offered the opposite! :roll_eyes: