Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC driving LED's

Status
Not open for further replies.

richacm

New Member
Hi,

I'm been drawing circuits to get my calculations right for having a PIC chip driving 9 LED's. Since I have a number of them I wanted to make sure I had all the right resistors etc in place.

During my research I got quite confused about how the LED's should be connected. Some examples I see are done one way and others another.

I've put together 3 options for connecting an LED to a PIC (see attachment). Firstly can someone check that my assumptions are valid, and secondly which one is the best? Or what questions should I be asking in terms of figuring out which way to do it.

I'm currently doing option 1, and am confused about option 2 (don't know if that's correct) and am thinking I should go to option 3 :)

Many thanks,

Craig
 

Attachments

  • LEDs.gif
    LEDs.gif
    5.4 KB · Views: 1,997
For controlling high brightness LED's/arrays of LED's/Segment displays, I like to use the **broken link removed**.

Internally the ULN2003 looks like this;

**broken link removed**

The ULN2003 is a very cost effective chip that acts like a switch. It simply switches an earth to/from an external circuit, and can withstand a continual 500mA current drain and a maximum 50V. It has a forward voltage drop of 0.9 Volts when on.

There is only one power connection, a common ground (Pin 8). Here's an example of driving a high power LED with logic voltages via the ULN2003 (note the LED is being driven by a 12 volt source, but controlled by the logic voltage);

**broken link removed**

**broken link removed**

To calculate the series resistor, you need to know the forward voltage drop of the resistor, and the current that the LED operates at.

R = V / I

Remember that the ULN2003 has a Vf of 0.9V to take into account aswell :eek:
 
Hey thanks chaps. Good to get my ideas verified. Gramo I really like the ULN2003 - will definitely add than in to my circuit instead of buying 9 transistors - cool site as well.

Thanks again,

Craig
 
Agreed. But, if you had to drive eight loads wouldn't you rather use a single slightly more expensive 8 bit driver IC instead of two of the 7 bit driver ICs? Mouser (a state-side distributor) shows the ULN2003 at approx. 45 cents and the ULN2803 at approx. 75 cents.

Other (expensive) sinking drivers to consider are the 8 bit cascadable serial-to-parallel sinking drivers ICs with a 3 pin interface (Data, Clock, and Strobe). These include the Micrel MIC5821/'5841, the Allegro A6821/'6841, the TPIC6C595, and others (example circuit using an MIC5821 below).

Mike

**broken link removed**
 
Last edited:
Agreed. But, if you had to drive eight loads wouldn't you rather use a single slightly more expensive 8 bit driver IC instead of two of the 7 bit driver ICs? Mouser (a state-side distributor) shows the ULN2003 at approx. 45 cents and the ULN2803 at approx. 75 cents.

Mike


For sure, I just don't promote it if all 8 are not required, or more then 8 but less then 15 are needed :)
 
I'm sure it's just personal preference Spency.

I bought a couple 7 bit ULN2003's long ago for my experiments but as soon as I learned about the 8 bit ULN2803 that's what I decided to stock in my parts bins. It just made sense at the time because everything I was doin' seemed to need 8 bits (7 segment displays, matrix displays, relay boards, etc.).

G'day, Mike
 
I made a 7 segment display using LEDs.I use 5 LEDs in parallel per segment but the output is so low almost unrecognizable at daytime. Do i have to use ULN2003 or ULN2803 also?
 
Can you post the circuit so people can review the calculations. From what I understand the PIC chip doesn't power that many LED's very well. The ULN2003 is so cheap anyway its worth getting one and using it. It would definitely make a difference.
 
I made a 7 segment display using LEDs.I use 5 LEDs in parallel per segment but the output is so low almost unrecognizable at daytime. Do i have to use ULN2003 or ULN2803 also?

You need to know the forward votage drop and current requirement of the LED's to properly match a series resistor...


Say you brought this LED...

Vf = 2V
If = 20mA

So you know the current required is 20mA, and the forward voltage drop of the LED will be ~2V, now you do some maths to figure out the resistor needed.. Ohms Law V = IR, rearrange that to R = V/I

Say your supply was 6 volts, 2 will be dropped on the LED, that means that a further 4 must be dropped over the resistor...

R = (6 - 2) / 0.020
R = 4 / 0.020
R = 200 ohm

If you ran 10 LED's in parallel, you should run each of them with a 200ohm resistor with a 6 volts supply, as each LED might have a different Vf and wont be as bright as each other... If you run it the crude way and only use 1 common resistor, then you need to remember to increase the current in the formula by 0.020 for each LED

:eek:
 
Thanks Spency that is most helpful for me as well....was just going through calculations working out what my resistor values would be.

Cheers
 
You don't mention the PIC chip you are using, but check the data sheets for the port current source/sink capabilities.
I use the 16F628A extensively as it has a high source and sink capability of 25mA per output pin (I use a 12 output configuration) and as the outputs are spread on both A and B ports, the combined current capability is indicated as 200mA.
By using the 'standard' 470R limiting resistors in series with the LED's I can drive ALL 12 leds directly from the PIC (although I do use a 680R resistor as my 'standard') .... this gives a current of around 7mA per LED (hence 12 x 7 = 84ma for all 12 LEDS) .... well within the rating of the 628A.

As an added 'load saving' on any 'battery' driven devices, I reduce the limiting resistor sizes to around 330R and then multiplex the LEDS, on TSO (Time Shared Output) basis so effectively only having one or two LEDS driven at any one time.
Hope this helps a little.

Roy
 
Thanks, I didn't realise that different PIC's had different port current source/sink capabilities....its good to know. I am using the PIC16F877A which I think is limited, plus I need to drive max 9 LED's at any one time with 20mA per LED, plus I need to fire a 0.1A current surge at a relay as well. The ULN2003 allows me to do that - but I will keep this in mind for future use.
 
So, if i understant, in the ULN2803 the com and the ground is connected???

No, the "com" (pin 10 of uln2803) refers to the "common free-wheeling diodes" pin.
These integral diodes are intended for back-emf suppression for inductive loads and the pin would have to be connected to the positive supply rail of these loads.

When using with leds, you can leave that pin unconnected. (you must not connect it to ground)
 
Thanks, I didn't realise that different PIC's had different port current source/sink capabilities....its good to know.

There are mostly only slight differences, PIC's generally have pretty good current driving capabilities - always as well to check the datasheet though, which will give you individual pin currents and an overall one.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top