Shop OBEX P1 Docs P2 Docs Learn Events
Temperature effects on Photo Resistor — Parallax Forums

Temperature effects on Photo Resistor

doggiedocdoggiedoc Posts: 2,242
edited 2013-11-30 08:29 in General Discussion
I've encountered and interesting and unexpected problem with my automatic chicken coop door. I am using a CdS photo resistor and an Analog input on the PropBOE to measure light intensity and compare the result to logical thresholds to determine when to open or close the coop door. The phenomenon I have noticed seems to be related to fluctuations in ambient temperature.

It appears to me that on recent cooler evenings the door does not close (ie the lower threshold of light intensity is not reached) even though on previous evenings (warmer I suspect) the door has closed at an ideal time. Tonight I went out after 10pm and the door still had not closed. So... I went in and grabbed my Mac and sat out there - I'm sure if any neighbors noticed they'd think it was normal - and sat by the coop to check the readings from the CdS. The same thing happened a couple of weeks ago when we got our first round of cooler weather. I adjusted the threshold then and all was fine, for a day or two. But then it warmed back up and I had to adjust the threshold again. Now I'm back to dealing with cooler evenings. WTF?

This "automatic door" concept is requiring too much manual tweaking. :(

So, questions:
1) Am I correct in my suspicion that temperatures are affecting the sensitivity of the CdS cell?
2) If so, is there a way to compensate for temperature variations (actively or passively)?
3) Is there an alternative to measuring light intensity that is not affected by temperature variations? (I have some of these.)

Doc
«1

Comments

  • LawsonLawson Posts: 870
    edited 2012-10-09 21:00
    A quick fix would be to keep track of the maximum and minimum resistance of the CdS cell over a 24 hour period. You'd then set the dark threshold as a function of these two numbers. I.e. the max resistance minus 20% of the difference. (this assumes the climate changes slowly)

    Another quick fix would be to substitute a BPW34 for the CdS photo-cell. Reverse biased would be the most immune to temperature swings, but measuring the open-circuit voltage gives the best dynamic range. (and with a >1 mA photo-current under "full-sun" you shouldn't need to change the load resistor much)

    Lawson
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-09 21:00
    By all means, use the TSL230 chips. They're immune to temp variations.

    -Phil
  • ercoerco Posts: 20,256
    edited 2012-10-09 21:44
    No, no, no. You guys are downright silly with your "different light sensor" suggestions.

    Get a government grant for $50K and assign a task force to study temperature effects on indeterminate-RohS compatible CdS cells. A second Prop can monitor 17 different types of temperature sensors and throw out the high & low (and the East German sensor) readings and average the rest together. Another round of grant funding can auto-generate the temperature correction algorithm and compensate for any delta T variations in your system.

    Simple. DUH!
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-10-10 05:49
    Simply calibrate the Cds as a thermometer to compensate.
  • skylightskylight Posts: 1,915
    edited 2012-10-10 07:17
    Could you train one of the chickens to close the door at nighttime?
  • davejamesdavejames Posts: 4,047
    edited 2012-10-10 08:33
    doggiedoc wrote: »
    1) Am I correct in my suspicion that temperatures are affecting the sensitivity of the CdS cell?

    Doc,

    I'm interested in using a CdS LDR in some future products that could be exposed to severe shifts in temperature, so I've emailed the west coast support person at Adanced Photonix, a manufacturer of said product. The datasheets did not relate anything other than the min/max temperature allowed. I'll let you know what's answered.

    I have to believe that being a resistive element, temperature will affect the overall response; it'd be nice to know how much.

    Later,

    DJ
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2012-10-10 08:52
    I wonder if it's as much temperature as it might be humidity ... I seem to recall observing a similar behavior, but I was convinced the problem was related to humidity more so than temperature.

    One way to overcome this, be it temperature or humidity, is to use two sensors in close proximity so that the ambient fluctuations happen equally, but use one sensor as a reference in a way it won't be affected by your input.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2012-10-10 09:11
    I'm surprised about that too, that a temperature coefficient or curve is not specified in the data sheets. Will be interested to hear what Advanced Photonix has to say.

    On one hand, you might expect a temperature dependence based on electrons being kicked up into the conduction band at higher temperatures. There may be compensating effects. My photonics book describes it in terms of a ratio between carrier lifetime and transit time and I don't understand what they are talking about. On the other hand, CdS photocells have been used successfully in simple controls for so many years that it hardly seems possible that they all had serious problems or serious need for temperature compensation. CdS cells are very sensitive, for example, Tony Messina's moonlight sensor. Resolution of the conundrum may take the $50k study that Erco suggested! Too late. The industry is getting away from anything containing Cadmium.

    Photodiodes do have a temperature coefficient, both for the dark current (spontaneous production of electron-hole pairs) and sensitivity (changes in light absorption), but those effects are very small until you start pushing the limits. The open circuit voltage of a photodiode under constant illumination has the familiar -2.1mV/°C dependence.

    DoggieDoc, is there anything else in the circuit that might have a temperature dependence? Can we presume it is just a voltage divider with the photocell and a resistor, into the ADC input? All in all, the TSL230 is a sure bet until you can train that one chicken to do it.
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2012-10-10 09:15
    "... a temperature coefficient or curve is not specified in the data sheets" - however being outside and exposed to morning/evening dew, temperature will play a part as condensation could build up depending on what the humidity levels are. The closer to the ground you are, the more pronounced this effect will be.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2012-10-10 09:39
    Beau,

    Yes, humidity, particularly if the resistances in the divider are high. That would call for the whole circuit to be mounted in a waterproof dry capsule. Keep it away from direct view of the sky so condensation is less likely to form on the surface.
  • davejamesdavejames Posts: 4,047
    edited 2012-10-10 10:14
    ...but aren't these things sealed?

    Looking at the CdS LDR supplied in the WAM kit, there's a glass(?) coating over the element. Wouldn't that prevent any humidity issues?
  • doggiedocdoggiedoc Posts: 2,242
    edited 2012-10-10 12:08
    @Lawson
    maximum and minimum resistance of the CdS cell over a 24 hour period.
    Do you mean a dynamic threshold calculation?




    @Phil
    use the TSL230 chips. They're immune to temp variations
    Could you elaborate on this immunity?




    @erco - LOL




    @Humanoido
    Simply calibrate the Cds as a thermometer to compensate.
    I don't know where to begin with that one. Suggestions?




    @skylight -
    Could you train one of the chickens to close the door at nighttime?
    Obviously your chickens are smarter than mine :tongue:




    @davejames -
    I'll let you know what's answered.
    Cool, I'd like to see what they say about temperature variations.




    @Beau -
    I wonder if it's as much temperature as it might be humidity
    I too had that thought when this first happened. My solution (or not) was to encase the CdS cell in a tube with a cork stopper. CdS_tube.jpg
    I don't know if it made a difference. It is entirely possible that the tube doesn't seal out enough humidity or perhaps humidity isn't a factor. I don't think there is any issue with dew/condensation as the sensor is inside the coop and about about 6 feet from the ground.




    @Tracey Allen -
    is there anything else in the circuit that might have a temperature dependence? Can we presume it is just a voltage divider with the photocell and a resistor, into the ADC input?
    The sensor is wired to the BOE with a phone cable - about 6 feet long. The voltage divider is with a 20K 1/4 Watt Carbon Film resistor (5%) into the ADC input of the PropBOE. I don't remember how I arrived at the 20K value at the moment. Perhaps it's too high combined with the 6 feet of thin phone wire?



    Thank you all for the help!
    Paul
  • Heater.Heater. Posts: 21,230
    edited 2012-10-10 12:29
    I'm not sure but, last time I played with such a thing the device itself was pretty well sealed from the environment. So putting it in a further hermetically sealed enclosure would not help much. But I get the idea these things are working at quite high resistance values, so whatever wires you have connecting them to your circuit (Did you say 6ft?) can be be subject to moisture which will affect the measurement. My conclusion is that the whole thing, sensor and front end electronics, needs to be sealed from the elements.

    On the other hand if this actually was a temperature dependent phenomena I would just arrange to have two of them. One would be illuminated by the ambient light and one would be in a box illuminated by a LED. Comparison of the output of one with the other would trigger whatever you want to do. To change the set point just change the current driving the LED to make it brigher or dimmer. i.e the light level you want to trigger at.

    Or perhaps one of your chickens has learned how to tweak the adjustments so that they can go in and out when they please:)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-10 13:31
    doggiedoc wrote:
    Could you elaborate on this immunity?
    At its heart, the TSL230's sensor is a photodiode. There are two temperature effects in play here. First is an increase in dark frequency with temp. But that should not affect your app. The second is a temperature coefficient related to irradiance color. Below 700 nm, it's nearly zero, but increases to nearly 10000ppm/C at 1000nm. This could be a factor in direct sunlight, which is rich with near IR. If it's a concern, an IR-blocking filter would eliminate the problem.

    -Phil
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2012-10-10 13:35
    In any sensor event, a differential approach might be the best solution for negating temperature and humidity.

    Aim one sensor towards the East, and aim the other sensor towards the West.
  • doggiedocdoggiedoc Posts: 2,242
    edited 2012-10-10 16:17
    In any sensor event, a differential approach might be the best solution for negating temperature and humidity.

    Aim one sensor towards the East, and aim the other sensor towards the West.
    Beau - I took your advice here and added a second sensor (CdS). I placed the one in the tube on the long wire outside under the roofline and the second one on the breadboard of the BOE inside the coop.

    This was the simplest attempt at a fix so I thought I'd give it a run first. Minor adjustments to the code: I added a second adc object and added the to values together (rawVal) and finally divide by the number samples x 2
    PRI GetLightLevel 
         sumVal := 0
         rawVal := 0
         repeat 120
            rawVal := adc_1.In(CdS_PIN_1)+ adc_2.In(CdS_PIN_2)
            sumVal += rawVal
            Display                                       'and here (3/3)
            waitcnt(clkfreq / 10 + cnt)
         lightVal := (sumVal/240)     ' 120 samples from 2 CdS cells (240 samples)
    
    I'll report back - first I'll need to recalibrate the threshold values since the combined sensors equates to a movement of the location.

    Thanks for the help.

    Paul
  • skylightskylight Posts: 1,915
    edited 2012-10-11 01:11
    Sorry for the joke about training a chicken, of course you should be training the rooster... but enough of that, I'm surprised you are getting this problem as I believe the cheap dusk/dawn sensors you use to control lighting are also based on Cds sensors? I don't think they suffer the same problem, could you perhaps use one of those to trigger you're circuit? Is it the complexity of the sampling in the programming somewhere that may be giving false triggering or making it too sensitive? ie Is there hysterisis built into the calcs?
    Or perhaps a stray light is affecting the circuit such as car headlamps, neighbours using a torch or something?
  • doggiedocdoggiedoc Posts: 2,242
    edited 2012-10-11 04:13
    skylight - I've tried to eliminate stray light such as passing cars and flashlights and such by averaging the samples over a period of time. In the above code clip I had changed it to sampling 10 times per second but I've changed that back to 2 times per second. So the average light intensity is now measured over a 60 second period and is from 2 separate sensors.

    I think perhaps I need to get this all soldered to a board. Currently using the bread board on the PropBOE. Perhaps switching to soldering the components to a prototype board will help.

    Paul
  • skylightskylight Posts: 1,915
    edited 2012-10-11 04:40
    If staying with a temperature problem, maybe it's not just the sensors?
    Presuming the connecting wires/cable are heating/cooling and you are taking resistance readings (light on cell), the length of run (from board to sensor) maybe a factor?
    how precise is the function that decides whether the door opens or closes? You might have to factor in a margin to cover for heating effect?
    Which boils down to what I was saying earlier, is the circuit and programming too sensitive for the application?

    Training may involve teaching the chickens to flap their wings to stabilise the coop's temperature :)
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2012-10-11 08:38
    Doggiedoc,

    The photocell resistance should decrease over several orders of magnitude as light level goes from ~100000 lux in full sunlight to <1 lux in darkness. Maybe the choice of 20k is not so good. In terms of voltage or ADC counts, what is your typical threshold value? I think you probably want that to be at around half-scale, 2048 counts. With the CdS cell attached to the ohmmeter, measure its resistance at the light level at which the door should be closing. Use that value for the fixed or adjustable resistor in your divider circuit.

    I found an an ingenious set of amateur experiments...
    http://www.brighton-webs.co.uk/electronics/light_dependent_resitor.htm
    It includes a look at temperature dependence. At a single light level, the resistance change due to a temperature change of 30°C was less than 10%. The experimenter immersed the sensor in a bowl of hot water, with the sensor looking out at the light source of interest (a 100W light bulb at some distance), and then recorded the resistance reading as the water cooled off. You could do that at your critical light level, along with a temperature measurement, and then use that factor for temperature compensation in your software if that is in fact the problem. Yet again, the 10% temperature effect should normally be swamped by order-of-magnitude changes in light level.
  • Desy2820Desy2820 Posts: 138
    edited 2012-10-11 08:40
    You mentioned that you're using a plain carbon-film resistor. I think these resistors are fairly temperature senstitive. I'm wondering if yours might be more senstitive than most. Can you try a precision 1% resistor instead? Or pull your current resistor, and measure it's value. Then chuck it in the freezer for 20 minutes and see if it changes, and by how much.

    Anyway, just a random thought. I hope it helps.

    -- Glenn
  • doggiedocdoggiedoc Posts: 2,242
    edited 2012-10-11 09:45
    Desy2820 wrote: »
    You mentioned that you're using a plain carbon-film resistor. I think these resistors are fairly temperature senstitive. I'm wondering if yours might be more senstitive than most. Can you try a precision 1% resistor instead? Or pull your current resistor, and measure it's value. Then chuck it in the freezer for 20 minutes and see if it changes, and by how much.

    Anyway, just a random thought. I hope it helps.

    -- Glenn
    Good tips. Thanks - will try this evening when I got off from work.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-11 11:32
    Now I think I know why Browser spent so long in the "back room" at the clinic yesterday. The vet was probably online to some forum instead of dealing with my cat. :)

    -Phil
  • doggiedocdoggiedoc Posts: 2,242
    edited 2012-10-11 13:24
    Now I think I know why Browser spent so long in the "back room" at the clinic yesterday. The vet was probably online to some forum instead of dealing with my cat. :)

    -Phil
    - You should notice the time stamp on my post. It's during lunch (East Coast Time). :D
  • ctwardellctwardell Posts: 1,716
    edited 2012-10-11 13:37
    Now I think I know why Browser spent so long in the "back room" at the clinic yesterday. The vet was probably online to some forum instead of dealing with my cat. :)

    -Phil

    Nah, Browser was busy telling the vet you don't give him enough shrimpz.

    C.W.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2012-10-11 13:43
    t'was the cat, couldn't be bothered, entralled by the vet's book on chicknz.
  • skylightskylight Posts: 1,915
    edited 2012-10-11 13:49
    Now I think I know why Browser spent so long in the "back room" at the clinic yesterday. The vet was probably online to some forum instead of dealing with my cat. :)

    -Phil
    He may be online but his door is always open. :smile:
  • Prophead100Prophead100 Posts: 192
    edited 2012-10-11 22:22
    Just to throw out another option that adjusts seasonally with day length but no sensors. The solar object will actually give you the exact time of sunset/sunrise as well civil, nautical and astronomic twilight so you could know when to close the door based upon the position of the sun / light levels with a RTC. You can also set it for a specific height of the sun above/below the horizon which correlates to light levels. ( sort of what the chickens do)
  • doggiedocdoggiedoc Posts: 2,242
    edited 2012-10-12 03:26
    Thanks Prophead100 - should I assume the solar object you speak of is in the OBEX?
  • davejamesdavejames Posts: 4,047
    edited 2012-10-12 08:18
    ...just picked up an email from Adanced Photonix saying they've rececieved my request for temperature data and will get back to me.
Sign In or Register to comment.