Pages: [1]   Go Down
Author Topic: LDR Readings (using an LDR to FadeLED(PWM))  (Read 1946 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25820
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Quote
full range of values (0 - 1024)?
sp. "1023"   smiley-wink
Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25820
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Lancashire, UK
Offline Offline
Edison Member
*
Karma: 9
Posts: 1991
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: April 18, 2010, 11:54:01 am by stephen_t » Logged


Pages: [1]   Go Up
Jump to: