Linear light reading

EveryReasonTo

New Member
I'm trying to design a simple program that will vary the speed of a continous rotation servo dependant on how bright the sun is but I'm struggling to 'calibrate' the LDR to get a linear reading.

This is the main code I've come up with so far:

Code:
Init: Servo 1,150     'Stop servo

Main: readadc 4,b1    'Read LDR, store value in b1
      b2 = b1/4+150   'The servo only needs to spin in noe direction, so this makes b2 always >150
      debug           'Show values of b1,b2 on screen
      goto SMov

SMov: Servopos 1,b2   'Move servo 
      goto main
This works but as you would expect, anything over a tiny bit of daylight and the servo is going full speed.

How can I get it so that I get a more linear change of speed?

Thanks!
 

nick12ab

Senior Member
Is the LDR part of a potential divider? If not then it should be. If it is, then try reducing the value of the other resistor.

If this fix doesn't work, then please post more details about that continuous rotation servo - how is it controlled?
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

You really need to measure what LDR reading you get for different brightnesses and set against that the values you want to set the servo to to get the speed desired. Draw that as a graph and then you can determine if there's an equation that can map from LDR to servo value or a lookup table which can deliver that.
 

EveryReasonTo

New Member
nick12ab - Hi I've followed the picaxe manual and used the LDR in a potential divider with a 10k resistor. I'm using the picaxe 08m2 servo driver board (replacing one of the 330R resistors with a wire link). I'll try changing the value tonight, what would you suggest? 1K?

hippy - Thanks! As an alternative to this, could you suggest a sensor that would give me a more linear reading? Maybe an IR sensor or a phototransistor?
 

SAborn

Senior Member
I doubt if you will ever get a true linear reading from a ldr and sunlight, there is just too many things that can effect the readings, like clouds, dust, etc...
Even though to the eye you might notice a change in intensity, to a sensor it wont be the same effect, for example a solar panel can put out more power with clouds then clear skies under certain conditions, but to the eye the intensity apears lower.
 

nick12ab

Senior Member
I'll try changing the value tonight, what would you suggest? 1K?
You could try that. It's just a case of trial and error to do it this way, to find the best value of resistor to get the desired LDR sensitivity. Consider replacing the resistor with a potentiometer so that the sensitivity is adjustable.
 

westaust55

Moderator
@EveryReason,
have a look at some work I did to optimise selection of the series resistor to go with an LDR back in 2008.
http://www.picaxeforum.co.uk/showthread.php?9265-Info-on-selection-of-series-Resistors-with-LDR
The key thing is to look at the datasheet for the LDR that you have and determine an optimal value for the greatest ADC input variation.

Have a look at the attached datasheet as an example.

Resistance is relatively linear as a function of light level (See figure 3) but the resistance varies significantly with the wavelength of the light. This is where difference between a clear day and a cloudy day can have a marked impact in response.
 

Attachments

mrburnette

Senior Member
I'm trying to design a simple program that will vary the speed of a continous rotation servo dependant on how bright the sun is but I'm struggling to 'calibrate' the LDR to get a linear reading.
My belief is that you are using the wrong type of sensor, a (naked) LDR. The attached chart will explain what you are up against with clear vs cloudy conditions. I worked for months at a college research center back in the late '70's and this is a serious issue... today, we can throw complex floating-point equations at the problem and create a linear model, but you will not pull that off inside a PICAXE. A more appropriate sensor is: http://akizukidenshi.com/download/ds/senba/LLS05A.pdf I have found these surplus on the Internet for a couple of American dollar$. At one time, Electronic Goldmine had them on their website. I did find them available from Newark this morning, but a bit pricey. Nice thing about these sensors, is that the output approximates in voltage what the human eye perceives in brightness... you can also query the Internet on circuits for designing camera light meters... for example, luxmeter.pdf

- Ray


Solar spectrum absorption-conditions.jpg
 

hippy

Technical Support
Staff member
Before getting too involved in best sensor choices and heading towards engineering perfection it might help to have an idea of what the application is, what it is intended to do. It might just be a case of optimising the LDR circuit then choosing a mapping / lookup table. Even if the sensor is made linear, the servo speed control likely isn't, so will likely have to have a mapping / lookup anyway.
 

AllyCat

Senior Member
I'm struggling to 'calibrate' the LDR to get a linear reading.
Hi,

Do you really want a linear reading? Most photographic exposure scales, for example, are Logarithmic. Even full sun in Winter is only about 20% of the Energy or Luminance of that in Summer.

Generally, a photoresistor is more suitable for a Log. scale, IMHO for a Linear scale you'd do better with a photodiode/transistor or a PhotoVoltaic panel (e.g. from a cheap garden solar light).

Cheers, Alan.
 

premelec

Senior Member
@AllyCat - oh my the mayor of London may give you a call! Here we get 10% more instantaneous insolation in winter [nearer the sun in orbit].

@EveryReasonTo- If trying to measure actual solar power best bet - as AllyCat sez - is simply a small photovoltaic array measuring the 'short circuit' current - either through feedback from an op amp or several cells in series into a small resistor... and keep the dust and birdy poop off it. Indeed the PVs from garden lights are cheap and available and tailored to give incident energy well...
 

EveryReasonTo

New Member
Before getting too involved in best sensor choices and.........
The project is going to be an interactive display of sorts for the kids. The servo is going to have a sun attached to it and I'd like it to spin extremelly slowly in the morning or on an overcast day, going up to maybe 15rpm in really bright sun. This is where I'm having problems, as soon as we have any sort of daylight, the servo is going full speed.

The LDR i'm using is the ORP12 from tech-supplies.
 

westaust55

Moderator
The LDR i'm using is the ORP12 from tech-supplies.
Can you post:
1. The schematic diagram for your circuit showing how you have the LDR connected.
2. Your program thus far so that folks here can better help/guide you to a solution.

While not having specific data to hand, I suspect the in terms of light levels, from darkness to even dull sunlight there is a significant jump/change in LDR resistance and from dull to bright sunlight the resistance change may be equal or smaller range.

If you look at the datasheet for an NORP12 LDR that I posted at post 7:
darkness ==> ~1,000,000 Ohms
light @ 10 lux = maybe a superbright LED at a few hundred mm (?) ==> ~9,000 Ohms
light @ 1000 lux = ~ twice typical office lighting ==> ~400 Ohms
Bright sunlight ==> 30,000 lux ==> likely not much less than 400 Ohms

Maybe adding some form of filter in front of the LCD to reduce light onto the LDR in bright sunlight will improve the resistance range in varying sunlight.
You could try a fixed tint sunglass lens as an experiment. A photo-chromatic lens with give the reverse of what you need to achieve.
 

SAborn

Senior Member
Not what you are trying to do and needs no picaxe, but has a similar result, is a small solar panel and a hobby DC motor.
The brighter the light on the solar panel the faster the motor spins, also linear in its operating range.
 

campo

New Member
some vehicles you can get these off the display for 5K, but for your factor i think it might price a we bit more, why not try having the gear box re-mapped and see how it goes, its way less expensive....
 
Last edited:
Top