LED & Resistor befuddlement

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:

formatting link
.

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

Reply to
Mike Turco
Loading thread data ...

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

Reply to
Jim Granville

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).

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 | ||
Reply to
Spehro Pefhany

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).

Reply to
Lewin A.R.W. Edwards

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
Reply to
Spehro Pefhany

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
Reply to
rickman

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
Reply to
Spehro Pefhany

when

you

and

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.

Reply to
Anthony Fremont

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

Reply to
Joe Legris

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
Reply to
rickman

Very, very low. I measure about 60nA with the one I mentioned earlier.

They follow the classic diode equation in this region up to perhaps a few mA where the series resistance starts to have a significant effect.

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
Reply to
Spehro Pefhany

What voltage do you measure on the LED with a current of 4 uA?

--

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
Reply to
rickman

Once a diode is turned on, the voltage remains pretty much the same regardless of the amount of in-spec current you run through it. If you limit the current too much, the LED won't be bright enough, or won't turn on.

In general, LED's drop between 1.5 and 2V. As you vary the current through the LED, you will see some variation in the forward voltage, but not enough to make a difference, and I doubt that a reliable way to use these devices.

Mike

Reply to
Mike Turco

I would skip the pulldown resistor altogether and simply drive the output low for a few cycles then switch it back to an input. The CMOS inputs have more than enough capacitance and a low enough leakage to hold the charge from the last driven state.

After driving the pin low and floating with no led connected you should indeed find a logic low on the input even for 100's of microseconds afterwards.

Normally I use this method for reading dip switches etc where the lead length is very short. If you want to run it a bit longer you should shield it somehow.

After driving the pin low and floating it when a led is connected you should see the input charging up to within Vdd in a very short period.

Method:

  1. Drive pin low and switch to output mode
  2. Hold for a few cycles
  3. Switch pin to input mode
  4. Wait for a few cycles
  5. Read the input - low = (no led)

This way you can still drive the LED with a high current and you don't need any additional components.

-- Peter Jakacki

Reply to
Peter Jakacki

I don't think you have read enough of the thread to understand what we are doing. I am trying to use a pull down resistor to pull the IO pin on the MCU to ground when the LED is absent. When the LED is in place, the pull down resistor needs to be light enough (high enough resistance) to *not* draw any more current than necessary. The pull down resistor is not trying to make the LED light. The goal is to allow the LED to pull the IO pin up to a voltage that will be seen as a 1 on the MCU IO pin.

I originally assumed that we were talking about TTL levels, but I expect there may be some devices that use CMOS thresholds on the inputs.

--

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
Reply to
rickman

the

limit

through

enough

devices.

I'd better read it from the top.

I understand what you're saying. The thing is that the drop across the LED is a fixed voltage of about two volts, and that puts the logic level into never-never land.

OK, lets say you have a 1k pull-up resistor and a 10k across the LED. The voltage drop across the 10k resistor is going to be ~ 2V. So, then, you change the pull-up to 330 and the 10k to a 100k, but it doesn't make a difference? Why? Because the voltage across the LED is always going to be pretty much the same -- that's the nature of a diode.

Another thing I thought about doing is putting two resistors in series under the LED. But it just doesn't cut it.

Last night I was thinking about this problem for just one LED. The fact is that I need to implement this into a 4x4 array of these "LED Switches". So.... the basic question remains, but its not so many transistors after all.

I will probably use a mux on the keypad rather than a controller, so I have a choice between TTL & CMOS, but not A/D.

Mike

Reply to
Mike Turco

... snip ...

Bad idea. You just don't leave CMOS input lines open. They can drift to a state where both input transistors are on, and just drawing excess current without limit.

--
fix (vb.): 1. to paper over, obscure, hide from public view; 2.
to work around, in a way that produces unintended consequences
that are worse than the original problem.  Usage: "Windows ME
fixes many of the shortcomings of Windows 98 SE". - Hutchison
Reply to
CBFalconer

You squeezed the trigger too soon and missed the point. Besides, when a micro is in reset all IO are inputs and floating, and that's for at least several if not 100's of milliseconds, isn't it? This includes spare pins that are not terminated and that configured as outputs for this reason.

If you had thought about it further you would of realized that the pin is normally in output mode anyway and just switching to input mode when testing.

We can't work with "ideal" circuits, we just make real circuits work for us, that's what engineers do.

-- Peter Jakacki

Reply to
Peter Jakacki

Oh, I see you are the OP. But your assumption that the LED has a constant 2 volt drop is not accurate. The drop is a function of current. Anyway, if your MCU input levels are TTL compatible, you don't have a problem in any event. What does your data sheet say?

If you can pick TTL levels, then the problem goes away....

--

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
Reply to
rickman

The drop is usually closer to 1.5 or 1.8v, which really doesn't cut it for TTL or CMOS.

I'm still working on the schematics. I plan to use the usbmicro U421, or something like that, and am still looking for a mux.

Anything between .8 and 2V is in la-la land for TTL, and the level for CMOS (IIRC), are 1.5 and 3V. There may be LED's out there that put me on the cusp of conformity.

Next time you get hold of an LED and a few resistors, you might want to build a little circuit. Just an LED, a resistor and a power source. Change the value of the resistor and measure the voltage across the LED. You'll find that the voltage across the LED changes very little, if at all, with any amount of current you drive through the device, within reasonable limits.

Mike

Reply to
Mike Turco

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.