Got a curious one and wonder if anyone has any pointers.
I've got an off-the-shelf cheap LDR
And enclosed it in a transparent plastic box outdoors. I've got it on a long pair of wires (approx 30 metres) back to where the Arduino Uno is, there I have a 10k resistor in the following very simple (standard) circuit:
However I'm getting very strange results that don't seem to vary according to light levels at all. There seems to be variance in the output (and when I disconnect the sensor it drops to 0) but not varying.
Could this be because of the 30metre cable run I have from the LDR back to the arduino+resistor? (Resistor is beside the Arduino) or is there some other factor potentially involved here?
Yes, its varying according to light levels. 750 = daytime cloudy? 980 = daytime sunny? Put a piece of black tape completely over the sensor, then nighttime <= 500?
With the sensor disconnected, the reading is supposed to be 0 due to the pulldown resistor.
Thanks Mike, that would make sense, I'll give that a go later on.
dlloyd, it's not giving varying results, as you can see on the graph it never drops below 700 (The drop in the graph you see is me disconnecting the sensor to confirm the Arduino reacts and drops to 0), as on my graph at midnight here in the UK it's pretty dark and LDR is still showing 800!
You'll need to change R1 to a lower value for your sensor. Try 1K.
You can fine tune the dark reading to around 100 or so by putting a piece of black tape over the sensor and testing with lower resistance values. Then double check the high reading with tape removed. This "calibration" will allow you to get maximum performance (range) from your specific sensor.
Just to tie up the ends here, I tried adding a capacitor to see if this helped with the long cable run, and no difference.
I then varied the resistor, doing the calibration dlloyd suggested, covered the sensor in tape and adjusted resistor down to around 200, then went and uncovered it, it only went up to about 350.
Still puzzled over what was wrong, I went and swapped the LDR itself. Guess what, it jumped and varied. So I adjusted the resistor values again (4k7 is what I ended up on) and this now gives me a great variance between light and dark (This is just for a dusk to dawn light sense).
So it looks like it was a faulty LDR all along. Thanks for the help though guys, helped me track it down and sort it.
For info, here is the faulty LDR.
Not sure if you can make it out but there looks like a crack/line from the bottom left to the middle right, which I'm going to suspect was the issue.
A small solar cell (from a cheap garden light) is a better solution.
The 2-3volt they produce can be read direcly by an analogue pin.
Wise to use a (~3k3) resistor between solar cell and pin.
And a (~10uF) cap from analogue pin to ground.
Leo..