how to use a light frequency sensor

I got my hands on one of these, but I have no idea of how to use it

It wasn't what i expected it to be, but since I have it I would like to know how to use it and what it is actually meant to do.

Thanks

This doesn't measure frequency, just intensity. The frequency it outputs, is proportional to the intensity. It's also basically an offset square wave that changes between HIGH and LOW logic states (+5v and 0v). So the quesion is: how do you measure frequency with the Arduino? The simplest technique I can think of is to use the period() function. I would guess that you need to call it twice since the first call may get an incomplete cycle. Frequency is the inverse of period, so then just use the specs in the datasheet to convert Frequency into light amplitude.
Why would someone want a sensor like this? Because they don't have a MCU with analog inputs! The Arduino analog inputs make many more, much simpler light sensors possible.
If you really wanted to measure light frequency, that sounds both very interesting and very tricky. I don't know of any solid state solutions, and digital spectrometers just sound expensive. Maybe a CCD could be hooked up to a prism setup and software could analyze the picture to do a frequency analysis. That sounds like an interesting experiment.

Did some test ing with that one last year. I recall that at high light intensities the Arduino got too many interrupts => blocking

give it a try

/*
 *    FILE: demo01.pde
 *  AUTHOR: Rob Tillaart
 *    DATE: 2011 05 16
 *
 * PURPOSE: prototype TSL235R monitoring  
 *
 * Digital Pin layout ARDUINO
 * =============================
 *  2     IRQ 0    - to TSL235R
 *
 * PIN 1 - GND
 * PIN 2 - VDD - 5V
 * PIN 3 - SIGNAL
 *
 */

volatile unsigned long cnt = 0;
unsigned long oldcnt = 0;
unsigned long t = 0;
unsigned long last;
unsigned long msec = 0;
unsigned int cf = 1466;  // cf = 10^0.166 * 1000 (figure 1 datasheet)

void irq1()
{
  cnt++;
}

///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup() 
{
  Serial.begin(115200);
  Serial.println("START");
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);
  attachInterrupt(0, irq1, RISING);
}

///////////////////////////////////////////////////////////////////
//
// MAIN LOOP
//
void loop() 
{
  msec = millis() - last;
  if (msec >= 1000)
  {
    last += msec;
    t = cnt;
    unsigned long hz = (t - oldcnt) * 1000 / msec;
    oldcnt = t;
    unsigned long mw = (hz * cf/1000 + 50)/100; // +50 == rounding last digit
    
    // smoothing possible...
    Serial.print("FREQ: "); 
    Serial.print(hz);
    Serial.print("\t "); 
    Serial.print(mw);  
    Serial.println(" mW/m2");
  }
}

// END OF FILE

Thank I will give it a try today :slight_smile:

Hello,

You can use the FreqCounter library which is very adapted to this kind of sensor's output. I use it for a HH10D humidity sensor which output a squarewave signal with a frequency depending of the humidity.

The following links should help you i think:
http://tushev.org/articles/electronics/43-measuring-frequency-with-arduino
http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/

Hope that it will help you :wink:

@darki03
How are your experiences with the HH10D sensor?
Accuracy ?
Precision?

Hello !

I'm really sorry because, for the moment, i can't answer you because i have only make RH measures (i buy the sensor recently) and i have no reference to estimate accuracy of the sensor. I will try to evaluate precision considering that my home's humidity is stable.

I'll inform you when the measure are done.

P.S: Maybe it is not the right place to ask this but is it possible to write csv files with processing ?

P.S: Maybe it is not the right place to ask this but is it possible to write csv files with processing ?

yes, from the examples

/**
 * SaveFile 2
 * 
 * This file a PrintWriter object to write data continuously to a file
 * while the mouse is pressed. When a key is pressed, the file closes
 * itself and the program is stopped. This example won't work in a web browser
 * because of Java security restrictions.
 */

PrintWriter output;

void setup() 
{
  size(200, 200);
  // Create a new file in the sketch directory
  output = createWriter("positions.txt");          // <<<< change name to .csv
  frameRate(12);
}

void draw() 
{
  if (mousePressed) {
    point(mouseX, mouseY);
    // Write the coordinate to a file with a
    // "\t" (TAB character) between each entry
    output.println(mouseX + "\t" + mouseY);   // <<<<<<<<<<<<< change \t to ,
  }
}

void keyPressed() { // Press a key to save the data
  output.flush(); // Write the remaining data
  output.close(); // Finish the file
  exit(); // Stop the program
}

Thank you for this very usefull example :wink: (i should have find it myself but my wife spying me and she don't like when i spend time on Arduino experimentations !)

So i have find the time to make further measures with HH10D sensor:

  • With processing i have recorded around 7 hours of frequency measurement with freqcounter library (1s gate time so 1 Hz resolution),
  • My sensor calibration parameters are: Sensitivity = 405 (12 bit coded, 4096 represent 1%/Hz) which represent a sensitivity of 0.0989 %/Hz. Offset = 7674 Hz),
  • RH in % is given by this formula : RH = (Offset - Fout)*Sensitivity/2^12,
  • So with this implementation, we can have a 0.1 % resolution (the datasheet indicates 0.08 % typical and 0.05% min/0.3 % max, a better resolution on the frequency measure can allow to check the sensor min resolution but needs a longer measurement gate time)
  • On the graph you can observe a room humidity dwell during about 2h30 after 4 hours of measure. During this dwell, the RH value is between 28.67% +/- 0.1 %, which indicates, for me, a good precision of the sensor (repeatability is announced at +/- 0.3 % in the datasheet).

Other performance parameters of the datasheet needs reference measure and probably a humidity controlled chamber.

In conclusion, it is a good sensor for my future project (weather station) and i think that datasheet performance parameters are reliable so the choice depends on your application requirements :wink:

Hope that it will partially answer to your questions :wink:

i should have find it myself but my wife spying me and she don't like when i spend time on Arduino experimentations !

Don't want to argue with your wife, but you can allways say that you do it to educate yourself with the latest in embedded and sensor technology.

Better explain what Arduino can do, and maybe she has interesting projects you both like, create a win win!

Although the program works excellent, it seems that the amplitude of the square wave increases when the sampling rate is increased
if (millis() - last >= 1000)
When I decrease to say 100, the amplitude increases.

I was puzzled by one of your comments in the program:
// smoothing possible...

Can you point me in the directions (sources) to reduce the amplitude or to smoothen the signal? I have already applied a 1st order low pass filter on the data, but it remains very spiky.
Or am I missing a crucial point?

depongo:
Although the program works excellent, it seems that the amplitude of the square wave increases when the sampling rate is increased
if (millis() - last >= 1000)
When I decrease to say 100, the amplitude increases.

I was puzzled by one of your comments in the program:
// smoothing possible...

Can you point me in the directions (sources) to reduce the amplitude or to smoothen the signal? I have already applied a 1st order low pass filter on the data, but it remains very spiky.
Or am I missing a crucial point?

First, you need to tell us how you measure the amplitude of the signal. Are you using an oscilloscope? The only instrument that will measure what you tell us you are measuring.

Paul

Hi Paul,
Thanks for replying to my post.
I’m trying to count the number of vehicles that pass in my street. For this I have built the TSL235 into a small monocular that is aimed at the street. Whenever a car passes, there is a sudden dip in the sensor value (or a peak depending on the position of the sun).
By closely looking at the data I can distinguish cars from trucks as the dip (or peak) is wider in the latter case.
I’m not really interested in absolute sensor values, merely a difference between different cases.

Basically, I am using the program that was posted by Rob Tillaart on Feb 9th 2012 in this thread.
Depending on the chosen sampling interval (originally set at 1000ms), the signal becomes very spiky. It seems that the shorter the sampling interval, the more spiky it gets.
I would like to apply a short sampling interval as I want to be able to distinguish between a car and a truck (even a slow driving car vs a high speeding truck).

To illustrate this spiky response (of which I assume is the amplitude of the square wave, but that could be my shortcoming) I have taken Robs program and changed the sampling interval from 10ms to 25ms to 50 ms and 100ms. See sketch and attached image which is just the output to the serial plotter (vertical axis = sensor value, horizontal axis = # sample) . The blue line is the sensor data and the orange line is a 1st order low pass filter.
Hope you can help me get rid of the fairly large spread in sensor data at short sampling intervals.

Arduino forum.png

TEST_LS_sampling_rate2.ino (1.26 KB)

Averaging the values will get rid of all the spikey values.

Paul

Hi Paul,

Averaging works excellent if every “high” is followed by a “low”. However, this is not the case. I have taken the previous graph and magnified it to see the details. See attached image (Arduinoforum MAGNIFIED).
It is important to know that the light that strikes on the sensor is a small LED shining at a constant brightness (250). Ambient light produces slightly different graphs.

What strikes me even more is the difference between the “highs” and “lows” at different sampling intervals:
10ms = 1000
25ms = 400
50ms = 200
100ms = 100

When multiplied, they all result in 10000. This cannot be a coincidence, hence I must be missing some fundamental understanding for which I’m seeking help.

Installing a capacitor does not solve the problem of “highs” and “low”.

Instead of averaging the signal as you suggested, I have tried a 1st order low pass filter on the data (the orange line). In principle this flattens the line to some extent, but then the signal becomes “sluggish”.

Upon further testing, I have placed the sensor in a pitch black container (no light). There is a peak every so many signals (see image Arduinoforum DARK) and again there is this correlation (slightly different):
10ms = 100
25ms = 40
50ms = 20
100ms = 10

I must be missing some fundamentals here….

Arduino forum MAGNIFIED.png

Arduino forum DARK.png