An unusual way of using LED as a light sensor

Go To Last Post
24 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a device which once could switch on the load in preset intervals (it stopped working so I disassembled it). There is a jumper to choose if the device will work during the daylight of during the night and there is an UV LED for sensing the light used instead of a photoresistor. I am aware of a few approaches when using LEDs as light sensors but this schematics looks somewhat unfamiliar. Here is the schematics I made by inspecting the PCB.

 

I can not be sure which µC has been used because the labels have been removed but since it is 8 pin package with pin 1 = Vcc and pin 8 = GND I am assuming it might be 12F629 or similar.

 

Nevertheless, I would like to replace the PIC with ATtiny and the only problem is the theory of operation of the light sensing circuit. Obviously the µC's pin that is connected to the light sensing circuit can not be output because by making it HIGH the LED would be shorted to ground - meaning it is either a digital or analog input (pin 7 of 12F629 can be analog comparator input with selectable internal voltage reference).

 

Can anyone decipher how this light sensing circuit works?

 

Cliff: For the benefit of others here is the attachment:

 

http://www.avrfreaks.net/sites/default/files/forum_attachments/LED_as_light_sensor.png

Attachment(s): 

This topic has a solution.

Chupo_cro

Last Edited: Tue. Oct 3, 2017 - 12:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An LED when exposed to light will generate a voltage, try connecting an ordinary LED to a voltmeter and point it at a light source (sun works well) and see it generate 1-2 volts.

I would guess this circuit is connected to either the analog comparator or ADC input on your chip and the pot adjusts the threshold light level to trigger the reaction you want.

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

An LED when exposed to light will generate a voltage, try connecting an ordinary LED to a voltmeter and point it at a light source (sun works well) and see it generate 1-2 volts.

I would guess this circuit is connected to either the analog comparator or ADC input on your chip and the pot adjusts the threshold light level to trigger the reaction you want.

Indeed, the green LED generates over 1.5 V under the strong light (I don't have a working UV LED at the momet to test it, the one from the device doesn't work). I wasn't aware the generated voltage can be that high - I thought it would be just a few mV :-/

 

But how exactly the potentiometer adjusts the threshold? It looks as the LED is in a half-opened state where forward voltage over the diode is lower than Vf and the voltage caused by the light is superimposed to the voltage caused by the current? Maybe the presence of light can that way be detected even by using just a digital input instead of ADC?

Chupo_cro

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you sure your UV LED is in fact an led, or could it be a phototransistor instead?

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you are going to rebuild the circuit, why not just build your own from scratch.

 

Select an AVR with at least 2 ADC inputs.

 

Test your LED under several different light conditions, with several different resistors connecting the LED to Vcc, (Not to the Pot).

Have the Resistor and LED form a simple voltage divider, with the junction going to the ADC input.

See roughly what resistor works well for your LED and the range of lighting you want the circuit to work with.

(10K, 50K, 100K, 250K 500K, etc., this isn't critical)

 

Connect a 10K pot from Vcc to ground, wiper to another ADC input.

 

If you want a Day/Night option, use a switch and the internal pull-up resistor as an input to another pin.

 

Now it is just a  matter of writing the software to read the inputs and do as you wish, controlling an output pin.

 

If you are going to purchase parts, you might just get a photocell or photo transistor as the sensor, instead of using the LED.

 

A $3 USD Nano clone from Banggood Electronics, or elsewhere, would work well for this.

The micro comes pre-mounted to the PCB, and the board includes a power supply and an LED for use as an output for testing your code, etc.

 

JC

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
Are you sure your UV LED is in fact an led, or could it be a phototransistor instead? Jim

Now that you ask - I can say it is a LED based only upon visual inspection. The component tester says: 'No, unknown or damaged part', and there wasn't a current when I connected the element as a LED + resistor. I looks like a LED to me but so does a phototransistor :-/ I haven't thought of that until now that you said.

 

Seems as I'll have to experiment with the circuit using both UV LEDs and phototransistors trying to determine which one was really used.

Chupo_cro

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:

If you are going to rebuild the circuit, why not just build your own from scratch.

 

Select an AVR with at least 2 ADC inputs.

 

Test your LED under several different light conditions, with several different resistors connecting the LED to Vcc, (Not to the Pot).

Have the Resistor and LED form a simple voltage divider, with the junction going to the ADC input.

See roughly what resistor works well for your LED and the range of lighting you want the circuit to work with.

(10K, 50K, 100K, 250K 500K, etc., this isn't critical)

 

Connect a 10K pot from Vcc to ground, wiper to another ADC input.

Do you mean to have the second ADC input for reading the threashold? Why using two ADCs - one for reading the signal and the other one for reading the threshold when the same functionality could be done with just one ADC input as in the original circuit (I might add a few more jumpers for configuring the device so I'll need that pin too)?

 

BTW, do you thing it woul not be possible to set the operating point so the dark/light could be determined by using just a digital input?

 

DocJC wrote:
If you want a Day/Night option, use a switch and the internal pull-up resistor as an input to another pin.

 

Now it is just a  matter of writing the software to read the inputs and do as you wish, controlling an output pin.

 

If you are going to purchase parts, you might just get a photocell or photo transistor as the sensor, instead of using the LED.

 

A $3 USD Nano clone from Banggood Electronics, or elsewhere, would work well for this.

The micro comes pre-mounted to the PCB, and the board includes a power supply and an LED for use as an output for testing your code, etc.

I might rebuild everything from scratch but I'd like to know how the original circuid worked as well.

 

I already have a bunch of mini AVR PCBs made by myself and I have quite a few ATmega8, ATmega328, ATtiny13, ATtiny861, ATmega128 etc. µCs (some of them are SMD) so the hardware is not the problem. The most important requirements are small footprint and low power because it is a battery powered circuit.

Chupo_cro

Last Edited: Mon. Sep 4, 2017 - 11:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just to note that there's been quite a few threads here over the years about using LEDs as sensors so probably worth searching those out.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Chupo_cro wrote:
I wasn't aware the generated voltage can be that high

Funny story:

An engineer wanted to buld a battery poered uC circuit and to save battery power he switched the led outputs to inputs when the led's were off.

When out in the wild he had a lot of premature dead batteries.

His led's were sometimes generating enough voltage that the inputs came in the lineair region and drained the batteries.

 

And murphy:

Some time ago I wanted to demonstrate the voltage generating properties of a led and it didn't work. I would only get a fev mV out of it.

A week later I couldn't let it rest and tested a lot of different leds.

Some only got to a few mV, others reached (nearly?) 2V.

Led's are not optimised for this, so results will vary.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Paulvdh wrote:
Led's are not optimised for this, so results will vary.

Absolutely - so why mess about with this? 

 

Why not just use a proper light sensor?

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

 but I'd like to know how the original circuid worked

 

The original circuit is a hack.

Cute, but not what I'd consider an eloquent design...

 

The three resistors on the left, 1K, 10K pot, and 4.7 K form a voltage divider.

The output voltage is available at the wiper of the pot.

 

If one simply connected the 10K pot to Vcc and to Ground, then the output would swing from +5 to 0 volts for the full wiper range of rotation.

 

If one wanted to very carefully adjust the pot for a specific voltage, e.g. 3.27 volts, or whatever, then it is very difficult to do this.

The rotation of the pot is very sensitive, 5 V / 300 degrees turn, and it is hard to set it for exactly the desired voltage.

 

The upper and lower resistors decrease the effective range of the pot.

If the upper and lower resistors were also 10K, then the example is easier.

The Pot output voltage would then only swing from 2/3 Vcc to 1/3 Vcc.

 

It is now much easier to set the pot to an exact voltage, as the rotation is only 1/3 the number of volts / degree rotation.

 

It is left as a project for you to determine the Vout with the current resistors.

Hint:  The output will be almost Vcc and extend down to about 1/3 Vcc, now you do the math to prove me right or wrong!

 

Back in the day, when more signal processing was handled in the analog domain, and less of it done by software, it wasn't uncommon to have a 100, 200, or 500 ohm pot in the middle position, to allow one to very finely set an exact voltage reference.  This was fine for expensive equipment and one-off lab gear, but doesn't work for mass produced devices where one doesn't want to manually calibrate a board full of pots for each one off the production line.  Now days one can use an "extra" ADC channel to read in a reference signal and autocalibrate many analog signals.

 

Next, the voltage, once set by the pot, is a relatively low impedance voltage source compared to the 470K resistor and "LED". 

(Which,  truth be known, is probably a photodiode.)

 

The pot then sets the operating voltage for the resistor & "LED" combination.

 

As the "LED" changes its resistance as a function of the ambient lighting, the 470K resistor and the "LED" also form a voltage divider whose output voltage is a function of the light level.

 

The overall "operating point" for the resistor and "LED" combination  is set by the pot circuitry, to adjust the output voltage for a given light range.

 

The input to the micro could be a simple digital I/O pin, an analog comparator, or an ADC.

Any of them could be used to trip the output as a function of the applied signal, (and hence the ambient light).

 

For a mass produced, cheap, low precision and reproducibility required device a simple digital I/O on a supper cheap chip could be used.

 

In this day and age of cheap 6 and 8 pin micros with ADC inputs, splitting the design with the Pot setting the threshold and the sensor input being read on a second ADC input would be a reasonable approach.

 

"Better" approach or not?

Depends upon the exact project requirements.

 

JC

 

Edit:

Why is it a Hack instead of a clever design?

The fact that the designer combined the Threshold and Signal into one input implies that the chip used a simple digital I/O as the input.

The Analog part is a clever design, and although the sensor changes the voltage of the voltage reference, the sensor stage is 2 orders of magnitude higher resistance than the voltage source stage, so one can easily compute the percentage error of this factor, and ignore it for a low precision, low cost device.

The reason it is a hack is because, depending upon the actual micro, and its digital input circuitry, it might well not have liked being operated in the linear range for extended periods of time, which may well have contributed to the circuit's early demise.

 

You get what you pay for!

 

JC

 

 

 

 

 

Last Edited: Tue. Sep 5, 2017 - 04:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
In this day and age of cheap 6 and 8 pin micros with ADC inputs ...

Not to mention widely-available, low-cost light sensors - with properly defined & specified properties & performance ...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Just to note that there's been quite a few threads here over the years about using LEDs as sensors so probably worth searching those out.

Yes, I am aware of those threads. I have TR2003-35.pdf doc by Mitsubishi labs for quite a long time on my hard disk. The origin of my confusion was the fact the element used to sense the light in the circuit I was analysing was not an UV LED as I thought. I now believe it is a phototransistor as photodiodes need to be reverse biased.

Chupo_cro

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Paulvdh wrote:

Funny story:

An engineer wanted to buld a battery poered uC circuit and to save battery power he switched the led outputs to inputs when the led's were off.

When out in the wild he had a lot of premature dead batteries.

His led's were sometimes generating enough voltage that the inputs came in the lineair region and drained the batteries.

Interesting story and a valuable information, thank you!

Paulvdh wrote:

And murphy:

Some time ago I wanted to demonstrate the voltage generating properties of a led and it didn't work. I would only get a fev mV out of it.

A week later I couldn't let it rest and tested a lot of different leds.

Some only got to a few mV, others reached (nearly?) 2V.

Led's are not optimised for this, so results will vary.

That was exactly why I thought LED would produce just a few mV. Because I remembered when I measured the voltage of ultra bright blue LED under the light and it was just a few mV.

Chupo_cro

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Absolutely - so why mess about with this? 

 

Why not just use a proper light sensor?

Although I do have 90+ LDRs out of the pack of 100 I bought some years ago which work very well, I think they are not as suitable for outdoor application as 'the element looking like LED' which I now believe is a phototransistor. Maybe I am wrong but LDRs seem not to be resistant to the humidity as the sealed element. I thought that was the reason the UV LED was used instead of LDR but now that I know it wasn't a LED I will certainly use more appropriate element.

Chupo_cro

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Chupo_cro wrote:
 I measured the voltage of ultra bright blue LED 

Remember that some of the more "esoteric" modern LEDs these days work by phosphorescence ...

 

But the key takeaway here is that using an LED as a photo-detector is relying upon unspecified behaviour.

 

While this can be an interesting novelty, it is not a sound basis for a good engineering design!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Chupo_cro wrote:
LDRs seem not to be resistant to the humidity

That's nothing specifically to do with LDRs.

 

LDRs had been widely (almost universally?) used in outdoor "dusk-til-dawn" sensors for many, many years.

 

As with any component, you need to get one that is properly specified (that word again!) for the conditions in which it will be used.

 

And/or use it in a suitable enclosure to provide the necessary environmental protection ...

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:

The original circuit is a hack.

Cute, but not what I'd consider an eloquent design...

 

The three resistors on the left, 1K, 10K pot, and 4.7 K form a voltage divider.

The output voltage is available at the wiper of the pot.

 

If one simply connected the 10K pot to Vcc and to Ground, then the output would swing from +5 to 0 volts for the full wiper range of rotation.

 

If one wanted to very carefully adjust the pot for a specific voltage, e.g. 3.27 volts, or whatever, then it is very difficult to do this.

The rotation of the pot is very sensitive, 5 V / 300 degrees turn, and it is hard to set it for exactly the desired voltage.

 

The upper and lower resistors decrease the effective range of the pot.

If the upper and lower resistors were also 10K, then the example is easier.

The Pot output voltage would then only swing from 2/3 Vcc to 1/3 Vcc.

 

It is now much easier to set the pot to an exact voltage, as the rotation is only 1/3 the number of volts / degree rotation.

 

It is left as a project for you to determine the Vout with the current resistors.

Hint:  The output will be almost Vcc and extend down to about 1/3 Vcc, now you do the math to prove me right or wrong!

 

My appologies for the delay, I had to prepare woods for the winter :-)

 

Yes, of course you are right:

 

Wiper at minimum: Uout = 4700/(4700+10000+1000)Uin = 0.299Uin

Wiper at maximum: Uout = 14700/15700)Uin = 0.94Uin

 

470k + light sensing element can be ignored because of much higher resistance.

 

So, the two resistors around the potentiometer are to increase the resolution (sensitivity) to be able to set the threashold more precisely (precise?).

 

DocJC wrote:

Back in the day, when more signal processing was handled in the analog domain, and less of it done by software, it wasn't uncommon to have a 100, 200, or 500 ohm pot in the middle position, to allow one to very finely set an exact voltage reference.  This was fine for expensive equipment and one-off lab gear, but doesn't work for mass produced devices where one doesn't want to manually calibrate a board full of pots for each one off the production line.  Now days one can use an "extra" ADC channel to read in a reference signal and autocalibrate many analog signals.

 

Next, the voltage, once set by the pot, is a relatively low impedance voltage source compared to the 470K resistor and "LED". 

(Which,  truth be known, is probably a photodiode.)


Would't a photodiode be reverse biased?

DocJC wrote:

The pot then sets the operating voltage for the resistor & "LED" combination.

 

As the "LED" changes its resistance as a function of the ambient lighting, the 470K resistor and the "LED" also form a voltage divider whose output voltage is a function of the light level.

 

The overall "operating point" for the resistor and "LED" combination  is set by the pot circuitry, to adjust the output voltage for a given light range.

 

The input to the micro could be a simple digital I/O pin, an analog comparator, or an ADC.

Any of them could be used to trip the output as a function of the applied signal, (and hence the ambient light).

 

For a mass produced, cheap, low precision and reproducibility required device a simple digital I/O on a supper cheap chip could be used.

 

In this day and age of cheap 6 and 8 pin micros with ADC inputs, splitting the design with the Pot setting the threshold and the sensor input being read on a second ADC input would be a reasonable approach.

 

"Better" approach or not?

Depends upon the exact project requirements.

 

JC

 

Edit:

Why is it a Hack instead of a clever design?

The fact that the designer combined the Threshold and Signal into one input implies that the chip used a simple digital I/O as the input.

The Analog part is a clever design, and although the sensor changes the voltage of the voltage reference, the sensor stage is 2 orders of magnitude higher resistance than the voltage source stage, so one can easily compute the percentage error of this factor, and ignore it for a low precision, low cost device.

The reason it is a hack is because, depending upon the actual micro, and its digital input circuitry, it might well not have liked being operated in the linear range for extended periods of time, which may well have contributed to the circuit's early demise.

 

You get what you pay for!

That was the theory of operation that I was looking for - thank you very much! BTW, the values I measured from unsoldered potemtiometer are:

 

Upper end to wiper: 4.28k

Lower end to wiper: 7.4 k

 

I measured upper to lower end as 11.45 k which is not exactly 7.4+4.28 but the error is not too big. From these valued the wiper voltage is:

 

Uwiper = (4700+7400)/(4700+7400+4280+1000)Vcc = 0.696Vcc

 

which really might be the operating point around VIH (input high voltage) of the µC.

 

In the meantime I unsoldered the unknown element (for which I thought it was an UV LED) and measured its resistance under various light conditions. When it is dark, the resistance goes up to about 20 MOhm and under the strong light (XML-T6 from just a few cm) the resistance drops even to zero.

 

I also oredered 'something' that was listed as 'photodiode' but marked as PT204-6C which is NPN phototransistor :-/ This is the listing and the package already arrived so I measured the element the same way I measured the element from the circuit. The element is not as in the picture but is dark as the upper element in this picture and the resistance reaches 20 MOhm even when it is still not completely dark - and under the strong light the resistance is about 1 - 2 MOhm.

 

With such a high resistance of an element I will have to put at least 1 MOhm to form a voltage divider meaning the output resistance of the circuit going into ADC will be to high so the measured values would be very noisy. I am thinking of adding a resistor in parallel to the PT204-6C to lower the resistance in order to be able to use lower resistance in a voltage divider.

 

I'd like to use some element with max resistance (in dark) under 20 MOhm because it is even not easy to masure voltages of such high resistance circuits because digital voltmeter has internal resistance of only about 10 MOhm.

Chupo_cro

Last Edited: Mon. Oct 2, 2017 - 02:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's the trouble with buying stuff like that!

 

That's why it's cheap!

 

Buy proper, fully-specified, fully-documented parts from a reputable distributor!

 

The element is not as in the picture but is dark

So what you've got is probably an Infrared Receiver.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

That's the trouble with buying stuff like that!

 

That's why it's cheap!

 

Buy proper, fully-specified, fully-documented parts from a reputable distributor!

I always buy critical components here, every item is always fully documented and the package containing detailed invoice, taxes, bills, return forms, ... despite being sent from another country arrives at my doors in within 48 hours. But in this case I was not willing to pay $10+ shipping for just a few phototransistors.

awneil wrote:

The element is not as in the picture but is dark

So what you've got is probably an Infrared Receiver.

You are right, the elements indeed are IR receivers. I connected the resistor + element voltage divider output to ATmega328 ADC and wrote short program for sending ADC results to RS232 four times per second and although the element does sense the visible light, the signal swing is too small. However, when I tried to use an IR TV remote instead of a flashlight, the signal swing was excellent. With 1 MOhm+470k resistors in the divider and visible light, 'dark to bright' signal was 1023 to 1010, which could barely be useful to detect light. Only when I used very bright flashlight from only a few cm the ADC results dropped to about 550. Ironically, I could much more reliable detect the light by using an ordinary 5 mm green LED (reverse biased, of course) in the place of that IR receiver :-)

 

However, I then used 10k resistor + LDR (which works very well, ADC 'dark to bright' signal swing is 1023 to 0) and tested if LDR is resistant to water - and was surprised to see an ordinary $2.5/100 pcs LDR is waterproof. The readings were exactly the same even when LDR was completely covered with water and the results are very reliable - seems as the results could be used even without averaging.

Chupo_cro

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

That's the trouble with buying stuff like that!

 

That's why it's cheap!

 

Buy proper, fully-specified, fully-documented parts from a reputable distributor!

 

So what you've got is probably an Infrared Receiver.

In fact, the elements I got do work according to the specifications. From the datasheet:

 

Applications

 

- Infrared applied system
- Camera
- Printer
- Cockroach catcher        <---- ??

 

Peak sensitivity is at 940 nm so it seems the only difference between the datasheet and the elements I received is the type of the epoxy. I didn't measure the other parameters but since PT204-6C is designed for infrared applications then the elements work as expected. It was my fault to order PT204-6C which is not suitable for my application. Or maybe it is, I still didn't test it outdoors where light spectrum is different.

 

I am still looking for a phototransistor which looks exactly as a LED and can be used with visible light because I am curious which model was used in the original design. Most of the phototranistors I can find online look different. Collector and emitter of this element look exactly as anode and cathode of an ordinary LED.

Chupo_cro

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Any phototransistor can be used in visible light, before Radio Shack went belly up I used one of theirs for an ambient light sensor.

 

Jim

 

EDIT:  I found one in my stores.  It's a standard NPN InfraRed Phototransistor with peak sensitivity at 850nm.  I have it connected to an op-amp circuit to give me a large enough voltage fluctuation the ADC in an AVR can work with.  Even though it's an IR device, it works just fine in indoor lighting.

 

 

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

Last Edited: Fri. Oct 6, 2017 - 02:19 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There’s also photodiodes to consider - there’s a few on digikey that have a led package.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And, as noted in #10, there are specifically-designed light sensors - which can give you a direct digital output, or a ready-conditioned analogue output