PDA

View Full Version : LDR readings



Jeremy Leach
17-01-2006, 08:46
Just thinking...

One thing I've noticed using my simple LDR setup (resistor divider into Picaxe ADC input) is that I can't get sensitivity at both extremes of light and dark using a Picaxe ADC input.

At first I had quite a high series resistor. This was great at showing tiny fluctuations of light at night and the data plotted a very satifying curve of sunset/sunrise. However during the day it got 'saturated' quickly and didn't show the fluctuations due to cloud cover.

Lowering the series resistor improved the day situation, but took the sensitivity out of the night readings.

So, I'm thinking .... how about a controllable series resistor, so that the Picaxe can adapt the resistor to get the best sensitivity for the particular light level?

Just wondering what the easiest way would be to do this. Perhaps MOSFET switches to select a range (even just two) series resistors?

Also, this could lead to a general solution for anything being read into an ADC??

Any ideas welcome!

BeanieBots
17-01-2006, 10:07
LDRs do actually saturate, so the the first thing to do is work out your maximum light intensity and if required, fit a diffuser or similar to prevent saturation. Once that is set, then I think you have a good and simple solution.
There are many alternatives that come to mind.
How about PWM to control the voltage of the
LDR potential divider. This would need to be higher than the PICAXE supply rail to give any real advantge.
Non-linear op-amp stage between LDR and PICAXE. This could have thousands of different configurations but some of the simplest involve simple components such as diodes/LEDs in the feedback loop to give gains that depend on input voltage. Even the humble incandescent lamp can be used to give a near sinusoidal response over limited input range. (50v telephone lamps are great for this when run at only a few volts).
Have a look at the I/V characteristics of many simple devices (diode/LED/bulb etc) and see if you can find one that has the opposite of an LDR/light characteristic. Then use it in the feedback loop of an op-amp gain stage and then you have a linear characteristic. More to the point, what you really need is to get the range you are interested in to fit linearly in the range of your ADC for maximum resolution. Much better than doing it AFTER the ADC.

Analog computing still has its place! ;-)

xstamp
17-01-2006, 10:41
A technique that I used with biosensors, that also had a wide resistance range, was to use a precision current to frequency converter (National LM331) and feed its output to the 16-bit count input of a microcontroller. Can be slow but offers a much greater dynamic range compared with a 10-bit ADC input.

slurp
17-01-2006, 11:17
I presume you're using another resistor with the LDR as a potential divider and you need to adjust this such that you have light sensitivity or dark sensitity.

Mechanical adjustment of a Potentiometers would be a pain but Maxim, and others, produce Digital Potentiometers that could be adjusted by your program as day light approaches.

Alternatively can you use two LDRs one set for daylight and the other for night and switch between the two as required.

Best regards,
colin

--

www.minisumo.org.uk

Jeremy Leach
17-01-2006, 11:25
Thanks already ....
The pulse-count idea is good. The Count command gets a word value. All I'd need is a voltage to freq ...555 solution I guess.

Having two LDRs for each scenario is actually so simple it could be the best for what I'm doing. I'm actually multiplexing a few analogue inputs via a HEF4051 chip (well it's still in design stage!) and I've a few spare inputs.

hippy
17-01-2006, 19:59
How about using a PICAXE output to switch resistances ...<code><pre><font size=2>----.----------------------.-- +5V
| |
| .|.
| | |
.---^---. |_|
| | |\ | ___ |
| Out |---| &gt;|---|___|---{
| | |/ | |
| | |
| A2D |&lt;-----------------{
| | |
`---.---' .|.
| LDR | | &lt;---
| |_| &lt;---
| |
----^----------------------^-- 0V </font></pre></code>

Jeremy Leach
17-01-2006, 20:14
Thanks Hippy. I was wondering about that sort of thing, but hadn't thought about the diode ! To be honest I think that will do exactly what I want.

Although I haven't tested this solution I think this could be a very useful trick to remember, in all sorts of designs. You've effectively got two PICAXE-selectable operating modes for the ADC input.

One thought though. As a CMOS 'high' output at 5V supply will be around 4.7V, and the diode will have a forward voltage drop of say, Vf, then if the ADC input voltage is higher than (4.7-Vf) then even with the PICAXE output high the PICAXE driven resistor will never acivate.

Not really a problem though, and I think it's a good idea to go for a low voltage drop Schottky diode such as the IN5817 - according to google this has a forward drop of around 320mV.

By my calcs this voltage drop does affect the ADC voltage a little bit: 94% what it would be if no drop (assuming the two fixed resistors are equal value).

Edited by - Jeremy Leach on 1/18/2006 7:09:37 AM

premelec
18-01-2006, 00:38
You might use a MOSFET switch to change the 'R' instead of the diode in series as the diode has a temperature dependent voltage drop - which might or might not suit your needs... 2N7000 would be ok...

Jeremy Leach
18-01-2006, 08:12
Yep, it is an option - although if the forward drop of a Schottky diode is only around 320mV then I wouldn't think temperature will make a huge difference to the output ?

I'd be interested to know what affect temperature has on the 320mV figure if anyone knows.

Bloody-orc
18-01-2006, 10:12
i would suggest you to use a DS1809 Digital Potentiometer from Dallas. it is cheap (one of the cheapest) and is very easy to control (not via 12c saddly). with that you can have different setings for day, night and dawn. you can also build your own using a normal pot and a servomotor, but i don't see the point of that...

Jeremy Leach
18-01-2006, 13:18
Thanks Bloody ....what a great device ..just been reading the datasheet. I think I'll try the Hippy solution first tho, because I've got one spare PICAXE output port.

Bloody-orc
18-01-2006, 17:54
glad to be helpful... ;) (it doesn't happen wery often. most of the time i'm the asker one...)

kranenborg
19-01-2006, 06:42
Would the DS1803 dual pot be an option? it is i2c ... All firmware versions of the 18X/28X/40X should be able to write to it (i.e. set the potentiometer), and recent firmaware versions can also read (but that is probably not necessary ...

Jurjen Kranenborg
http://www.kranenborg.org/ee/picaxe

Larry
19-01-2006, 07:41
I vote for the 555 timer in astable mode for sampling the LDR. You didn't mention how long a sampling time you had, but with a properly sized cap in the circuit, you could stretch the sampling time to get readings over a big piece of the word range-- probably 12 bits or better, using the COUNT command.

Cheap and easily tuneable.

Jeremy Leach
19-01-2006, 09:43
Larry
The 555 solution is very appealing too - thanks. I really like the thought of getting a word output. Would need around 3 second sampling time using count command.

Another thing I like is to do with the maths. What I don't generally like about the normal potential divider setup feeding an ADC is the Vadc = R1/(R1+ R2) formula, which makes getting any sort of linear ADC response basically impossible.

What I like about the 555 solution is that one Astable circuit has the formula f = 0.72/(r1 x C). ie f is inversely proportional to r1.

So, because an LDR resistance is also inversely proportional to Lux (light), then if the LDR is used in this Astable circuit f will be proportional to Lux... ie a straight line relationship. Well, that's the theory, but it makes it an attractive solution.

The only thing is ... this is all in my outdoor , low power , sensor uni for my weather station. I still think the simple , non-linear solution using another PicAxe output port above will be best for my purposes ...and do all the clever maths to get to Lux on the PC.

I'm no expert on Lux etc ....been reading up on it. According to one article I've read, &quot;the human eye's reaction to light variation is proportional to Log (Lux). So in some ways it would be better to measure human's response to light, rather than Lux !!

Maybe I'm getting in too deep ;-)

BeanieBots
19-01-2006, 10:04
You are correct about the human eye's response but there is even more to it because it has &quot;an area averaging AGC (automatic gain control)&quot; aka, the iris.
When in a room that doubles in brightness, only about a 10% change is perceived, however, if the room is observed from a distance, it is perceived to almost double in brightness not to mention the effects of colour.
Is was wondering, is it possible using sensors to tell the difference between a bright overcast day and a dull clear day?

Jeremy Leach
19-01-2006, 14:17
Interesting Beaniebots. Well, as my interest is outside then can assume a uniform brightness across the whole viewing area.

This whole investigation has started me wondering about filters as well. My guess to the question about overcast/clear is that there's probably difference in UV etc, which could probably be detected using filters of some sort. There's a lot of potential for experiments here !

BeanieBots
19-01-2006, 14:35
I guess you could never end. How blue is the sky and how red is the sunset? Does the LDR respond to UV (A and/or B)?

premelec
19-01-2006, 22:45
Hi Jeremy - you might look at the 90-100db log amplifiers which are available from Analog Devices www.analog.com P/N AD8307, AD8310.

There is a legitimate concern about what the LDR looks like at low light levels - i.e. noise and linearity etc... The log amp can give you extraordinary range at a modest price....

Also using the LDR in a 555 astable pulse generator circuit and using PULSIN on the PICAXE would seem to cover quite a range.... might suit youir needs... good luck..

Edited by - premelec on 1/19/2006 9:48:44 PM

Michael 2727
20-01-2006, 04:19
How many varieties of LDR have you tried,, they differ greatly in linearity and in
minimum and maximum resistances.

The 3 main types that seem to be available here in OZ are -
A 11.5mm Diameter, silver/grey with red track, only markings are 3k on the back of it.
A 11.5mm Diameter, silver/grey with yellow track, no markings on the back of it.
A 5.0mm Diameter, flat sides, silver/grey, orange/red track, no markings on the back of it.
A 5.0mm Diameter, flat sides, silver/grey, brown track, no markings on the back of it,
the tracks on this last one are square ended, the others are all rounded.

They rarely seem to have any markings on them, so it would be hard to say what
brand type they were.
The larger diameter types seem to cover a greater range of resistance e.g. as low
as 10 Ohms in very bright light to over 20 Megs in total darkness. (well Off Scale on my meter)
The smaller diameter types only go down to 300 Ohms or so in bright light to
as high as 20 Megs. The speed at which they register change also differs greatly.

It would be nice to see some sort of reference like an NTC thermistor ?? Ohms at ?? Lux etc.

Jeremy Leach
20-01-2006, 08:05
premelec ...wow those are interesting. I'll need a good read of the datasheet to grasp it ! Although they aren't that cheap, and I think there's a lot that can also be done with standard op amps too.

Michael ... I've only tried a couple and yes I've been frustrated with lack of markings and generally lack of datasheets on net.



Edited by - Jeremy Leach on 1/20/2006 7:24:50 AM

premelec
21-01-2006, 23:22
Recently I got a copy of Maxim Engineering Journal Vol 56 which has a discussion of DC logarithmic amplifiers - MAX4206 in particular - the text says &quot;...most common applications of the DC logarithmic amplifier are those involving the measurement of light.&quot; I tried to access their site www.maxim-ic.com and my browser crashes so I don't know if this article is available on line. It's quite detailed and interesting.

On the 555 side of possibilities note that there is a CMOS 555 available with very low input currents. I don't know what the temperature coefficient of LDRs at high resistance but suspect it may be high...