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.

Best way to do this (sense LED signal w/PIC)

Status
Not open for further replies.

kpatz

New Member
Here's the gist of my little project.

I have a box (the function of which isn't really important for this discussion) which runs off 12V. The box has a power switch, a LED which may be on, off, or flashing (as controlled by the box). I want to use a PIC micro to detect the state of this LED.

Sound simple enough? Well, the LED is wired as shown in the attached diagram. As far as I can tell, the LED anode is wired directly to the +12V side of the switch, and the cathode goes to one of the connector pins on the box. Using my great power of ASSumption, I can surmise that the box switches the LED on/off via a transistor which grounds the cathode of the LED through a current limiting resistor.

I hooked my scope up to the point that I marked on the diagram (between the LED cathode and ground), to see what I would get. I saw about 5.5V with the LED on, and 10V with the LED off. This is a bit off from what I expected (something closer to 10 and 12V, based on a typical 2V drop from a LED).

Anyway, if I want to use a PIC to detect whether the box has the LED on or not, what do you think the best way is?

These are the options I thought of:

Option 1: Use a voltage divider to bring the maximum voltage down to 5V, and feed to one of the PIC inputs. Advantage: Easy to do. Disadvantage: the LED ON voltage may be too high (probably around 2.5V if I divide the voltage by 2) to trip the input low.

Option 2: Use a comparator. The PIC I'm using (PIC16F526) has two comparators on board, along with a programmable voltage reference. I could use that to detect whether the LED voltage is above or below a certain threshold (which I would divide down to meet the PIC's 5-volt maximum). Advantage: Almost as easy to do. Disadvantage: What if the next guy's control box drives the LED in a different way, or the voltages vary due to supply/load variation?

Option 3: Use the PIC's A/D converter. Then I can take measurements and detect a change in the LED's state when the A/D returns a significantly higher or lower value than the last check.

Option 4: Some other blatantly simple and obvious way that I'm totally overlooking, that's where you guys come in. :)
 

Attachments

  • led_sense.GIF
    led_sense.GIF
    8.4 KB · Views: 161
Any chance you could get to the collector end of the current limiting resistor?
 
Simply use a resistor in series with the PIC input to limit the current though the input protection diode. The protection diode at each input clamps the input voltage to about 0.6V above the power supply voltage. Then the input will be high when the signal is +10V and the input will be low when the input is +0.5V.
 
Simply use a resistor in series with the PIC input to limit the current though the input protection diode. The protection diode at each input clamps the input voltage to about 0.6V above the power supply voltage. Then the input will be high when the signal is +10V and the input will be low when the input is +0.5V.
The LED lead is at 5.5V with the LED on, and 10V give or take when it's off. So I would just be getting a high, and a high with a clamped protection diode. :)
Any chance you could get to the collector end of the current limiting resistor?
Not without modifying the box and voiding its warranty.

Another idea: put an optocoupler in series with the LED. It might make the LED dimmer though.
 
Last edited:
Simply use a resistor in series with the PIC input to limit the current though the input protection diode. The protection diode at each input clamps the input voltage to about 0.6V above the power supply voltage. Then the input will be high when the signal is +10V and the input will be low when the input is +0.5V.

This goes against the specific recommendations in this MicroChip App Note, especially for analog input pins (A/D inputs, comparitor inputs).
 
The LED lead is at 5.5V with the LED on, and 10V give or take when it's off.

Just make a voltage divider out of two resistors: R1 to the Led, and R2 to ground. Make R1 about 15K, and R2 about 10K. Bypass R2 with 100nF capacitor. Tie the tap to an A/D or comparator input. This will offset the range of input voltages to about 2V and 4V, respectively.
 
If you want to keep it isolated electrically you could use an optocoupler.
Basically a transistor that uses light to turn on (it has an LED inside).
You could place it in parallel with your led and connect the other side to your pic.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top