Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked — Edited

How To Drive A Led Correctly From A Digital Output

SHOULD always use a current resistor inline with led ,so you dont damage the ezb digital pin or burn out the diode

Here is a link for reasons why and formula to work out the resistor value.


driving a led from a digital output

AI Support Bot
Related Content
Synthiam
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
#1  
Wednesday, 27 March 2013

GREAT Job RobotMaker !

I like the Idea of Showing the EZ-B Digital Output BOTH Sinking and Sourcing the Current !

In your example, P0 is SINKING the Current, and P1 is SOURCING the Current.

Therefore, P0 has approximately a 1-Volt Advantage over P1.

Chances are that the EZ-B has the HexFet Equivalent of a Totem Pole Output.

The Final Choice would be to find out Which FET has the Highest or Safest Current Limits ?

Best Wishes,

DougPope@cox.net, 602-246-1246(H)
PRO
Synthiam
#2  
The EZ-B (as stated many times in this forum and on documentation) does not need a resistor for the LED. This is because the EZ-B microchip contains an internal resistor for the I/O

Users: Please ignore RobotMaker's post. There is no point to use a resistor for LED on EZ-B.

Further reading visit our hardware tutorial: http://www.ez-robot.com/Tutorials/Hardware.aspx?id=7

:)
#3  
WHAT do meen by a fet having the highest or safest current limits ?

DO you meen from a microprocessor or fet driving circuit?

If microprocessor is depends on the type ,its in the data sheet of that microprocessor for max sink current and max source current
#4  
oh i did see that DJ ,SORRY, i thought it was a straight drive from microprocessor

DJ is right look at the led tutorial and see that its built in,not like other boards like arduino and other microprocessoor board that need it.
#5  
Thank You DJ For The Clarification !

As usual, I have got a lot of Homework and Catching Up to Do; The Joys of being age 68.
#6  
SAME with me ,i guess i didnt see it,and it hard to look up led in seach because of so many will come up.

NEXT time will look at the hardware manual first and if i can find the answer will post it,nobody is perfect.
Canada
#7  
DJ, I am sorry but you are incorrect in your statement about not needing a resistor to drive an led with the microcontroller on your board. I have been designing with Microchip's dsPic33F controllers for the past 3 years and its I/O ports are the same design as the ports in the 18F4684 that you use with the EZ-B.

From the Microchip 18F4684 datasheet (document DS39761C, page 134):

" Each of the PORTB pins has a weak internal pull-up. A
single control bit can turn on all the pull-ups. This is
performed by clearing bit RBPU (INTCON2<7>). The
weak pull-up is automatically turned off when the port
pin is configured as an output. The pull-ups are
disabled on all device Resets."

The reason that you can drive an led directly from the port pins is that they are internally limited to sourcing or sinking a maximum of 25 ma. However, you have no control over the brightness since every led will get this 25 ma. Another disadvantage is that driving 8 leds at 25ma makes a total of 200ma which is the aggregate current limit for all of the port pins. If you use resistors you can match the brightness of different types and colours of leds and reduce the current so that you can use all of the port pins. For some ir leds used in sensors and many high efficiency leds 10ma is sufficient.

There is also a more general concern about a lack of resistors. When port pins are connected to a cable, there can be voltage spikes from noise pickup and static electricity. If the port pin is connected directly to the wire it may be damaged. A 100 ohm res. between the port and the wire will give some protection (both outputs and inputs).

Finally, being able to drive an led directly is valuable if you are designing a commercial product for a very competitive market because it saves parts and board space. For most diy designs these are not issues so I always use transistors to drive leds and relays. You have a more robust design, the microcontroller will be isolated from the dangerous real world and there will be less heat generated in the microcontroller.
#8  
YES i tried to explain that but it does no good.
PRO
Synthiam
#9  
Ah interesting. I thought the internal pullup was active on output. Surprising I missed that:) You should get an award if you are correct regarding the chip that the EZ-B uses. Which is not the chip you referenced.

To make it easier on everyone - there still is no need for a resistor on your LED because it won't do any damage
#10  
@Nomad If I understand you correctly, you agree that LEDs can be driven directly from EZB, although there are caveats that need to be explicitly noted in tutorial? Also I don't know myself but the pullup resistor might be enabled upon power on or connection to ARC. We will have to see what DJ says. (Edit: He already did)
#11  
If you drive a led at half the current it will last much longer and still have goood brightness,most leds are rated at 20ma max.

When i get home late tonight going to make a quick test using a inline current meter with the led to EZB to find out how much it really draws.
Canada
#12  
DJ - I removed the Bluetooth module from my EZ-B and the chip has 'Microchip & 18F4685' printed on it. I referred to the data sheet for this part. I also noticed that the pullups are only available on port B.

One thing I have learned about Microchip is that you need to read at least 3 different data sheets; 1 on hardware design, one on software design and another on the family the part belongs to. Each document will have a couple of critical points that the other two don't mention.

I don't need an award. SEND MONEY!, but seriously, I am happy to help out.

Troy - I don't want to confuse the issue because DJ is correct in saying that you can run the led directly and not damage the part. What I am trying to say is that there are some applications where using a resistor is beneficial in several ways. Since resistors are cheap and have virtually zero negative impact, why not use them all the time? It always comes down to the application.

For example, if the led is connected as in the tutorial and there is a 1 kohm pullup resistor on the pin, the led will be on when the port output is high. If the port was not connected, the 1 kohm res. would limit the current through the led to 3.8 ma since the led anode will be at 2 diode drops above ground potential. However, with the port connected it tries to drive the line to 4V which means its output will hit the 25 ma limit. To turn off the led the port pin goes low and steals the current being supplied to the led by the pullup. A low on the port pin will be 0.4V which means the port will be sinking 4 ma from the pullup to keep the led off. If your robot is powered by a 12V lead acid battery, this isn't a big concern. However, if you are using a couple of AAs and you have 8 leds your batteries will be dead in a few days just from sitting. Instead, keep the led connected to the pullup resistor but connect the cathode to the port pin. Now, the port sinks the 3.8 ma through the pullup when the led is on but when the led is off the port pin is high and zero current flows. This also results in less heat being generated in the microcontroller. My current project requires 2 gear motors and controller electronics with battery inside an 16 cu. in. waterproof shell with a total weight of less than 5 oz. For me, saving 4 ma is a big deal.

If you want to go even farther, consider that sinking 4 ma through a port pin will generate slightly less heat than sourcing 4 ma. I leave the proof of this as an exercise for the reader. It is very useful in combatting insomnia.
PRO
Synthiam
#13  
Sorry, you wrote 18F4684 in your previous post... Money? I wish!

Although our new web hire is pretty awesome and he's implementing a neat new community feature soon. When people ask questions, those who answer the question and help the OP out get EZ-Bucks! That's credits to be spent in our store. So the more helpful you are (i.e. rich and dave and others) will have credits to buy more things.

Also, those "things" are changing:D It's kind of exciting - I wish I could tell you all now. But I'm forbidden for a few more weeks. We'll announce Revolution on here before the press releases.