Go Down

#### LAB

##### Apr 18, 2010, 04:38 pm
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()
{

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

#### AWOL

#1
##### Apr 18, 2010, 04:53 pm
I'd try a bigger resistance between 5V and the analogue input.

Quote
full range of values (0 - 1024)?

sp. "1023"
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

#### LAB

#2
##### Apr 18, 2010, 05:10 pm
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

#### AWOL

#3
##### Apr 18, 2010, 05:32 pm
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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

#### LAB

#4
##### Apr 18, 2010, 05:41 pm
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

#### pluggy

#5
##### Apr 18, 2010, 06:31 pmLast Edit: Apr 18, 2010, 06:54 pm by stephen_t Reason: 1
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.
http://pluggy.is-a-geek.com/index.html

Go Up

Please enter a valid email to subscribe