GA1A12S202 Lux Sensor Question

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
TerminalDosage
 
Posts: 5
Joined: Sat Nov 16, 2013 6:36 pm

GA1A12S202 Lux Sensor Question

Post by TerminalDosage »

Hi,
I'm reasonably new to Arduino platform so please excuse my greenness! I'd love to get a little help with the GA1A12S202 Lux Sensor I purchased a while back. I've connected it up just the same as in the tutorial and the sketch is the same too. I'm using an Arduino Mega 2560 with the sensor connected to analog pin 0 and, of course, ground to gnd and positive to 5v. I have also connected 3.3v to the external reference as stated in the tutorial.

Not surprisingly, everything works as expected when receiving regular daylight (Stable readings with very little variation). However, I'm trying to measure the brightness of a DLP projector and therefore the light is of a structured nature (Using the projectors' internal white test pattern) The measurements taken become quite erratic (Maybe 100-300 lux or more variation between each measurement)

When using a scope to measure the signal from the sensor the following waveform is observed, which may explain the reason for the erratic results as under daylight conditions the waveform is a simple horizontal line.

Image

Now, my main question is, is there a way to overcome this issue to get a nice stable measurement?

Thanks for any advice.

Matt

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: GA1A12S202 Lux Sensor Question

Post by adafruit_support_bill »

I think you need to take the average of many readings over a sample window that is some multiple of that wave-form wide.

TerminalDosage
 
Posts: 5
Joined: Sat Nov 16, 2013 6:36 pm

Re: GA1A12S202 Lux Sensor Question

Post by TerminalDosage »

Thanks for the reply, I have the following code. Just like to check if this makes sense to you based on the scope readings. Also using the statistic library.

Code: Select all

#include "Statistic.h"  // without trailing s
Statistic myStats; 
int sensorPin = A0;    // select the input pin for the potentiometer
float rawRange = 1023; // 3.3v
float logRange = 3.3; // 3.3v = 10^5 lux
unsigned long previousMicros;
const unsigned long interval = 83333UL; 

void setup(void) 
{
  analogReference(EXTERNAL); //
  Serial.begin(9600);
  myStats.clear(); //explicitly start clean
  previousMicros = micros();
}
 
void loop(void) 
{
  while (micros() - previousMicros <= interval)
  {
    previousMicros += interval;
    // read the raw value from the sensor:
    int rawValue = analogRead(sensorPin);    
    long rn = rawValue;
    myStats.add(rn/100);
  
    if (myStats.count() == 16)
    {
      Serial.print("Average Lux = ");
      Serial.println(RawToLux(myStats.average()*100));
      myStats.clear();
    }
  }
}

float RawToLux(int raw)
{
  float logLux = raw * logRange / rawRange;
  return pow(10, logLux);
}

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: GA1A12S202 Lux Sensor Question

Post by adafruit_support_bill »

I think you want to update previousMicros outside of the while loop:

Code: Select all

  previousMicros = micros();  // time at the start of the loop
  while (micros() - previousMicros <= interval)  // loop until 'interval' has elapsed
  {
    ...
  }

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”