0
\$\begingroup\$

I have a 2Mohm dark resistance LDR and i'm wondering what would be the best choice for the fixed resistor. If I made it too large then it would be very insensitive and if I made it too small then it would be very sensitive and draw more current which I heard can create more noise on the MCU ADC. What would be a good value to use ?, would 10k be fine ?

\$\endgroup\$
  • \$\begingroup\$ 10% of dark for sensitive threshold for dark level. \$\endgroup\$ – Sunnyskyguy EE75 Nov 12 '16 at 9:06
  • \$\begingroup\$ Do you want to just have a digital input used? Or are you preferring to use an ADC for this? \$\endgroup\$ – jonk Nov 12 '16 at 9:30
1
\$\begingroup\$

There are a number of approaches.

  1. Use the ADC together with the LDR and a capacitor and a way to reset the capacitor voltage, then gather many samples used to work out the exponential decay slope by linearizing the data and then using a least squares fitting (LSQ} routine to work out the slope and therefore the \$\tau\$. Doing so will require you to work out the offset (and subtract it) prior to performing the logarithm. Also, this requires a different treatment of the noise at low ADC values vs high ADC values, because there is a difference in influence of noise at low ADC values vs high ADC values and the typical LSQ fitting algorithm. It can be done, but it is complex to get right.
  2. Use a resistor divider. The price here is that the ADC values will bunch up on one end or the other of the ADC range, as the LDR goes over two to three order of magnitude change from light to dark. Working out a good approach here, together with the needed hysteresis, can itself be tricky. It's workable. But it poses difficulties, too.
  3. Use an opamp and a BJT to perform a logarithmic function to linearize the range. This works and provides a nice, linear voltage span over which the ADC operates while the LDR transits over its up-to-3 orders of magnitude change. But it means an opamp, of course.
  4. Go digital. Here, you design an analog circuit that provides the needed hysteresis and generates a digital output that is easily read by a digital input of an MCU.

I'm sure there are many more; as many as the imagination can create, in fact. But the above provides a quick overview pointing out that there are many ways to solve problems. You just have to pick your poison and go with it.


Here, I'll give you two different ways to approach this, both of which generate a digital output with hysteresis. Neither of these require an ADC. To start, both the left and right schematics are symmetrical and balanced. We'll need to add some positive feedback to produce the hysteresis to both. But for now, it's enough to just get the basic ideas:

schematic

simulate this circuit – Schematic created using CircuitLab

The left side is kind of like a flip-flop. The right side is more like a differential amplifier (long-tailed pair) and should be seen as a kind of teeter-totter that can tilt to one side or the other.

This leads to two different ways to add in the LDR:

schematic

simulate this circuit

The difference between them is just 5 resistors vs 6 resistors. The one on the left provides a clean output that spans the full range of the supply rail voltage. The one on the right provides a fairly clean output but it won't reach the supply rail. Either works fine. But the one on the left is probably better for a simple digital output and it uses one resistor less than the other. So probably better, overall, for something like this.

Using a simple digital I/O pin also saves you from messing around with an ADC. It's very cheap and easy to use (though not as cheap if you already have an extra ADC that isn't being used.)


So, using the left side circuit, it accepts an LDR and provides hysteresis. The circuit here is based on \$V_\text{CC}=5\:\textrm{V}\$ and will become active when the current rises above \$40\:\mu\textrm{A}\$ (when the LDR drops below \$100\:\textrm{k}\Omega\$) and will stay active until the current drives below \$15\:\mu\textrm{A}\$ (when the LDR rises above \$270\:\textrm{k}\Omega\$.)

schematic

simulate this circuit

Adjust \$R_5\$ to change the hysteresis -- a little lower or higher will be fine.

If you are using \$V_\text{CC}=3.3\:\textrm{V}\$ instead, change \$R_1\$ and \$R_2\$ to \$120\:\textrm{k}\Omega\$ and then adjust \$R_5\$ to suit your hysteresis range.

It has very nice, clean hysteresis and provides a very simple digital input value. And you can easily test it separately, using a voltmeter to measure the IO PIN output, before you commit yourself to something with the micro.


The alternative is that you use the ADC and set up a divider, like you mentioned. Or consider the ideas that Tony has suggested.

\$\endgroup\$
0
\$\begingroup\$
  • 10% of dark for sensitive threshold before dark level
  • or 5% of dark for sunrise detection
  • or 1% for bright light.
    These are just educated guestimates.

To correctly choose the best R, determine what comparator threshold or midpoint for an analog amp, the median LUX level you expect to see then I*R=Vthreshold to choose an R value.

1st define the task of the LDR , then the ambient light , thus Current then the R to determine the midpoint V or V threshold.

A photo diode is more accurate but gives less current and needs an Op Amp or transistor for gain.

I prefer the 5mm Panasonic Light sensor. It is accurate , cheap and only needs a 3 terminal LDO, load R and cap. and a comparator to accurately measure LUX threshold. It can be used as a LUX meter for a camera for example or a regulator for MPT control of a PV array to determine the optimum PV voltage as a current source. The Voltage is chosen by Light current and Load R is far more accurate than an LDR.

Unlike an LDR it has 3 1/2 decades of light range with high consistency between devices.

enter image description here

But then if you have an LDR use it with 100k for now.

http://www.digikey.com/product-detail/en/panasonic-electronic-components/AMS302/255-2655-ND/2125641

enter image description here

\$\endgroup\$
  • \$\begingroup\$ The problem with 3-4 decades of current range will be in arranging the ADC to handle it well. It was a pain handling 8 decades on a Hamamatsu (from below \$100\:\textrm{fA}\$ to \$7\:\mu\textrm{A}\$ max when some of the IC aluminum traces on the Burr Brown IC would start to migrate from the current.) Wonderful devices, of course. But a handful of decades is not entirely trivial. \$\endgroup\$ – jonk Nov 12 '16 at 10:16
  • \$\begingroup\$ Agreed. I found some problems with Mil-Std-883B old BB ADCs which had Agnd shift from Dgnd current causing deadspots on a 12 bit ADC. while most log amps on SA's have greater range. meanwhile this student is just trying to make something like a Night Lite and just needs to know the Ambient Lux level to determine the uA level amd comparator threshold to choose R within 1 decade of current range. definitely trivial. \$\endgroup\$ – Sunnyskyguy EE75 Nov 12 '16 at 14:07
  • \$\begingroup\$ I couldn't use log amps as they weren't linear enough in their logarithmic responses. We were providing pyrometry and required accuracy figures of \$50\:\textrm{mK}\$ after calibration with NIST traceable standards and repeatability between instruments about 10 times better than that. Over 8 decades! Expensive equipment. But uniquely good, too. Also had to be conscious of leakage -- the usual epoxy IC packages leak too much, pin to pin, even clean as a whistle. \$10^{11}\Omega-\textrm{cm}\$ isn't good enough. \$\endgroup\$ – jonk Nov 12 '16 at 18:01
0
\$\begingroup\$

The choice of resistor depends on the resistance of the sensor at the range of light you care about. If you are using the LDR as one resistor of a resistor divider, you get the most sensitivity at the light level where the two resistors are equal.

If you're worried about too much current draw, then consider sampling the sensor only occasionally. You don't say what the application is, so we have no way to know if this is appropriate. Drive the high end of the resistor divider from a digital output. Turn this on just long enough to take a A/D reading, then turn it off again. Let's say you sample the light level 10 times per second, and that it takes 20 µs each time. That means it will be powered up only 0.0002 of the time. Even if the sensor took a whopping 1 mA when on, the average current draw would be 200 nA.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.