LED Wiring with Microcontroller

Thread Starter

MTech1

Joined Feb 15, 2023
161
I see two versions of LED wiring with the microcontroller. Please take a look at the attached image.

IMG-20231106-WA0000.jpg

We can wire the other end to Gnd, or we can wire the other end to Vdd.

I have tried the second version with PIC18F45K22.

I am interested to know which version you use and why, and which version you would recommend to other
 

Martin_R

Joined Aug 28, 2019
137
LD1 will light when the output is low, LD2 will light when the output is high. It's use will depend on you. If you want to monitor an output when it's high I would use LD2 circuit.
 

John P

Joined Oct 14, 2008
2,022
Back in the TTL days, chips could sink more current than they could source, so it became standard to have an "active low" output. Intuitively, we might say "On is high, off is low", and with CMOS, that would work equally well, but maybe there's still a little prejudice that makes an active-low output more common.
 

liaifat85

Joined Sep 12, 2023
47
The first LED is active LOW and the second one is active HIGH. In most PCBs, there are Active HIGH LEDs. Like the in built LED of the Arduino UNO. In many PCBs there are active LOW LEDs. For example, the in-built LED of the NodeMCU. If your circuit consists of a microcontroller and LED only, you can design your circuit both ways. However, if your setup consists of many components, you can choose the configuration that will be most convenient for the compact design.
 

dl324

Joined Mar 30, 2015
16,642
I have tried the second version with PIC18F45K22.

I am interested to know which version you use and why, and which version you would recommend to other
The device you reference can sink more current than it can source (across all ports).
1699292873660.png
My most typical application for driving LEDs is to drive a matrix of them and I operate them at a higher peak current than the outputs can typically support. Because of that, I use external transistors as row and column drivers.
 

MrChips

Joined Oct 2, 2009
30,415
Neither option.
Use an inverting or non-inverting buffer to drive the LED. A simple BJT will work as a driver.
Whether you put the LED on the HIGH side or LOW side depends on how much sink or source drive current is available and if you want ACTIVE LOW or ACTIVE HIGH indicator.
 

Thread Starter

MTech1

Joined Feb 15, 2023
161
Neither option.
Use an inverting or non-inverting buffer to drive the LED. A simple BJT will work as a driver.
I noticed your comment suggesting the use of a buffer to drive an LED, and I'm curious to understand more about the reasoning behind it. In many microcontroller applications, I've seen that simply using the current-limiting resistor seems to work well for driving LEDs. Could you please elaborate on when and why a buffer might be necessary in LED driving applications?
 

dl324

Joined Mar 30, 2015
16,642
Could you please elaborate on when and why a buffer might be necessary in LED driving applications?
That's just it. It depends on the application.

If you wanted to drive hundreds of LEDs at a current high enough to operate them at their highest brightness, your microcontroller wouldn't have enough outputs. It would also likely run into its maximum current sink/source spec. Those limits can also vary by port.
 

Thread Starter

MTech1

Joined Feb 15, 2023
161
That's just it. It depends on the application.
Let's consider an application where I need to control a number of LEDs, say at least 24 of them. The microcontroller I'm working with is the PIC18F45K22. Given this scenario, I'm interested in understanding the most efficient and practical way to drive these LEDs

Attached link for refrance
LED
 

MrChips

Joined Oct 2, 2009
30,415
I noticed your comment suggesting the use of a buffer to drive an LED, and I'm curious to understand more about the reasoning behind it. In many microcontroller applications, I've seen that simply using the current-limiting resistor seems to work well for driving LEDs. Could you please elaborate on when and why a buffer might be necessary in LED driving applications?
As Dennis said.

This is a common fault with people who want to use LEDs to monitor logic signals.
LEDs require current. Hence it depends on how much current you are going to take to light the LED and how much current the port can supply without degrading the logic voltage. (To find out, measure the output voltage of the port while the LED is on.)

If the output voltage of the output is degraded beyond being a proper logic level voltage, then you cannot reliably use this output to drive another logic gate.

Hence, use a buffer to drive the LED alone and don't use this same buffer to drive a logic gate at the same time.
 

dl324

Joined Mar 30, 2015
16,642
Let's consider an application where I need to control a number of LEDs, say at least 24 of them. The microcontroller I'm working with is the PIC18F45K22. Given this scenario, I'm interested in understanding the most efficient and practical way to drive these LEDs
  1. What current will you be operating the LEDs at?
  2. Will they all be on at the same time?
  3. If using multiple colors, do you desire brightness matching?
  4. The microcontroller has 36 I/O's. Will any of them be used for other purposes?
As a side note, I wouldn't recommend buying LEDs from any source that didn't provide manufacturer part numbers and datasheets. If you multiplex LEDs, you need to know the continuous and peak current specifications.
 

Jon Chandler

Joined Jun 12, 2008
969
Neither option.
A better answer would be "It depends." Not all micros are the same in terms of source/sink current. A PIC18F-series is happy to source or sink 25mA from a port pin (although not all of them at once). An ESP32 as I recall is limited to 3 or 4 mA.

Modern LEDs are bright with 5mA drive current or less. So buffers with an 18F are a needless complication.
 
Top