I don't understand the LED thing

Hi, all./. I am brand-new to Arduino, and have not even gotten mine yet - it comes in the mail tomorrow. I am building a 5-button MIDI switch for a piece of rack-mount music gear. I have mechanical aptitude enough, to have figured out how to wire the switches and MIDI port to do what I want, and I have loads of code to make the switches do different things. That is not my problem here.

My problem is, I can find little reference to how to wire up LEDs specifically. Like, no basic schematics seem to exist. I have two pole momentary footswitches and when I click a switch to put the switch in 'on' position, I want the LED to go on... when I click it to the 'off' position, I want the LED to go off. Simple as that; just an indicator LED.

Do I wire the LEDs to separate digital pins, or can I run them to the same ones I am using for the switches? Is there code involved in either instance? Can I be pointed to appropriate resources?

Thanks for bearing with me.

AMSchmitt79:
My problem is, I can find little reference to how to wire up LEDs specifically. Like, no basic schematics seem to exist.

Here you go:
https://www.arduino.cc/en/Tutorial/Blink


Or if you prefer Fritzing:

Wire the switch between input pin and ground, and the LED (with current limiting resistor) between pin and 5volt.
Then enable internal pull up on the pin with pinMode in setup.

pinMode (switchPin, INPUT_PULLUP);

Now the pin digitalReads LOW and the LED lights up when the switch is closed.
Leo..

@larryd
The diagram doesn't show how a switch and indicator LED can be connected to a single input pin.
Leo..

I sould have said the schematic shows to have LED and switch on a separate pin.

However, if the OP needs both on the same pin, see this link:
https://forum.arduino.cc/index.php?topic=439838.0

Also covered here:
Post #334
https://forum.arduino.cc/index.php?topic=445951.msg3336467#msg3336467

And #391:
https://forum.arduino.cc/index.php?topic=445951.msg3430326#msg3430326

Thank you guys! I've got what I need. You are the best!

Why the resistor in series with the switch.
Not needed, and it will give a less defined LOW for a digital input pin.
Just the resistor in series with the LED will do (with internal pull up on the pin).

Unless you want added LED burnout info by using analogue pins.
Leo..

That resistor is the "idiot-proofing" in case you have set the output HIGH to turn off the LED and then press the button. Since you are using a pin as both an input and an output (in some manner), there is a risk of a mistake in the code. Obviously if you knew that your code was 100% reliable and only ever used INPUT_PULLUP or output LOW (prior to setting OUTPUT), it would not be required. :roll_eyes:

Ahh, double-use of the pin as input and output to light the LED when the switch is not pushed makes sense.
But it seems OP didn't ask for that.
Leo..

Wawa:
Why the resistor in series with the switch.
Not needed, and it will give a less defined LOW for a digital input pin.
Just the resistor in series with the LED will do (with internal pull up on the pin).

Unless you want added LED burnout info by using analogue pins.
Leo..

If this is to me.
When the Arduino pin is at +5V, the LED is OFF.
Pushing the switch (which connects to GND) causes GND current flow.
The 240R will limit the output current to ~21mA

Do I wire the LEDs to separate digital pins, or can I run them to the same ones I am using for the switches? Is there code involved in either instance? Can I be pointed to appropriate resources?

Not sure what they are asking for here.

larryd:
If this is to me.
When the Arduino pin is at +5V, the LED is OFF.
Pushing the switch (which connects to GND) causes GND current flow.
The 240R will limit the output current to ~21mA

But the resistor in series with the LED already limits the current.

Only the above mentioned double-use of the pin, and LED burnout detection makes sense.
Leo..

Edit: It seems OP was only asking for a LED indicator when the switch was closed.
And detection of the switch state.
Nothing more.
That can be done with one input pin.