LDR Readings (using an LDR to FadeLED(PWM))

I'm trying to use the values of an LDR to control the fade of an LED. The LDR is only turning out values between 941 and 1003 which I have downscaled by dividing by 4, but the changes in the LED are barely noticable. How do I make the LDR more sensitive and produce the full range of values (0 - 1024)?

The aim is to eventually be able to control multiple LEDs in this way.

The circuit is as follows:
5V to a 220ohm resistor - AnalogPin(1) - LDR - GND
Pin11(PWM) - 220ohm resistor - LED - GND

Code Below:

int LDR = 1;
int red = 11;
int LDRval = 0;

int redVal = 0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
LDRval = analogRead(LDR);

redVal = (LDRval) / 4;
Serial.println(LDRval);
delay(5);
analogWrite(red, redVal);
}

I'd try a bigger resistance between 5V and the analogue input.

full range of values (0 - 1024)?

sp. "1023" :wink:

Thanks AWOL, trying a few different resistors but it tends to bracket the output or just moves it down. Any ideas on a resistance value that would work?

Thanks for the correction :slight_smile:

Do you have a spec for the LDR?
Have you tried it with an ohmmeter?

If you can't get a better result, you could use "map" between your min and max values to your output range.

Here is the spec for the LDR: http://uk.rs-online.com/web/search/searchBrowseAction.html?method=searchProducts&searchTerm=596+141&x=0&y=0

I think the main problem is that the LDR only gives readings of between (700 - 900) or (200-400) and I'm not sure why this is happening. I imagine it is to do with its resistance rating. If I connect the LDR directly to 5V, I only get readings of 1023, is there another way of connecting the circuit?

hmmmm

Turn it the other way up and use something like a 10k or larger resistor.

5v - LDR - Analog Pin - 10k - Gnd.

Connecting 5v through the LDR to the analogue Pin will only ever yield a reading of 1023 because the impedance of an analog pin is so high.

When wired as above it will give higher reading the brighter the light. There should be no difficulty in getting readings between 0 and 1000.

A 220 ohm resistor with a LDR maximum resistance of 20 mega ohms will have virtually no effect unless the light is very bright.