FreqCounter for very low frequencies (below 100 Hz or something) isn't the best thing you can do to count cycles.

As someone told you, you would need to measure the length of the pulse instead (FreqMeasure, FreqPeriod, InputCapture, pulseIn, millis()/micros() ). Since at dark time it's rare to get more than 10,000Hz with those sensors, I think FreqCounter isn't useful at all for this project.

Is the limit in the FreqCounter library? i was thinking to count Hz as the sensor itself generates Hz, not pulses... or am i missing something? The sensor is the TSL237 light to frequency sensor.

You can count the time length of a number of pulses, the more you count the more the per-pulse average will ... average out.

You can count how many pulses in a measure of time and lose a fraction of a pulse. The longer the time the less the lost fraction means.

pulses/time or time/pulses, both are ratios is all. Get one, you have the other.

That sound quite logical even to me is there any good library/code that i can use for this? I believe that, after counting time, i will be have to translate to time to Hz, in some way, and that Hz is more realible than just counting Hz straight from the sensor?

AHA! Now i understand the differens between pulses and freq, maybe this lib. is more suiteble for me?

http://interface.khm.de/index.php/lab/experiments/frequency-measurement-library/But he is writning: The library returns the measured period length in 1/16 us steps as a long integer. To get the frequency, the clock frequency has to divided by the returned value. The clock frequency is set in this example to 16000400 to compensate inaccuracies of the Arduino board.

What is that meaning for me and my arduino?

This might also work?http://www.pjrc.com/teensy/td_libs_FreqMeasure.html

I wouldn't use a library. I'd save micros() in an unsigned long, count 10,000 pulses and save the micros() right then. Annnnnd I think you can get micros() in an interrupt though it's stopped. If not then you'll pick up a couple micros setting a flag in the interrupt, leaving the interrupt and catching the flag in loop(). With a tight loop() you'll have micros() very quickly.

Errors --- you can measure Arduino inaccuracy and compensate. Deal with that after you get the rest working. It amounts to changing time microseconds

frequency = pulses / time

If the time is a 62845 microseconds then multiply pulses by 1 million then divide by 62845 to get Hz = cycles(pulses) per second.

When you do math for science, keep the units (pulses, seconds, ergs) in the math because at the end if your units don't make sense then your math didn't either. (this is where you remember your science teachers saying the same thing)

minaya

@GoForSmoke, 10,000 pulses?!. This would take a whole life if the site is dark. The TSL237 generates generates pulses of frequencies as low as ~0.15Hz in dark skies (even lower if you use filters). That's more than 6 seconds of period, so integrating 10,000 cycles seems a bad idea.

The best approach I think is to measure first one single pulse and decide (at runtime) if you want to count frequencies (or a great amount of pulses to promediate, as GoForSmoke suggested) or you need an alternative way to get the frequency.

Corpze, the SQM is *cheap* for what it does. If you take into account that those instruments need filters to cut the IR and narrow the spectral sensibility, needs some kind of optics to narrow the FoV, needs a case, an LCD, a board ... you end (in the arduino road) with an instrument that is nearly as expensive as the SQM (or even more!) and probably not as accurate (at least if you don't know what you do/need), trust me. And then, you need to calibrate the device.

If you want to build it just for learning purposes or something else, I think you need to return to the basics and stop trying to get inmediate results. I've been researching on this topic for months and I haven't found any library that just do what you want, sorry.

I had all the hardware at home, except for the sensor, UV/IR block filter and lens that on its way (5 USD worth of hardware) It is kind of a learning thingy, maybe it isn't any idéa of keep on going with this :/

If you count pulses for 1800 or even 180 seconds and something bright doesn't intrude, you can get less error than if count 1 or 3 seconds. Can get... because there's always a way to can't anything.

If you count pulses and see that a certain time has elapsed then you will be off by the fraction of the last pulse that didn't make it unless you exactly end the time period on a pulse start. So there you have the fraction error but that is divided by the number of pulses when you determine the average length of just 1 pulse (the inverse of frequency) so the more pulses, the better.

To do that, have an interrupt increment the pulse count and in loop() set up a timer the way it's done in BlinkWithoutDelay and when the interval is reached, copy pulse count and use that with the time interval you set up, do the math and you can have frequency. The longer the interval, the closer to precise you can be as long as something doesn't intrude on the patch of sky you're watching.

OTOH you can set up an interrupt to count some number of pulses and see how long that took, maybe completely in the IRQ. Then your loop() code just watches for the IRQ to update the how-long-it-took variable and report that. You will have pulses and time.

Why not a library? You keep wondering what library to use. You keep wondering if the library you use is the problem. That's because you don't know what they do and it is a problem trying to troubleshoot with such an unknown.

In this case what the library does is not difficult and you will doubtless benefit from learning. Just take your time, identify what it is your don't know and learn those pieces as you put it together.

So you have used interrupts and know to make variables used in interrupts as volatile?And you know that time is kept in unsigned long variables?

How long can you aim at dark sky to get measurements? 3 seconds? 30 s? 300 s? 30 minutes?

Maybe the best way will be to count pulses and see how long that takes. ....You understand, if I stop when pulse count is done I can know how many whole usecs (microseconds) it takes but I can't know the fraction of a usec after the last full usec. If it was 400001.7 usecs, I will miss the .7. That is an unavoidable (and small) source of error. If I stop on a time count while also counting pulses then I can know the usecs and how many pulses but not the fraction. If 100 seconds takes 50.8 pulses, my 100 second read only sees 50.....Since pulses are so big compared to usecs there will be more possible error counting over a set time than counting a set number of pulses and seeing how long that took. I would rather have a fraction of a usec (really, Arduino is good to 4 usecs which is still very small) as error than a fraction of a much bigger pulse as error. What decides the method for me is the way with the smaller error. In this case, it's pretty clear?

So big open to the forum just to be sure question --- can you read micros() in an interrupt?

So you have used interrupts and know to make variables used in interrupts as volatile?And you know that time is kept in unsigned long variables?

How long can you aim at dark sky to get measurements? 3 seconds? 30 s? 300 s? 30 minutes?

Maybe the best way will be to count pulses and see how long that takes. ....You understand, if I stop when pulse count is done I can know how many whole usecs (microseconds) it takes but I can't know the fraction of a usec after the last full usec. If it was 400001.7 usecs, I will miss the .7. That is an unavoidable (and small) source of error. If I stop on a time count while also counting pulses then I can know the usecs and how many pulses but not the fraction. If 100 seconds takes 50.8 pulses, my 100 second read only sees 50.....Since pulses are so big compared to usecs there will be more possible error counting over a set time than counting a set number of pulses and seeing how long that took. I would rather have a fraction of a usec (really, Arduino is good to 4 usecs which is still very small) as error than a fraction of a much bigger pulse as error. What decides the method for me is the way with the smaller error. In this case, it's pretty clear?

So big open to the forum just to be sure question --- can you read micros() in an interrupt?

No i haven´t really used interrupts more then those that allready have been written in existing code... I have read the reference about interrupts and there are two kinds? internal and external? the external ones are located on pin2 and 3 on the uno. Is one of those inputs usable for me?

I think 10sec will be the highest time i want to measure (the original SQM-meter measures on 2sec)

So 10000ms of measurements is a number i can start with.

I understand that i will lose the .x count of the pulses if the time runs out