Is there a way to "linearize" a photoresistor output? - Page 1
Forum section: electronics / beginners

author: Faranight
author_rank: Unknown
timestamp: January 02, 2022, 04:59:53 pm
content: Hi there.I'd like to measure ambient light by using aCdS photoresistor(got a bunch of them from ebay) on an Arduino. It doesn't have to be ultra-accurate, but I'd like to at least have similar precision across the full measuring range. I've already done some homework, and apparently the resistance of a light-dependent resistor is not linear, but rather falls exponentially as the illumination increases. Most circuits I googled show the LDR in series with another resistor to create a voltage divider between Vcc and GND, and the tap point in between them is connected to an ADC. The problem with this approach is that the ADC steps aren't equal. I know I could create a "gamma correction" curve in software, but I would rather measure a linear signal to begin with.I was wondering, if there is a circuit to "linearize" this output i.e. by using some op-amp wizardry? The circuit output should span from 0 to 5 VDC. The sensor minimum should be in a complete darkness like deep in an undergound cave without any light sources. In this case the circuit output should show 0V. The sensor maximum should be about the brightness of a small in-door room lit by a single 800 lumen light bulb. This value should appear as 5V on the circuit output. Anything brighter than that should be clamped at 5V. In other words I'd like a circuit that converts a signal from a device whose resistance decreases exponentially with increasing illumination to a signal thats voltage decreases (or increases) linearly with increasing illumination.Is something like this possible with a simple analog circuit? Or am I better off using some other sensor instead i.e. a photodiode?Thanks in advance.

author: Capernicus
author_rank: Frequent Contributor
timestamp: January 02, 2022, 05:08:33 pm
content: This is a case of its really easy to do it with an arduino, and then its extremely difficult to do it 70's style analogue.Take ur pick.

author: BeBuLamar
author_rank: Super Contributor
timestamp: January 02, 2022, 05:46:24 pm
content: You have the Andruino isn't that what it is for?

author: Ian.M
author_rank: Super Contributor
timestamp: January 02, 2022, 05:59:04 pm
content: Use the Arduino to switch in different value pullup resistors for different ranges of illumination level. Their 5V end can be switched directly by an I/O pin, by setting it from input (off) to output high, (on to 5V). You'll probably also have problems with the LDR + pullup potential divider's source resistance being too high for the ADC to operate well at low light level. While you could use a 5V RRIO OPAMP as a unity gain buffer (or even gain switch it by using an I/O pin to disconnect the bottom of the non-inverting configuration's feedback divider), high source impedance to the ADC can be partially mitigated by adding a capacitor to ground at the ADC pin of at least2(N+1)Cint(where N is the number of ADC bits and Cintis the value of its sampling capacitor), and reading the ADC twice with a delay in between, and discarding the first reading, whenever you change ADC channels.

author: george.b
author_rank: Frequent Contributor
timestamp: January 02, 2022, 07:35:03 pm
content: Since you're already using a microcontroller, the proper way to do it is to use a LUT or some other means of software linearization.That said, you could use an anti-logarithmic amplifier. I've attached a quick and dirty example, which isn't tremendously linear, nor is it temperature-stable. There are better, but more complex implementations, which is why it's normally desirable to do it in software if possible - you get results just as good or better, for cheaper.

author: BrianHG
author_rank: Super Contributor
timestamp: January 02, 2022, 08:32:58 pm
content: Light sensitivity for our eyes and these CdS isn't a linear process.Have you measured the 'full dark black' resistance of your cells?You need to place them in a thick black box with the edges and leads foam sealed to eliminate absolutely every photon possible.I know in the past, doing so, with the CdS I had on hand, they would achieve something like >10 megaohms after around a minute at room temperature in the dark. Yes, at low levels of light, these CdS get really slow. Then in sunlight, my photocells would reach something like <150 ohms. With a superbright red LED right in their face, I've got them down to around 50ohm.Using an opamp, you can expand the CdS resistance range to a voltage between 0-5v, but you will need probably 2 trimpot adjustments as each CdS will not match each other.I like Ian.M's idea of using different pull-up or pull-down resistors running multiple ADC cycles to generate a high resolution reading at different ranges, then calculate you 'linear' output from a software calibration for each CdS cell as they will all differ and you want to go from pitch black to sunlight with measurements withing the near pitch black. This is a huge span.

author: Kleinstein
author_rank: Super Contributor
timestamp: January 02, 2022, 09:25:07 pm
content: The light intensity can vary over a large span and the eye is more logarthmic than linear. So a limpe linear response is not even very disirabel with the limit 10 bit ADC. A curde approximation is intensity proportional to 1/ (resistance-R_limit).The sensor is slow and the µC is fast enough to do some math.Instead of a OP to buffer the signal, the ADC in the AVR is also OP with a capacitor (e.g. some 22 nF or 100 nF) from the ADC input to ground.Multiple resitors are indeed a good ideal to extend the range. In the very low light range with an added capacitor one could also use no active resistor and a delay to extend the range even further.