EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

LED & Resistor befuddlement

Started by Mike Turco June 2, 2004
I thought this was going to be simple. I have a controller, an LED, a
resistor and a socket. Its a five volt circuit.

I want to plug the LED into the socket in a board. The controller needs to
know whether or not the LED is plugged in, and if the LED is plugged in, it
needs to be able to turn it on and off.

One issue is that the forward voltage of just about any LED puts all the
voltages out in the middle of no-mans land in terms of logic levels.

Anyway, I came up with a solution, but it seems a little too complex and I
get the feeling I'm missing something. My solution is here:
http://miketurco.com/123/ledbef.gif .

Basically, if you put a low on the input and there's an LED in the socket,
the LED will turn on and you'll get a low on the output. If there's no LED,
then you'll see a high on the output.

Is there a way to accomplish this with one i/o pin? Any way to save a part?

Thanks,

Mike






Mike Turco wrote:
> I thought this was going to be simple. I have a controller, an LED, a > resistor and a socket. Its a five volt circuit. > > I want to plug the LED into the socket in a board. The controller needs to > know whether or not the LED is plugged in, and if the LED is plugged in, it > needs to be able to turn it on and off. > > One issue is that the forward voltage of just about any LED puts all the > voltages out in the middle of no-mans land in terms of logic levels. > > Anyway, I came up with a solution, but it seems a little too complex and I > get the feeling I'm missing something. My solution is here: > http://miketurco.com/123/ledbef.gif . > > Basically, if you put a low on the input and there's an LED in the socket, > the LED will turn on and you'll get a low on the output. If there's no LED, > then you'll see a high on the output. > > Is there a way to accomplish this with one i/o pin? Any way to save a part?
Yes, & how about saving 2 parts ? :) a) If the uC has a ADC on board, you can measure the drop across the NFET, to sense LED presence. b) Place a small CAP ~1nF across the IO pin to gnd, then Float and readback in atomic form. Read L = No LED, Read H = LED is present. If the uC has open Collector & low leakage port option, it might work with No cap. -jg
On Tue, 1 Jun 2004 23:53:15 -0700, the renowned "Mike Turco"
<miketurco@yahoo-nospam4me.com> wrote:

>I thought this was going to be simple. I have a controller, an LED, a >resistor and a socket. Its a five volt circuit. > >I want to plug the LED into the socket in a board. The controller needs to >know whether or not the LED is plugged in, and if the LED is plugged in, it >needs to be able to turn it on and off. > >One issue is that the forward voltage of just about any LED puts all the >voltages out in the middle of no-mans land in terms of logic levels. > >Anyway, I came up with a solution, but it seems a little too complex and I >get the feeling I'm missing something. My solution is here: >http://miketurco.com/123/ledbef.gif . > >Basically, if you put a low on the input and there's an LED in the socket, >the LED will turn on and you'll get a low on the output. If there's no LED, >then you'll see a high on the output.
Watch that the output voltage on the port pin when driving the LED + Vce on the transistor is guaranteed to be a reliable "0" (with decent margin). If you're using a micro with (asymmetrical) TTL-compatible inputs it might be better to flip everything around and use a PNP (same number of parts).
>Is there a way to accomplish this with one i/o pin? Any way to save a part?
I don't see a simpler (general) way of doing this. In the specific case of a PIC @5V Vdd driving a GaAlAs super bright red LED at relatively low current, you should be able to do it with two port pins (one of which must be a TTL-level input) and no extra parts: Output o-------------------| | | | | / V / LED - | o-------------------+ TTL input | .-. | | 1K | | '-' | | === GND Here is a more complex circuit that uses just one port pin and drives the LED with a small MOSFET rather than the port pin directly. It will work with pretty much any single junction LED at pretty much any reasonable current. +5 o--+-------+ | | | .-. | | | 1K | | | | '-' >| | |-----+ /| | / | V / | - .-. | LED | | | 1K | | .-. '-' | | | | | RLED | '-' | | | | | ||-+ Port pin | ||<- o-------------+----||-+ 2N7000/7002 | | .-. | | | === 20K | | GND '-' | | === GND If you turn the LED on (output = high) and then tristate the port pin, and wait, say, 10usec, the pin will read 0 if there is no LED and 1 if there is an LED. BTW, this is kind of an unusual requirement. Why do you care if the LED is there or not? Why not just "try" to turn it on? Are you switching the program functionality depending on the presence of an indicator LED? Best regards, Spehro Pefhany -- "it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com
> I want to plug the LED into the socket in a board. The controller needs to > know whether or not the LED is plugged in, and if the LED is plugged in, it > needs to be able to turn it on and off.
I haven't thought about this in detail, and I'm probably neglecting some important point, but why not put a capacitor in parallel with the LED and its current-limiting resistor? When you want to detect the LED's presence, follow an algorithm like this: 1. Set pin to output mode, low output 2. Bring pin high. 3. Wait for time t. 4. Set pin to input mode and sample. 5. If pin reads low, increase t and repeat from step 2. You should see a certain threshhold time t for the LED-absent case, and if you go much beyond this time, you can assume the LED is present. (Assumed: Micro is capable of driving the LED directly, open-emitter output).
On Wed, 02 Jun 2004 11:55:43 GMT, Spehro Pefhany
<speffSNIP@interlogDOTyou.knowwhat> wrote:

P.S. one more idea, specific to the PIC with ADC and requiring ZERO
parts beyond the LED and the resistor to set the current and just ONE
port pin. 

You can set digital/analog port pins to be a digital output and still
measure the voltage on that pin with the ADC.  

For example, the minimum (3-sigma) output voltage at 5mA with 5V Vdd
is over 100mV. That represents 20 counts on a 10-bit ADC. That's
sinking current, the situation is even better with higher currents,
sourcing current, or with lower Vdd. 

Best regards, 
Spehro Pefhany
-- 
"it's the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Mike Turco wrote:
> > I thought this was going to be simple. I have a controller, an LED, a > resistor and a socket. Its a five volt circuit. > > I want to plug the LED into the socket in a board. The controller needs to > know whether or not the LED is plugged in, and if the LED is plugged in, it > needs to be able to turn it on and off. > > One issue is that the forward voltage of just about any LED puts all the > voltages out in the middle of no-mans land in terms of logic levels. > > Anyway, I came up with a solution, but it seems a little too complex and I > get the feeling I'm missing something. My solution is here: > http://miketurco.com/123/ledbef.gif . > > Basically, if you put a low on the input and there's an LED in the socket, > the LED will turn on and you'll get a low on the output. If there's no LED, > then you'll see a high on the output. > > Is there a way to accomplish this with one i/o pin? Any way to save a part?
Seems to me you guys are all over thinking the problem... or I am missing something important. How about just adding one resistor and using the IO pin as an input when you want to check for the presence of the LED and as an output when you want to drive it? ___ | | - | | R1 | | current - limiter | ~330 ohms | --- \ / LED _V_ | +----------> To MCU IO pin | - | | R2 | | Light - Pulldown | ~10 kohms | _|_ \ / V With this circuit the IO pin will be high if the MCU is not pulling it down and the LED is installed. If the IO pin is not driving it low and no LED is plugged in, the IO pin will be low by R2. The IO pin can drive low to turn on the LED. -- Rick "rickman" Collins rick.collins@XYarius.com Ignore the reply address. To email me use the above address with the XY removed. Arius - A Signal Processing Solutions Company Specializing in DSP and FPGA design URL http://www.arius.com 4 King Ave 301-682-7772 Voice Frederick, MD 21701-3110 301-682-7666 FAX
On Wed, 02 Jun 2004 13:06:46 -0400, the renowned rickman
<spamgoeshere4@yahoo.com> wrote:

>Mike Turco wrote: >> >> I thought this was going to be simple. I have a controller, an LED, a >> resistor and a socket. Its a five volt circuit. >> >> I want to plug the LED into the socket in a board. The controller needs to >> know whether or not the LED is plugged in, and if the LED is plugged in, it >> needs to be able to turn it on and off. >> >> One issue is that the forward voltage of just about any LED puts all the >> voltages out in the middle of no-mans land in terms of logic levels. >> >> Anyway, I came up with a solution, but it seems a little too complex and I >> get the feeling I'm missing something. My solution is here: >> http://miketurco.com/123/ledbef.gif . >> >> Basically, if you put a low on the input and there's an LED in the socket, >> the LED will turn on and you'll get a low on the output. If there's no LED, >> then you'll see a high on the output. >> >> Is there a way to accomplish this with one i/o pin? Any way to save a part? > >Seems to me you guys are all over thinking the problem... or I am >missing something important. > >How about just adding one resistor and using the IO pin as an input when >you want to check for the presence of the LED and as an output when you >want to drive it? > > ___ > | > | > - > | | R1 > | | current > - limiter > | ~330 ohms > | > --- > \ / LED > _V_ > | > +----------> To MCU IO pin > | > - > | | R2 > | | Light > - Pulldown > | ~10 kohms > | > _|_ > \ / > V > >With this circuit the IO pin will be high if the MCU is not pulling it >down and the LED is installed. If the IO pin is not driving it low and >no LED is plugged in, the IO pin will be low by R2. The IO pin can >drive low to turn on the LED.
This will work with good margin for some LEDs and some input buffers, and not at all or marginally with other choices. For example, a super-bright green LED will yield about 2.2-2.3V typically at the input with the above circuit and 5V Vdd. Some input buffers need Vdd * 0.8 worst-case, others are okay at around 1.9-2.0V (the "TTL" type). Since this circuit is "measuring" the LED presence with 250uA rather than 10-20mA, it has less drop and will work with more LEDs than the circuit I showed, however it has one more component. Best regards, Spehro Pefhany -- "it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com
"rickman" <spamgoeshere4@yahoo.com> wrote in message
news:40BE0926.99211C0A@yahoo.com...

> Seems to me you guys are all over thinking the problem... or I am > missing something important. > > How about just adding one resistor and using the IO pin as an input
when
> you want to check for the presence of the LED and as an output when
you
> want to drive it? > > ___ > | > | > - > | | R1 > | | current > - limiter > | ~330 ohms > | > --- > \ / LED > _V_ > | > +----------> To MCU IO pin > | > - > | | R2 > | | Light > - Pulldown > | ~10 kohms > | > _|_ > \ / > V > > With this circuit the IO pin will be high if the MCU is not pulling it > down and the LED is installed. If the IO pin is not driving it low
and
> no LED is plugged in, the IO pin will be low by R2. The IO pin can > drive low to turn on the LED.
I think the problem with doing that is that the forward voltage drop of the LED puts the input pin in the area of "uncertain" results.
rickman wrote:
> Mike Turco wrote: > >>I thought this was going to be simple. I have a controller, an LED, a >>resistor and a socket. Its a five volt circuit. >> >>I want to plug the LED into the socket in a board. The controller needs to >>know whether or not the LED is plugged in, and if the LED is plugged in, it >>needs to be able to turn it on and off. >> >>One issue is that the forward voltage of just about any LED puts all the >>voltages out in the middle of no-mans land in terms of logic levels. >> >>Anyway, I came up with a solution, but it seems a little too complex and I >>get the feeling I'm missing something. My solution is here: >>http://miketurco.com/123/ledbef.gif . >> >>Basically, if you put a low on the input and there's an LED in the socket, >>the LED will turn on and you'll get a low on the output. If there's no LED, >>then you'll see a high on the output. >> >>Is there a way to accomplish this with one i/o pin? Any way to save a part? > > > Seems to me you guys are all over thinking the problem... or I am > missing something important. > > How about just adding one resistor and using the IO pin as an input when > you want to check for the presence of the LED and as an output when you > want to drive it? > > ___ > | > | > - > | | R1 > | | current > - limiter > | ~330 ohms > | > --- > \ / LED > _V_ > | > +----------> To MCU IO pin > | > - > | | R2 > | | Light > - Pulldown > | ~10 kohms > | > _|_ > \ / > V > > With this circuit the IO pin will be high if the MCU is not pulling it > down and the LED is installed. If the IO pin is not driving it low and > no LED is plugged in, the IO pin will be low by R2. The IO pin can > drive low to turn on the LED. > > >
But the "high" voltage with the LED installed is at best 3.5 Volts and probably less, depending on the LED. The threshold voltage of the input may be around 2.5 volts, so it's all a little dicey. -- Joe Legris
Joe Legris wrote:
> > rickman wrote: > > Mike Turco wrote: > > > >>I thought this was going to be simple. I have a controller, an LED, a > >>resistor and a socket. Its a five volt circuit. > >> > >>I want to plug the LED into the socket in a board. The controller needs to > >>know whether or not the LED is plugged in, and if the LED is plugged in, it > >>needs to be able to turn it on and off. > >> > >>One issue is that the forward voltage of just about any LED puts all the > >>voltages out in the middle of no-mans land in terms of logic levels. > >> > >>Anyway, I came up with a solution, but it seems a little too complex and I > >>get the feeling I'm missing something. My solution is here: > >>http://miketurco.com/123/ledbef.gif . > >> > >>Basically, if you put a low on the input and there's an LED in the socket, > >>the LED will turn on and you'll get a low on the output. If there's no LED, > >>then you'll see a high on the output. > >> > >>Is there a way to accomplish this with one i/o pin? Any way to save a part? > > > > > > Seems to me you guys are all over thinking the problem... or I am > > missing something important. > > > > How about just adding one resistor and using the IO pin as an input when > > you want to check for the presence of the LED and as an output when you > > want to drive it? > > > > ___ > > | > > | > > - > > | | R1 > > | | current > > - limiter > > | ~330 ohms > > | > > --- > > \ / LED > > _V_ > > | > > +----------> To MCU IO pin > > | > > - > > | | R2 > > | | Light > > - Pulldown > > | ~10 kohms > > | > > _|_ > > \ / > > V > > > > With this circuit the IO pin will be high if the MCU is not pulling it > > down and the LED is installed. If the IO pin is not driving it low and > > no LED is plugged in, the IO pin will be low by R2. The IO pin can > > drive low to turn on the LED. > > > > > > > > But the "high" voltage with the LED installed is at best 3.5 Volts and > probably less, depending on the LED. The threshold voltage of the input > may be around 2.5 volts, so it's all a little dicey.
I picked the 10K value from air. The diode drop is not a fixed number, but varies with current. Simply increase the 10K resistor value until you get an acceptably high voltage at the pin. It won't take much to pull down an open input to make it read low with no LED. I expect a 100K will work, or possibly you will need something closer to 1M. I have never been able to get an IV curve on LEDs and I have not measured it myself. Anyone know how low the current must be to get the voltage drop below 1 volt? -- Rick "rickman" Collins rick.collins@XYarius.com Ignore the reply address. To email me use the above address with the XY removed. Arius - A Signal Processing Solutions Company Specializing in DSP and FPGA design URL http://www.arius.com 4 King Ave 301-682-7772 Voice Frederick, MD 21701-3110 301-682-7666 FAX

The 2024 Embedded Online Conference