# Using LDR

Discussion in 'The Projects Forum' started by lordeos, Aug 19, 2015.

1. ### lordeos Thread Starter Member

Jun 23, 2015
33
1
Hi guys,

I want to start a simple experiment using an LDR to turn on a LED. But along the way i have some questions

1) When i read about LDR's they are used for dark/light detection and according their change of resistance. Mainly they are used to switch off lights during day for electricity reduction. But this part is unclear for me ...

- as i understand it during the day the resistance is low and the correct flows trough the LDR and not the Lightbulb/LED , so a current is flowing !!!. If i hook this up to a battery my battery would be drained even during the day. Am i correct or do i miss something ?

2) Calculating the resistance values. I found an article which explained how to calculate the fixed resistance value ... Square root (min value LDR * max Value LDR). In all the formula's i never see the amount of current that is needed in the circuit and based on that the calculation of the resistor.

- If my voltage ranges from for example 0 to 8 volts do i have to put a resistor in front of the LED to limit the amount of current (20MA for LED). Is the series resistor in front of the LED the one that decides how much current flows in the circuit ?

Thanks for the help
Mike

2. ### DerStrom8 Well-Known Member

Feb 20, 2011
2,428
1,333
Hi Mike,

In order for an LDR to be used to switch off a light during the day and switch it on during the night, the logic must be inverted. This is commonly done using a circuit like this:

When the LDR has a low resistance (in the light, during the day), the base of the NPN transistor is held close to ground (0V) and stays switched off. This prevents current from flowing through the LED.

In order to calculate the current limiting resistor for an LED, you must know the LED forward voltage drop. The formula is:

R = (Vs - Vf)/If

where R is the resistance you're looking for, Vs is the source voltage, Vf is the forward voltage drop of the LED, and If is the current (20mA for your LED). When using the above circuit, most of the current will be flowing through the current limiting resistor, through the LED, through the transistor (C-E), then to ground. You will have some current, however, flowing through the resistors at the left (above the LDR) whether the LED is on or off. Something to keep in mind. Running a circuit like this for an extended time off of batteries will indeed drain them.

3. ### lordeos Thread Starter Member

Jun 23, 2015
33
1
Hi derstrom8,

Thx for the detailed explanation. The circuit with the transist is also one of the circuit setups i encountered. However to begin with the project i'm looking at the most simple designs first (understand them) and the improve on them.

Currently i'm looking at this simple design (screenshot included as attachment "circuit.jpg"). Hence my question that in this design wether the LED is turned ON or OFF current is flowing in the circuit, either trough the top resistor and LDR or trough the LED, am i correct ???

But how much current is flowing in OFF mode trough the resistor and LDR ??since i never see the value of the resistor being calculated based on the amount of current. With a led a max of 20MA must go trough the circuit. so i believe i must put a resistor on the output infront of the LED ... Because with a 9V battery my range is from +- 0V trough 8.5 V --> the LED only takes 2V and 20Ma, Am i correct ??

thx for the help

File size:
12.5 KB
Views:
9
4. ### DerStrom8 Well-Known Member

Feb 20, 2011
2,428
1,333
The circuit you attached is not an on/off circuit. It is a voltage divider. The more light there is that hits the LDR, the closer to 0V the output voltage gets. The purpose of the transistor was to switch on at a specific output voltage from the divider. An even better option than the transistor would be to use a comparator, but that's a whole other animal. In your circuit, the output will range between (theoretically) 0V at full light (LDR resistance = 0 ohms) and

$image=https://latex.codecogs.com/gif.latex?Vout%20%3D%20Vs%5Cfrac%7BR_%7Bldr_%7Bmax%7D%7D%7D%7BR_%7Bldr_%7Bmax%7D%7D%20+%20R%7D&hash=dfebdb54972b314a9a5b80f9773e8736$

where Vs is the source voltage, $image=https://latex.codecogs.com/gif.latex?R_%7Bldr_%7Bmax%7D%7D&hash=257be235e15c87cb796f3af996044426$ is the maximum resistance of the LDR, and R is the value of the fixed resistor.

If you want to simply turn something on and off with the above circuit, you'll need to convert that analog voltage to a digital signal (either "ON" or "OFF"). That's what the transistor was used for.

5. ### lordeos Thread Starter Member

Jun 23, 2015
33
1
But if during dark the LDR has a high resistance and the voltage on the output rises to above the forward voltage drop of the LED then a current limiting resistor and LED directly attached to the output could be turned on, correct ?

If there is enough light the the voltage drops on the output to below the forward voltage drop of LED and the LED is turned OFF, correct ?

6. ### ian field AAC Fanatic!

Oct 27, 2012
5,455
970
Professional circuits usually use a Schmitt trigger circuit to give clean switching at dawn and dusk, if you used a relay with a non-Schmitt circuit, you'd have relay chatter problems at dawn and dusk. Unfortunately the web seems to be swamped with basic non-Schmitt circuits!

Somewhere I have a hand trace of a professional circuit, it uses an IR photodiode and apparently worked just fine like that.

AFAIK: the LDrs which contain cadmium sulphide are prohibited by the RoHS directive, they're getting pretty scarce. They're coming in from China via Ebay - I ordered a couple of packets while I still could.

7. ### DerStrom8 Well-Known Member

Feb 20, 2011
2,428
1,333
That is true, though that's really not a very good way to do it. I suppose if your fixed resistor is chosen well you could do it that way, but that will not give you the on/off functionality. As it gets darker out the LED will gradually grow brighter. This may sound like a good idea in some applications, but it will drain your batteries much more quickly because the LED will likely be "on" for a longer amount of time. It does not simply "switch on" when the forward voltage drop is reached, it will start off very dim. LEDs are current-driven devices, so you need a steady current to keep the brightness steady. Consider if the output from the voltage divider is 2.0V (let's just say the forward voltage drop of your LED is 1.7V), and you have a 100-ohm resistor. The current flowing through your LED would be:

(2.0V - 1.7V) / 100 ohms = 3mA

You would only have 3mA flowing through your LED, which probably won't even make it bright enough to see. Suppose your voltage divider goes up to 3V. Your current will be:

(3.0V - 1.7V) / 100 ohms = 13mA

The brightness will vary, even if you meet the forward voltage drop of your LED.

What exactly are you trying to do with this circuit? Generally if you want the output that is either full-on or full-off you'd want to use a MOSFET (not a BJT) or a comparator.

8. ### DerStrom8 Well-Known Member

Feb 20, 2011
2,428
1,333
Schmitt trigger = comparator.

I heard that as well, about LDRs. They are definitely becoming more difficult to find. I think they have a modern alternative that is RoHS-compliant, but I'm not sure. I'd have to do some research.

9. ### ian field AAC Fanatic!

Oct 27, 2012
5,455
970
A comparator doesn't become a Schmitt trigger until you add positive feedback.

The only alternative I can think of to Cd-S, is cadmium selenide - which is still based on the highly toxic cadmium.

There were lead and zinc photo sensitive materials, but they were no match for cadmium and were never very commercial.

For quite a long time, professional manufacturers have been adapting circuitry to get by with silicon detectors that are better suited to IR.

Somewhere I have a hand trace of a commercial "dusklight" outdoor lighting fixture that doesn't waste enenergy when the sun shines - it uses a fairly common photodiode similar to the ones in TV front panels for the remote, I think it uses a LM358 - one section set up as a comparator and some positive feedback to make it a Schmitt, the other section drives the triac gate.

The schematic was on this PC, but W10 search hasn't found it yet!

DerStrom8 likes this.
10. ### DerStrom8 Well-Known Member

Feb 20, 2011
2,428
1,333
Fair point. Guess I'm a bit rusty on my op-amp circuits

Hmm, I found this LDR that is still based on the CdS chemistry, but is RoHS-compliant:

http://www.digikey.com/product-sear...e=1&rohs=1&quantity=0&ptm=0&fid=0&pageSize=25

I suppose there's not enough in there to exceed the limits for RoHS. I doubt you'll be able to find a larger one that's also RoHS-compliant.

You're right, I'm not seeing any alternatives.

11. ### ian field AAC Fanatic!

Oct 27, 2012
5,455
970
RoHS is riddled with random exemptions - its entirely possible that a certain standard of encapsulation qualifies for an exemption, the ones out of China are usually plated onto a ceramic disk and given a coat of lacquer - a tiny scratch could expose toxic material.

Some months ago I found some on a mainstream suppliers website with a; "not ROHS compliant" warning notice.

DerStrom8 likes this.
12. ### lordeos Thread Starter Member

Jun 23, 2015
33
1
@DerStrom8

I got the idea with the change in brightness from the LED. In the circuit with a transistor wouldn't this be the same case. Since my output voltage varies from (theoreticcal) 0 tot 8 V my base current also constantly varies ?

- I suppose i also need a resistor in front of my transistor to drop to 0.7V, correct ? So i assume i calculate this resistor on the highest voltage available on the output ? , correct ?

Does the fluctuation in base current (output voltage going from 0 V tot +-Vs) effects the brightness of my LED ? --> with for example an transistor HFE of 100 the current trough my LED resistor will accordingly with the change in base current ?

thx

13. ### ScottWang Moderator

Aug 23, 2012
5,424
854
In series with a resistor between B of bjt and the common pin of 10K and LDR, that will more easy to turn off the bjt.

14. ### DerStrom8 Well-Known Member

Feb 20, 2011
2,428
1,333
To an extent, yes you are correct. It's difficult to use a BJT to turn something directly on or directly off using an analog signal on the base. That's why I was recommending a comparator, and Ian was suggesting a Schmitt trigger.

15. ### ian field AAC Fanatic!

Oct 27, 2012
5,455
970
Just off the cuff - for linear control of the LED by a LDR, maybe put the LDR in the emitter circuit of a single transistor current limiter.

At good light intensity, an LDR can get down to a few hundred Ohms, so you'd need a pretty high base voltage on the constant current transistor, or follow it with some form of current multiplier.

Its basically a common base stage, so the collector current will be just a smidge less than the emitter current, I'd suggest using a PNP emitter follower to give greater current capability to the voltage developed across the collector resistor.