simplest led interface ever

Post date: Aug 01, 2016 11:43:50 PM

Need to light an LED and don't have a resistor? Just connect it from GPIO 3 to ground (the connections are right next to each other!). The 1.8K pull-up resistor on the Pi will light it as long as the pin is configured as an input. To turn the LED off, set the pin as an output and output a low level. Just don't output a high level - that will probably burn out the LED. You can use GPIO 2 the same way, but unfortunately a ground connection isn't nearby. Or you could use a 2-Lead Bicolor LED between the GPIOs 2 and 3!

You can also use this technique to drive the base of an NPN transistor to switch larger loads.

And it can get even simpler: a blue or white LED may not need a resistor at all! Why? It's forward voltage is less than the 3.3V supply voltage at reasonable currents, and it's voltage/current curve is not very exponential. If you're going to use this technique, you should first prototype it and test the current through your particular LED: it shouldn't be more than 15 milliamps to avoid frying the Pi. Try different LEDs if it's too high. My preference is something around 4 milliamps.