Measure nightsky with TSL237

minaya:
@GoForSmoke, each star contributes to the 'total' flux on the sky with the same amount of photons no matter how the sky is polluted.

There must be something you say that I don't understand.

Parts of the sky, especially at low alt, do get a lot of particles/dust from natural and man-made sources. At night here we have electric generation stations do their stack cleaning (evidenced by the crap laid down for miles with lead, cadmium and mercury as well as sulfur compounds). For well over 10 years now the pall running from India clear across China has cut sunlight by 15% and more, reducing crop yields. Even CLOUDS reflect light back to space... water and dust pollution!

Somehow I don't think that all the photons from Sirius make it to Earth surface. Flying over Earth it's possible to see how much dust and humidity in the lower atmosphere blur details compared to up in the mountains from the same AGL. And up in the mountains where the air is thinner and doesn't have such a load of junk (first time I really understood was on Pike's Peak) objects miles away look very clear where at sea level they're blurred in less than 2 miles.

When a big volcano pops (Krakatoa around 1880) the whole planet cools just from the dust.

Does starlight get through all that with the same photon count? Sunlight doesn't and the Sun is a star.

I've had the chance to see the night sky from 6500 ft (the saddle between Mauna Loa and Mauna Kea) and 8000-9000 (central north New Mexico) up away from any cities before and wow, the sky doesn't just look more clear but far brighter.

Corpze:
Thanks for your very good answer, i will use the meter for my own, to measure different sites where i do my astrophotographing.

For the ZP i have a luxmeter that i can use, it will not be scientific grade, but good enough for me!

It´s just one thing left, does anyone know what kind of "lensmodule" i have marked on the picture?

Oh, and one more question; The code i am gonna start out with is this: How to: Light to Frequency Converter - TSL235R? - #17 by madepablo - Interfacing - Arduino Forum

But will that work? it is written for a Arduino duemilanove?

@GoForSmoke.

I didn't mention the important 'extinction' effect (I was just talking about the 'light pollution' effect only, the photons added by human activities). Of course, dust particles extincts and scatters the radiation of objects that are outside the atmosphere, but normally the human effect here isn't as important as one thought (maybe in heavy polluted cities). The main effect of those particles is to reflect the scattered light that comes from cities to the outside.

In high altitude mountains like Mauna Kea, Atacama, Roque de los Muchachos aerosols (these atmospheric particles you mention) abundance is relatively low, and thus is the effect on the night sky.

But of course, if the sky is foggy/cloudy o very polluted (like in Pekin or even at desert with sand storms), you won't see anything. ;).

Which is why I asked about calibration using known magnitude objects . And the haze from India to China and beyond, 15% less sunlight is just scary IMO.

The naked eye view from over 1 mile alt is just freaking amazing! It's better than Hubble pics. Everyone should have the chance. I wonder how few nowadays have every seen the Milky Way as a solid band?

Corpze:

Corpze:
Thanks for your very good answer, i will use the meter for my own, to measure different sites where i do my astrophotographing.

For the ZP i have a luxmeter that i can use, it will not be scientific grade, but good enough for me!

It´s just one thing left, does anyone know what kind of "lensmodule" i have marked on the picture?

Oh, and one more question; The code i am gonna start out with is this: How to: Light to Frequency Converter - TSL235R? - #17 by madepablo - Interfacing - Arduino Forum

But will that work? it is written for a Arduino duemilanove?

Ok, so iv'e hooked up the sensor but it just recieves 0pulses, 0khz and 0 uw... but in the code, i can´t se that the sensor input pin is initialized? i have hooked it up to pin 5, maybe it is initialized in the freqCounter.h lib?

INPUT LOW is the default state for all I/O pins. It makes them safer for one, kind of a NULL state as opposed to starting up as OUTPUT LOW or HIGH.

I connected the capacitor wrong :stuck_out_tongue: Now it works like a charm... XD

I wonder how and where i am gonna put the formula for converting uW/cm2 to mag/arcsecond2, (according to minaya, its this formula;
ZP - 2.5*log10(frequency) where ZP is my ZeroPoint i will calculate that after i have revcieved the lens if i could find one :~ )
in this code:

#include <FreqCounter.h>



long irradiance;
long freq;
long  pulses;
const float area = 0.0092;
int cnt;
int pinLed=13;
short period = 100; // 100 ms Gate Time

void setup() {
  pinMode(pinLed, OUTPUT);
  Serial.begin(115200);        // connect to the serial port
  Serial.println("Frequency Counter");
}

void loop() {
 light();
 Serial.print(cnt++);
 Serial.print("  Pulses: ");
 Serial.print(pulses);
 Serial.print(";  Freq: ");
 Serial.print(freq);
 Serial.print(" Hz;  Irradiance: ");
 Serial.print(irradiance);
 Serial.println(" uW/cm2 = KHz");
 delay(1000);
}  

void light(){
  digitalWrite(pinLed, HIGH);
  FreqCounter::f_comp=10;   // Cal Value / Calibrate with professional Freq Counter
  FreqCounter::start(period);  // 100 ms Gate Time
  while (FreqCounter::f_ready == 0)
  pulses=FreqCounter::f_freq;
  delay(20);
  digitalWrite(pinLed, LOW);
  freq = (pulses*1000)/(period*area);
  irradiance = (freq/1000);
  return ;
}

You have the code to measure the frequency, so you need to put the conversion to magnitudes after that :wink: . Don't forget to declare the variable in which you want to save the 'mag/arcsec2' value (maybe as global var?). You have an excelent example in how the code you used defines and prints through Serial the variable Irradiance. Just mimic that (change the math expression).

log10 is included in <math.h> library, don't forget to include it in the header of you sketch.

I hope that 32-bit floats in the formula won't spoil your accuracy. They'll certainly slow your code down as Arduino has no FPU.

There are alternatives like BCD, fixed-point 64-bit integers and Nick Gammon's big number library.

Ok, 1st try for the formula, does this look ok to you guys?
I also coded a button witch i want to make the measurements start (not with the button pressed down all the time but once) i am not sure if that is what i asigned in the code?

If i want to make ,say three measurements, and then take the median (freq1 + freq2 + freq3 / 3) ? for increasing the accuracy, where to put a code like that?

Thanks for the help :slight_smile: i am a total novice on this :stuck_out_tongue:

#include <FreqCounter.h>
#include <Math.h>


long irradiance;
long freq;
long pulses;
long magnitude;
const float ZP = 12; // "Zero Point" i just picked a random nr for now, not calibrated)
const float area = 0.0092;
int cnt;
int pinLed=13;
int buttonSQM = A2;
short period = 100; // 100 ms Gate Time

void setup() {
  pinMode(pinLed, OUTPUT);
  pinMode(buttonSQM, INPUT);
  digitalWrite(buttonSQM, HIGH);
  Serial.begin(115200);        // connect to the serial port
  Serial.println("Frequency Counter");
}


void loop() {
 light();
 Serial.print(cnt++);
 Serial.print("  Pulses: ");
 Serial.print(pulses);
 Serial.print(";  Freq: ");
 Serial.print(freq);
 Serial.print(" Hz;  Irradiance: ");
 Serial.print(irradiance);
 Serial.println(" uW/cm2 = KHz");
 Serial.print(magnitude);
 Serial.print(" Mag/Arcsecond2 ");
 
 delay(1000);
}  

void light(){
  if (buttonSQM = HIGH)
  digitalWrite(pinLed, HIGH);
  FreqCounter::f_comp=10;   // Cal Value / Calibrate with professional Freq Counter
  FreqCounter::start(period);  // 100 ms Gate Time
  while (FreqCounter::f_ready == 0)
  pulses=FreqCounter::f_freq;
  delay(20);
  digitalWrite(pinLed, LOW);
  freq = (pulses*1000)/(period*area);
  irradiance = (freq/1000);
  magnitude = ZP - 2.5*log10(freq);

  return ;
}

Corpze:
Ok, 1st try for the formula, does this look ok to you guys?
I also coded a button witch i want to make the measurements start (not with the button pressed down all the time but once) i am not sure if that is what i asigned in the code?

If i want to make ,say three measurements, and then take the median (freq1 + freq2 + freq3 / 3) ? for increasing the accuracy, where to put a code like that?

Thanks for the help :slight_smile: i am a total novice on this :stuck_out_tongue:

#include <FreqCounter.h>

#include <Math.h>

long irradiance;
long freq;
long pulses;
long magnitude;
const float ZP = 12; // "Zero Point" i just picked a random nr for now, not calibrated)
const float area = 0.0092;
int cnt;
int pinLed=13;
int buttonSQM = A2;
short period = 100; // 100 ms Gate Time

void setup() {
  pinMode(pinLed, OUTPUT);
  pinMode(buttonSQM, INPUT);
  digitalWrite(buttonSQM, HIGH);
  Serial.begin(115200);        // connect to the serial port
  Serial.println("Frequency Counter");
}

void loop() {
light();
Serial.print(cnt++);
Serial.print("  Pulses: ");
Serial.print(pulses);
Serial.print(";  Freq: ");
Serial.print(freq);
Serial.print(" Hz;  Irradiance: ");
Serial.print(irradiance);
Serial.println(" uW/cm2 = KHz");
Serial.print(magnitude);
Serial.print(" Mag/Arcsecond2 ");

delay(1000);
}

void light(){
  if (buttonSQM = HIGH)
  digitalWrite(pinLed, HIGH);
  FreqCounter::f_comp=10;   // Cal Value / Calibrate with professional Freq Counter
  FreqCounter::start(period);  // 100 ms Gate Time
  while (FreqCounter::f_ready == 0)
  pulses=FreqCounter::f_freq;
  delay(20);
  digitalWrite(pinLed, LOW);
  freq = (pulses1000)/(periodarea);
  irradiance = (freq/1000);
  magnitude = ZP - 2.5*log10(freq);

return ;
}

Ok, this is the result so far, i don´t think it can go lower than 1086hz, but why? And it doesn´t matter if i change the delay to 4000ms either :confused:

úFrequency Counter
0 Pulses: 0; Freq: 0 Hz; Irradiance: 0 uW/cm2 = KHz
-2147483648 Mag/Arcsecond2 1 Pulses: 1736; Freq: 1886956 Hz; Irradiance: 1886 uW/cm2 = KHz
-3 Mag/Arcsecond2 2 Pulses: 10; Freq: 10869 Hz; Irradiance: 10 uW/cm2 = KHz
1 Mag/Arcsecond2 3 Pulses: 1; Freq: 1086 Hz; Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 4 Pulses: 1; Freq: 1086 Hz; Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 5 Pulses: 1; Freq: 1086 Hz; Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 6 Pulses: 1; Freq: 1086 Hz; Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 7 Pulses: 1; Freq: 1086 Hz; Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 8 Pulses: 1; Freq: 1086 Hz; Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 9 Pulses: 1; Freq: 1086 Hz; Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 10 Pulses: 1; Freq: 1086 Hz; Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 11 Pulses: 1; Freq: 1086 Hz; Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 12 Pulses: 1; Freq: 1086 Hz; Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 13 Pulses: 1; Freq: 1086 Hz; Irradiance: 1 uW/cm2 = KHz

Corpze:
If i want to make ,say three measurements, and then take the median (freq1 + freq2 + freq3 / 3) ?

Operation order will screw that up. Only the last will be divided.

((freq1 + freq2 + freq3) / 3) is what you want, if that is really what you want to do **.

Extra parenthesis can't hurt unless they're in the wrong place or not balanced (as many opens as closes). If in doubt, use them. The compiler doesn't add code for extras.

**

Pulses: 10; Freq: 10869 Hz

If you averaged the 10 pulses as above, you would lose the last digit, have no rounding....

You could do something like (untested pseudo code alert!) this for rounding

samples = 3 // could be 10 for instance
freq = ((freq1 + freq2 + freq3 + samples / 2) / samples)

GoForSmoke:

Corpze:
If i want to make ,say three measurements, and then take the median (freq1 + freq2 + freq3 / 3) ?

Operation order will screw that up. Only the last will be divided.

((freq1 + freq2 + freq3) / 3) is what you want, if that is really what you want to do **.

Extra parenthesis can't hurt unless they're in the wrong place or not balanced (as many opens as closes). If in doubt, use them. The compiler doesn't add code for extras.

**

Pulses: 10; Freq: 10869 Hz

If you averaged the 10 pulses as above, you would lose the last digit, have no rounding....

You could do something like (untested pseudo code alert!) this for rounding

samples = 3 // could be 10 for instance

freq = ((freq1 + freq2 + freq3 + samples / 2) / samples)

I will try that, but what about the frequency, why can´t it go any lower than 10869 Hz? I haven´t calibrated the ZP yet, can it be the problem?

Corpze:
I will try that, but what about the frequency, why can´t it go any lower than 10869 Hz? I haven´t calibrated the ZP yet, can it be the problem?

For single samples you get 1086. Why? I don't know!

freq = (pulses1000)/(periodarea);

Is it any surprise that 10 pulses gets 10x the freq?

Also you should mix your mixed-types math.
As above you have by types: long = (long * int) / (short * float) <<=== not a good idea

That whole business needs a total going-over.
You can throw in casts (tell the compiler to treat a variable as a different type) but if you're not careful you won't get the equation you think. Without casts, as it is now, you're letting the compiler decide.

Example of casting:
long L;
int I = 1000;
float F = 0.1;

L = (long) ((float I) * F);

And thanks to the floating point math, the result won't likely be 100L. Yes 100L because it's cast as a long to go into a long variable. 100 is a 16-bit signed integer. 100L is a 32-bit signed integer. If the letter U is used, 100U is a 16-bit unsigned integer and 100UL is a 32-bit unsigned integer.
If you use a constant and want it seen as a floating point then put in a decimal point, 100.0 is a 32-bit floating point value.

Give the compiler less room to wiggle and you may get more predictable results.

GoForSmoke:

Corpze:
I will try that, but what about the frequency, why can´t it go any lower than 10869 Hz? I haven´t calibrated the ZP yet, can it be the problem?

For single samples you get 1086. Why? I don't know!

freq = (pulses1000)/(periodarea);

Is it any surprise that 10 pulses gets 10x the freq?

Also you should mix your mixed-types math.
As above you have by types: long = (long * int) / (short * float) <<=== not a good idea

That whole business needs a total going-over.
You can throw in casts (tell the compiler to treat a variable as a different type) but if you're not careful you won't get the equation you think. Without casts, as it is now, you're letting the compiler decide.

Example of casting:
long L;
int I = 1000;
float F = 0.1;

L = (long) ((float I) * F);

And thanks to the floating point math, the result won't likely be 100L. Yes 100L because it's cast as a long to go into a long variable. 100 is a 16-bit signed integer. 100L is a 32-bit signed integer. If the letter U is used, 100U is a 16-bit unsigned integer and 100UL is a 32-bit unsigned integer.
If you use a constant and want it seen as a floating point then put in a decimal point, 100.0 is a 32-bit floating point value.

Give the compiler less room to wiggle and you may get more predictable results.

To be honest, i don´t understand anything of what you just wrote :confused:

Maybe i should just start over with a basic frequency counter and go from there?

Basicly, all i wanna do is translate frequence to mag/arcsecond2, and because the sensor is linear, wouldn´t it be quite easy to do that?

I am fairly new to arduinos and coding, i have just got a steppermotor to work with two buttons and a lcd-display :confused:

Is this the way to go maybe?:

I have one sensor, capable of sending between 0.00x Hz to 1000kHz
I also have a luxmeter, so i can calibrate the sensorvalue roughly.

if i has a light that shines with 100 lux, and the sensor is sending 20 kHz, can i from there convert to mag/arcsecond2?

I dont need any pulsecounter any else of the data, i am just interested of Mag/AS2

Is this possible?

BR/ Daniel

How about get the setup working without converting to frequency and -then- take that step?

Just show the pulses, your raw data, as you point at darker or lighter things right in the house. That will let you test and debug everything but the convert and I and or others will walk you through the conversion to the best of our abilities?

That sounds good :slight_smile:

But you are talking about pulses, the sensor outputs a frequency, that isn´t the same?

is Pulse the time and freq the hight of the wave? And the dutycycle of the sensor is 50%, is that because it ouputs a square wave or something?

I did all the maths in the sketch last night, just to see how things work together like pulses, frequency an so forth. One thing i i stumbled upon is the "Gate time", what exactly is that, because that one is set to 100ms in the sketch, but somwhere on the internets, i read that the Gatetime should be set to 1000ms to get "the true freq of the sensor"?

//

But you are talking about pulses, the sensor outputs a frequency, that isn´t the same?

I'm just going off your variable names.
How about leaving this part out until you have reliable 'pulses' then?

  freq = (pulses*1000)/(period*area);
  irradiance = (freq/1000);
  magnitude = ZP - 2.5*log10(freq);

that's where your mixed-types math is a totally different issue, let's cut that in the attempt to troubleshoot and get back to it when the rest is ready.

Starting from scratch;

This codes fetches just the freq, nothing else...

#include <FreqCounter.h>


void setup() {
  Serial.begin(57600);                    // connect to the serial port
  Serial.println("Frequency Counter");
  
}

long int frq;
void loop() {

 FreqCounter::f_comp= 8;             // Set compensation to 12
 FreqCounter::start(1000);            // Start counting with gatetime of 100ms // CHANGED TO 1000/
 while (FreqCounter::f_ready == 0)         // wait until counter ready
 
 frq=FreqCounter::f_freq;            // read result
 Serial.println(frq);                // print result
 delay(20);
}

and this is the serial monitor:

;1Frequency Counter
0
39313
39342
39573
39757
39835
39816
38690
31962
8259
7940
7956
7564
27334
5070
966
273
39
31
31
30
30
31
1087
32437
34741

where 30-ish is almost completely black.

The Irradiance responsivity for my sensor is 2.3 kHz/(uW/cm2)
and the integrated photodiode active area is 0.92 mm2 in size

How should the formula look for converting my hz to mW/cm2?

And what gatetime should i use? Martin Nawrath sais that "The Gate Time for the counting period can be chosen in the start() function where values of 10, 100 or 1000 ms are practicable for a resolution of 100, 10 and 1 Hz but any value can be used. The internal resolution of the gatetime is 2 ms so that the time can be varied in the increment of 2."

Does that means that if i use a gatetime of 1000ms, i will be viewing my sensor in Hz, and if i use the 100ms that is used in the freqcountersketch, i will be viewing the sensor in Hz/10?

Is this really the right formula? ZP - 2.5*log10(frequency) ?