Pages: [1] 2   Go Down
Author Topic: LDR light sensor does not return my expected value  (Read 2649 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wrote an Arduino program to test two light sensor: one is the LDR light sensor (http://arduino-info.wikispaces.com/Brick-LightSensor), and the other is the Phidget precision light sensor (http://www.phidgets.com/products.php?product_id=1127).   The pictures of results can be found in the http://alturl.com/5vc4m .... From this picture, I found that :
  • at the beginning (time < 500), both sensors are working fine
  • when I turned a light off (400 < time < 700), both sensors returned lower values, but the output values do not overlap
  • when it is dark (700 < time < 1000), both output values are very closed to zero
  • After I turned on the light (1000 < time < 3100), output values of LDR light sensor jumped to 76x, even I turned a light off, LDR light sensor can not output lower values
  • dark again (time > 3100), both output values are very closed to zero

My LDR light sensor, is a new sensor, never returns values higher than 76x.  I have two LDR light sensors, they are all have the same problems.  

Anyone could tell me what's the problem of my LDR light sensor?  Am I bought bad sensors?  Should I need to change my code, which is simply the analogRead(LDR_LIGHT_PIN)?

Here comes the codes:

#define LDR_LIGHT_PIN  A0
#define PHID_LIGHT_PIN  A4

/*----( SETUP: RUNS ONCE )----*/
void setup()
{
   pinMode(LDR_LIGHT_PIN, INPUT);  // for LDR light sensor
   pinMode(PHID_LIGHT_PIN, INPUT);  // for Phidget lighet sensor
   Serial.begin(9600);             // Enable the Serial data output
   Serial.println("#------- Test Light Sensors ---------");
   Serial.println("#time (sec), LDR, Phidget Precision--");
}
/*--(end setup )---*/


/*----( LOOP: RUNS CONSTANTLY )----*/
void loop()
{  char str[40];   // string for results printing

   // print the luminous
   sprintf( str, "%06ld, %4d, %4d \0", millis()/1000,
                 analogRead(LDR_LIGHT_PIN), analogRead(PHID_LIGHT_PIN) );
   Serial.println( str );

   delay(5000);                          // Wait 5 second
}
/*--(end loop)---*/
« Last Edit: August 06, 2011, 02:22:58 pm by wrjih » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


The two links are the same smiley-sad I cannot see the LDR code =>

please post the code which compares the two ...

How did you connect the LDR and how the phidget?
LDR need a voltage divider!

Chacked your wiring ?


Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


PLease modify your post, selct the code and press the # button, the look will be better ...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The analogRead() is not stable in the last bit.

Please try this code:
* based upon yours
* increase baudrate
* removed meaningless comments
* removed the use of delay

Code:
#define LDR_LIGHT_PIN  A0
#define PHID_LIGHT_PIN  A4

unsigned long prevtime = 0;

void setup()
{
  pinMode(LDR_LIGHT_PIN, INPUT);  
  pinMode(PHID_LIGHT_PIN, INPUT);  

  Serial.begin(115200);              

  Serial.println("#------- Test Light Sensors ---------");
  Serial.println("#time (sec), LDR, Phidget Precision--");
}


void loop()
{
  if (millis() - prevtime >= 5000)
  {  
    prevtime = millis();

    // MAKE MULTIPLE READINGS AND AVERAGE THEM TO MINIMIZE "JITTER"
    int ldr = 0;
    for (int i=0; i< 5; i++) ldr += analogRead(LDR_LIGHT_PIN);
    ldr /= 5;

    int phidget = 0;
    for (int i=0; i< 5; i++) phidget += analogRead(PHID_LIGHT_PIN);
    phidget /=5;

    // OUTPUT THE AVERAGED RAW READINGS
    char str[40];  
    sprintf( str, "%06ld, %4d, %4d \0", millis()/1000, ldr, phidget);
    Serial.println( str );
  }
  // ... do other things
}
« Last Edit: August 06, 2011, 05:44:36 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, robtillaart

Change the baud rate is not work for this case.  I've tried 9600, 19200,38400,57600, 115200....

I've used your code, but still have the same trouble.  The Phidget sensor works properly, but the LDR light sensor returns incorrect results.... 

BTW, in your code, in the loop(), the second LDR_LIGHT_PIN should be replaced by PHID_LIGHT_PIN

Currently, the output of my LDR light sensor:
  • time > 4000
  • if there is some lights, returns 76x
  • if it is dark, returns 0, or value < 5
  • if the LDR light sensor is under the light directly, it returns 76x
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2566
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

IMHO, the problem is in design LDR brick light-sensor, even I don't have complete schematic of their unit, but what they say on page http://arduino-info.wikispaces.com/Brick-LightSensor
LM324 - used as amplifier, which isn't rail-to rail. Data sheet for OPA says that maximum output voltage for power +5V  is 3.3 / 3.5V, this is why you can't get more than 76X .
Are the any reason you need to keep this shield instead of connected separate LDR (I mean just light sensitive resistor) and resistor? You always can calibrate your setup by adjusting external resistor or use a pot.

Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
BTW, in your code, in the loop(), the second LDR_LIGHT_PIN should be replaced by PHID_LIGHT_PIN
modified my post above to reflect that, thanks,

Are the readings more stable?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, Magician & robtillaart,

The value is stable or not is not my key focus point.  Thank you for giving me the hint for solving the future problem.

Now I know the reason why my LDR light sensor can only reach max 76x.  But there is still  a question......I don't understand why the LDR light sensor can work properly at the beginning, but after I turned off lights and then turn on the light, it cannot work properly anymore....  the return value is always 76x no matter how many lights has been turned on, that is, the illumination of the room is changed, but the LDR sensor always ouput 76x........ the only exception is when the room is totally dark, it returns 0. 

Wish I could use the LDR light sensor instead of the LDR + 1k Ohm resistor + breadboard.
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2566
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Effect, as you described it, likely related to big time constant of the circuitry. Which is completely LDR sensor bias resistor fault selection , or could be some on-board electrolytic cap If there is any, as I don't have a schematic and can't see reverse side of the board. (probably you can post high resolution pictures both side of the board).
Ether way, it's design flow, prototype should be tested thoroughly  before production.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, Magician,

I use the following boards:
  • Arduino UNO
  • Sensor Shield V04, which is mounted on the top of UNO
  • Phidget Precision Light Sensor, a Arduino sensor cable is connected between Sensor Shield and the Sensor
  • LDR Light Sensor, front (http://alturl.com/qwcfh) & back (http://alturl.com/vggkp) pictures

The UNO and the Sensor Shield are the Arduino official products. The Phidget light sensor works fine.  So, I think you need the picture of LDR light sensor.

Let me know, if I need to provide more detailed information.  smiley-grin
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2566
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Shield isn't the same with shield you posted a link to in first post. I was hoping get better quality pictures, can't see a trace. IMHO, it's unlikely, you can do anything in order to fix it.

edited:
There is a link that explain what  are missing components for:
http://iteadstudio.com/store/index.php?main_page=product_info&cPath=62_65&products_id=461

« Last Edit: August 07, 2011, 09:24:50 pm by Magician » Logged

0
Online Online
Faraday Member
**
Karma: 45
Posts: 5789
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

try to use the LDR only, without IC


Logged

- [Guida] IDE - http://goo.gl/ln6glr
- [Lib] ST7032i LCD I2C - http://goo.gl/GNojT6
- [Lib] PCF8574+HD44780 LCD I2C - http://goo.gl/r7CstH

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, Magician & Testato,

The image of my LDR light sensor (the latter one) is different my first post.  Do you mean you need the image from different angles?

I used a 100K ohms resistor + LDR and get the following results http://alturl.com/dt2zt
I'm not sure whether the lux equation is correct or not.  Here is my code:
Code:
#define LDR_LIGHT_PIN  A1
#define PHID_LIGHT_PIN  A4

/*----( SETUP: RUNS ONCE )----*/
void setup()
{
   pinMode(LDR_LIGHT_PIN, INPUT);  // for LDR light sensor
   pinMode(PHID_LIGHT_PIN, INPUT);  // for Phidget lighet sensor
   Serial.begin(9600);             // Enable the Serial data output
   Serial.println("#------- Test Light Sensors ---------");
   Serial.println("#time (sec), LDR, Phidget Precision--");
}
/*--(end setup )---*/


/*----( LOOP: RUNS CONSTANTLY )----*/
void loop()
{  char str[40];   // string for results printing

   // calculate the voltage, v_out = analog reading * 5V / 1024
   float v_out = analogRead(LDR_LIGHT_PIN) * 0.0048828125;

   // calculate the illumination, 100K Ohms,
   int lux = 500 / ( 100.0 *( (5.0 - v_out) / v_out ) );

   // print the luminous
   sprintf( str, "%06ld, %4d, %4d \0", millis()/1000, lux, analogRead(PHID_LIGHT_PIN) );
   Serial.println( str );

   delay(5000);                          // Wait 5 second
}
/*--(end loop )---*/
Logged

0
Online Online
Faraday Member
**
Karma: 45
Posts: 5789
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so now it work ?
why not used 10K res like in the schematics ?
you may use a pot for calibrate the LDR to the other sensor result
Logged

- [Guida] IDE - http://goo.gl/ln6glr
- [Lib] ST7032i LCD I2C - http://goo.gl/GNojT6
- [Lib] PCF8574+HD44780 LCD I2C - http://goo.gl/r7CstH

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, Testato

I do not have 10K ohms resister in hand, can only find the 100k one. 

Actually, If anyone could help me to figure out  the problem of my  LDR sensor module that will be great. 

The LDR + resister is just another exercise for learning how to calculate the lux, and wish can know whether my lux equation is correct or not?
Logged

Pages: [1] 2   Go Up
Jump to: