# How can you turn perceived brightness (log scale) into a linear analog output using an LDR? This question is not about how to make illuminance (in lux) a linear function of voltage! It's about linearly representing the human perception of brightness, which itself scales logarithmic to the unit lux and is not equal to lux.

TL;DR: How can you transform the resistance of a light dependent resistor (up to 2MΩ) to an analog signal, so that it reflects the logarithmic growth in resistance as a (more or less) linear output?

First of all: Although the relationship between Lux and LDR resistance is inversely proportional (see Figure 4 from datasheet), light intensity itself is perceived logarithmically.

• Night sky: ~0.1 lux (=1MΩ)
• Fullmoon: ~1 lux (=100kΩ)
• Dark indoors: ~80 lux (=10kΩ)
• Living room: ~600 lux (=2kΩ)
• Overcast sky: ~1.000 lux (=800Ω)
• Bright sunlight / clear sky: ~50.000 lux (=40Ω)

But so far the typical usage of an LDR in a voltage divider has served me well. I can measure quite a big range with a 10bit ADC. The only downside is that it has an "increased resolution" spot around resistances similar to the fixed RS value, while magnitudes further out are getting more and more inaccurate. This kind of "focal length" property might even be useful in situations where you want to specialize in a certain lux range (e.g. window light dependent LED dimmer). But as an academic question, I would like to know how to turn this curved measurement into a more linear output.

• Turning the full range between 1 and 100,000 Lux into a linear output voltage may be a problem. If you assign 1 mV to 1 Lux you will get 100 V for 100,000 Lux. Bright sunshine at a clear day in summer may be about 100,000 Lux.
– Uwe
Apr 13, 2022 at 14:20
• You seem to be getting several answers that are trying to make the output (in volts) a linear function of illuminance (in lux), when what you seem to actually want is an output proportional to the logarithm of illuminance (to better approximate the more or less logarithmic lightness perception of the human eye), and I suspect your question title is contributing to the confusion. Rephrasing it as something like "How can I get an (approximately) logarithmic analog voltage vs. illuminance response from an LDR?" might help. Apr 13, 2022 at 21:24
• (Or, given that you've used the arduino tag, perhaps a more appropriate rephrasing might be something like "How to connect an LDR to an ADC to measure illuminance varying by several orders of magnitude?") Apr 13, 2022 at 21:31

Consider something like this, which uses about 25 cents worth of parts: (as mentioned in the comments it would be better to keep the transistors together or use a co-packaged dual transistor, though only partial temperature compensation is provided). simulate this circuit – Schematic created using CircuitLab

It has an output that varies from about

500mV (630mV @ 0°C to 360mV @ 50°C) for 1M$$\\Omega\$$ resistance to

1.1V (1.18V @ 0°C to 1.01V @ 50°C) for 100K$$\\Omega\$$

1.6V (1.65V @ 0°C to 1.57V @ 50°C) for 10K$$\\Omega\$$

2.11V (almost zero and slightly reversed temperature coefficient) for 1K$$\\Omega\$$

2.62V (2.57V @ 0°C to 2.67V @ 50°C) for 100$$\\Omega\$$

2.82V (2.76V @ 0°C to 2.88V @ 50°C) for 40$$\\Omega\$$

Of course you could attempt to measure the temperature and correct for the varying drift in firmware, but maybe this is close enough (the LDR will have temperature sensitivity - I believe maybe 2:1 or more over the 0~50°C range, and tolerances in excess of +/-50% are not unusual to begin with- they are not precision devices).

## Explanation- the R1/R2 divider maintains a constant 100mV (derived from the power supply) across the LDR. The voltage is chosen to keep the maximum current in the LDR reasonable (2.5mA) while still giving a decent signal.

The feedback current is passed through diode-connected Q1 which gives a logarithmic (though temperature-sensitive) voltage at the output of OA1.

Q2 and R3 produce a voltage to offset the output of OA1 and to provide partial temperature compensation, it is buffered by OA2 and then subtracted with gain via OA3 to give a high enough voltage that the ADC gives reasonable resolution without saturating the LM324s (which can reliably produce up to 3V output).

Diode-connected transistors are used rather than 1N4148 etc. because they have a more ideal voltage/current curve ($$\\eta\$$=1 rather than about 2 for silicon signal diodes).

• Is the difference wrt Q2 there for temperature compensation reasons? If so maybe suggest a co-packaged dual BJT Apr 13, 2022 at 17:41
• @tobalt Yes, it might be better to have a co-packaged part or at least to keep them together. It's also to subtract off an offset to maximize the range. Apr 13, 2022 at 17:44
• Ah I got it. Similar like bode plot, which needs to cover wide range of frequency. OA1 needs to be logarithmic amplifier because the LDR has a very wide range of resistance, from ideally near zero to near inifinity. And in order to cover all of it, without loss of information, it will be practical to encode it in the form of virtually straight linear line, as shown in the log-lin plot. After the circuit has been made, you just need to calibrate it with industrial lux meter. Nice. Apr 15, 2022 at 14:45
• Wait, why the cathode of "diode" or emitter of Q1 facing towards the LDR instead of the op amp output? Apr 16, 2022 at 7:48

The log-log characteristic of the LDR is mentioned as the problem to be solved but, within the question, the change in resolution seems to be the actual problem.

If linearity was really the main problem, the voltage divider approach would not be the best one, as it also adds another non-linearity. A possible solution to this would be an op-amp based current source.

If the application really demands better resolution throughout the 6 orders of magnitude input resistance range, an auto-range feature would probably work better. This could also be achieved with the current source solution and removing the log-log behavior in the software is a lot simpler and more reliable/stable.

• "auto-range feature": am I assuming right that you mean some type of (smooth or stepped) gear shift solution for the fixed resistor, to actively move around my so called "increased resolution" spot. Pro: more accurate; Con: requires active feedback... Interesting, the famous XY problem strikes again. Apr 12, 2022 at 20:59
• @NiklasE. Yes. If you decide to go with a voltage controlled current source you could change the range with a DAC, so the feedback you mention would be complete since you already read the resulting voltage with the ADC. If many ranges are needed, maybe you also need to "change" the resistor (a small mosfet controlled by an IO would do it) used at the current source. Apr 12, 2022 at 21:27
• Yeah, or I don't do that and just take a 470kΩ resistor and optionally switch on 12kΩ or 270Ω in parallel using NPN transistors... enough accuracy for me. (250Ω is the abs. lowest I can go with the 50mW limit of the LDR, but that should be ok) Apr 12, 2022 at 21:47
• Sure. It is a good compromise. You could even read the saturation voltage of the BJT to improve the measurement, if needed and if there are a few ADC channels available. Apr 13, 2022 at 14:23

LEDs are very linear in brightness vs current so you can use an LED and a second LDR with an op-amp to linearise the reading. Q1 here is boosting the output current to the led.

output is by sensing the voltage across R1, and hence the current through the led simulate this circuit – Schematic created using CircuitLab

if you want to go all the way to sun brightness you'll probably need a 3W led upgrade Q1 to something that can bolt to a heatsink, and use 1 ohm for R1.

• I'm not actually convinced that LDRs are logarithmic, I think they are actually linear in conductivity vs illumination so a simpler circuit can probably be used, Apr 13, 2022 at 5:45
• I'm not saying LDRs are logarithmic in conductivity per lux (or photons hitting), they are linear. But although the SI unit Lux itself is not a log scale, luminescence is perceived as such by humans. Sound has the same problem, but for that we use a log scale: "Decibel" Apr 13, 2022 at 7:52
• Seems legit in theory. But I'm not really happy about the idea to use an LED as an anti-log device. The voltage/current anti-log capability is totally wrecked by temperature-related deviations. 5°C and fundamentally different measurements. Apr 13, 2022 at 12:04
• not understanding the meaning of the question this circuit will produce a result that is linear in volts per lux. if you want perceived brighness you need some sort of gamma function. Apr 13, 2022 at 21:09

Instead of linearizing, I'd use an analog to digital conversion with a wide enough range to cover what you need.

A good candidate would be a comparator relaxation oscillator that turns a resistance into a frequency. All you need is a comparator, two resistors, and an accurate cap.

This can be input into a microcontroller timer to measure the frequency.

• This. Just achieving any semblance of resolution at the ends of the six-orders-of-magnitude wide range requires a 24-bit ADC. And that's before taking noise into account (good luck distinguishing that one extra microvolt that corresponds to twice the light at night). In contrast to that, a 32-bit counter is trivial. (Any nonlinearity can be corrected for in software.) Apr 13, 2022 at 8:40

LDRs aren't logarithmic.

$$\ R = R_{10}\left(\frac{10\ \mathrm{Lux}}{E}\right)^\gamma \$$

$$\R_{10}\$$ is the resistance at 10 Lux, $$\E\$$ is the illuminance and $$\\gamma\$$ is a "constant" usually between 0.5 to 1 (citation needed).

To get a fairly linear response, you can apply a constant voltage across the LDR and measure the current through it. simulate this circuit – Schematic created using CircuitLab

Example design (with free bugs) - my website: https://oskog97.com/projects/light-sensor/light-sensor-part-1-design.pdf#page=39

Measurements - my website: https://oskog97.com/projects/light-sensor/light-sensor-part-2-testing.lowres.pdf#page=29 (really begins at page 24)

• "LDRs aren't logarithmic." They aren't logarithmic in conductivity per lux (or photons hitting), they are linear, as I said "indirectly proportional". But although the SI unit Lux itself is not a log scale, luminescence is perceived as such by humans. Sound has the same problem, but for that we use a log scale: "Decibel" Apr 13, 2022 at 7:56
• Your PDFs are actually mentioning this problem first in Part 1 7.2 Problems with digital: "The variable hysteresis is not well designed; it’s very asymetric and depends heavily on the trigger level." and "P9 could be larger (...) and logarithmic, R25 could be twice as large. There is an insane amount of hysteresis." Great PDFs tho! Apr 13, 2022 at 8:07

You could do it in software, or with hardware you could probably use an anti-log circuit. The problem would be where the curve changes direction.

I think that you could offset it to make the mid-point 0 V, have a circuit to detect the sign of the voltage and an absolute value circuit. Run the absolute value through an anti-log and then multiply by the sign.

OK, I guess what you want is an analog signal representing the logarithm of the illuminance. The graph indicates (conductance) ∝ (illuminance)^0.6, not linear. What I would do is bias one end of the detector with a fixed voltage, measure the current to "ground", and then extract the log of that current as a voltage using a diode. The power-law nonlinearity then simply becomes a scale factor multiplying the logarithmic output.

Sounds easy, but there are serious subtleties. Fortunately, this is a fairly common problem, and there are "logarithmic amplifier" chips that do this. An example is the LOG101.

On the other hand, if your ADC input has a nice high impedance, you could simply do the "poor man's" version: simulate this circuit – Schematic created using CircuitLab

This will add a bit of nonlinearity and temperature sensitivity. Unless you calibrate these out, it's probably only good to 30% or so as an absolute photometer. That's still far better than the human eye is at photometry.

• As I mentioned under @Jasen's answer: Seems legit in theory. But I'm not really happy about the idea to use an diode as an anti-log device. The voltage/current anti-log capability is totally wrecked by temperature-related deviations. 5°C and fundamentally different measurements. Apr 13, 2022 at 16:10
• @NiklasE. Hardly "totally wrecked" relative to a measurement intended to reproduce human perception. Temperature compensation is certainly possible: the chip implementations do it by using two diodes. Apr 13, 2022 at 16:30
• @NiklasE.It comes down to requirements. No requirements are stated in the question, and the reference to human perception suggests very relaxed requirements. The LOG101 has very tight specs if needed. But a signal diode might be just fine. Apr 13, 2022 at 16:39
• A 30% temperature-dependent swing on a log scale means totally wrecked. @SpehroPefhany's design uses much more sophisticated methods (anti-log op amp, diode-connected BJT, ...) and has a decent usable precision to it (barely decent on a 0°-50° range). The pseudo requirement is to be better then my 1kΩ voltage divider. This is worse (even amplified). I tested it. Just tipped the diode with a finger shortly... Apr 13, 2022 at 16:57
• @NiklasE. I bet my old CdS photographic light meter isn't good to 30%, but it was useful back in the day. If you need better, go with SpehroPefhany's design, or even better, easier, but pricier, get a LOG101 (which is essentially the same thing integrated and precisely calibrated). Apr 13, 2022 at 17:07

Using WebPlotDigitizer to extract the data points from the graph I can plot the conductivity vs illumination. We see that the data is an extremely good fit for the conductivity being linearly proportional to LUX with a small offset of 40mOhms in the resistance.  But as an academic question, I would like to know how to turn this curved measurement into a more linear output.

In that case don't use the LDR as a voltage divider. Use it with an op-amp in a standard photodiode amplifier setup. You will then get a voltage that is linearly proportional to indecent light (See OA7 in the circuit below).

Human perception of brightness is logarithmic. So, if you wish to transform your linear sensor output so that it matches human perception, you would use a "LOG AMP".

Temperature stable log-amps can be purchased as off the shelf microchips.

The TL441CN is one example.

Or you can make one using standard op-amps. simulate this circuit – Schematic created using CircuitLab

The log amp consists of three parts.

1. A fixed voltage is placed across the LDR ot get a current proportional to LUX. OA7 converts that current into a voltage. Its a standard photodiode amplifier setup.

2. OA7 feeds a chain of non-inverting amplifiers that are cascaded together. Lets say we want to measure brightness between 0.1 LUX and 10K LUX (five orders of magnitude). We could then (arbitrarily) pick that we will use five stages each with a gain of 10. We could have also used 10 stages with a gain of sqrt(10). It just depends on how accurate you want to get.

3. Finally OA6 sums up the output of all stages.

Lets say we want 10,000 LUX to output +3.3V. Lets assume all the opamps are "rail-to-rail" output and powered by ±3.3V. Maximum output occurs when all five stages saturate and output -3.3V each. We have five stages going into the summing amplifier OA6. In that case we choose R18 = 20K so the summing amplifier has a gain of 1/5.

At 10,000 LUX the LDR has a resistance of 100 ohms. So the current in the LDR will be 3.3V/100 ohms = 33mA. Since this is the highest level we wish to measure, we want 33mA to generate an output on OA7 that just barely causes OA1 to start saturating. This will occur when the input is -3.3V/G = -0.33V (with G=10). Therefore R17 = 10 ohms.

The general equation for this circuit is VOUT = C * LOG10(LUX)

In this particular case 3.3V = C * LOG10(10000). So C = 3.3V / 4.

VOUT = 0.825V * LOG10(LUX)

Note that the op-amps in the circuit need dual supplies to work (+3.3V and -3.3V).

Also note that you must pick op-amps with very low input offset voltage. Ideally something much less than 3.3V / 100000 = 33uV.

Something like the TLC2652IN with a 3uV offset might be appropriate.

• @NiklasE. I mainly included that graph to put to rest the question of whether it was linear or not, since a lot of people were assuming it was logarithmic. Apr 14, 2022 at 0:13