0
\$\begingroup\$

I want to connect leds to Cherry MX switches (push switches) so they light up when I press them.

I have 6 switches each connected to a different pin of a teensy 2, basically like this:

enter image description here

enter image description here

The diodes are 1N4148.

What is the correct way to connect the leds and resistors?

Like this?

enter image description here

or like this?

enter image description here

With this one, if more then one key will be pressed, will the leds shine brighter and potentially burn?

The leds are 3mm cheap ones, I measured with a multimeter with single led with 5V and a 200Ohm resistor I get about 23mA.

\$\endgroup\$
7
  • \$\begingroup\$ Why are the switches connected to the Teensy? What role does the processor play in this? \$\endgroup\$ Jun 18, 2018 at 19:56
  • \$\begingroup\$ Always label your pins. I hate guessing. \$\endgroup\$
    – Bort
    Jun 18, 2018 at 19:57
  • \$\begingroup\$ It's a 6 key keyboard, I need to map the keys and USB port. @ElliotAlderson \$\endgroup\$
    – shinzou
    Jun 18, 2018 at 20:47
  • \$\begingroup\$ The pins are irrelevant, it's connected to general io pins and they work. @Bort And would pins F5, B6, F7 mean anything in this context? no. \$\endgroup\$
    – shinzou
    Jun 18, 2018 at 20:48
  • \$\begingroup\$ Bort’s point was really you should label your diagrams properly - avoids confusion, even though it may not be necessary in this case... @Bort \$\endgroup\$
    – Solar Mike
    Jun 18, 2018 at 22:17

1 Answer 1

1
\$\begingroup\$

LEDs are non-linear devices when it comes to their forward voltage. They have a narrow range (by voltage) where they work optimally. Too little voltage and they don't conduct, too much and they fail.

By B.Gashiii - Own work, CC BY-SA 3.0

Credit: B. Gashiii

There are other questions which address the proper ways to connect and power LEDs; but simply put, you need constant current. The most straightforward way to connect LEDs is to use a current-limiting resistor with fixed voltage sources. You're on the right track with the inclusion of current-limiting resistors, but you have two different methods in your examples.

Let's simplify these by eliminating the switches for the moment and just examining the differences between having LEDs share a resistor versus having dedicated ones.

schematic

simulate this circuit – Schematic created using CircuitLab

In the top example, each LED has a resistor to limit current through it. In the lower example, the LEDs share a resistor to limit current through the two in parallel. (I've selected resistor values for LEDs having a Vf of 2V and a nominal current of 20 mA.)

I've eliminated switches, so these examples are for "all LEDs lit" situations, which you would achieve by pressing all switches simultaneously.

If you examine this question about LEDs in parallel, you'll discover that while it works in theory, it doesn't usually work well in practice. What happens is one LED has slightly different physical characteristics than others, and current is not shared equally. Over time this leads to various problems.

The other problem occurs at the introduction of switches. When you have a single resistor, how can its value be appropriate for a variable number of lit LEDs? The answer is that it can't, so you should have a resistor for each LED.

Up to this point, I've ignored two other aspects of your question: The microcontroller and the switching diodes. From the way you worded your question, I am assuming you want to read switch state with the microcontroller, but light the LEDs with the press of a switch.

An LED is also a diode (Light Emitting Diode). So you shouldn't need the additional diodes at all. They will introduce an additional small voltage drop (about 0.8 - 0.9V depending on temperature and current).

The pins on your microcontroller should either be configured as input pins, to read the switch state, or output pins to drive LEDs. These are conflicting situations, better discussed in this question. Depending on which Teensy you have, you may need to dedicate some pins as output to drive the LEDs and some pins as input to read the switch states. You might not have enough pins, so that leaves you having to either multiplex switches and/or LEDs or use a microcontroller with more I/O pins. There might be other options as well, but you should ask a new/separate question once you've narrowed it down a bit. Hope this helps.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.