Measure nightsky with TSL237

minaya:
@GoForSome, Using a LED as a sensor you mean?. I think the photosensitive area is pretty small here (and then the current it generates will be in the range of 1pA or even less), but it would be interesting to test them as their are super cheap and you can get them with any spectral range you want (different led colors).

There's a led as a light sensor sketch where you park a led and resistor between two pins. You charge the led as you would a capacitor and that <= 1 pA degrades the minute charge over time. In the dark it could take a few msecs at least, in the bright it could take less than 50 usecs. Mitsubishi Labs uses it for rock solid, dirt cheap wireless and to make self-adjusting brightness LCD's.

You're not trying to measure low current except as the time it takes to bring a digital pin LOW. It would only be as good as the calibration at best. But then just how to calibrate closely, I dunno.

Charge in a clear-lens IR led would degrade with near-IR and every higher frequency light. Leds with colored lenses filter what they get IIRC, and even that is used in some apps.

minaya:
@GoForSome, Using a LED as a sensor you mean?. I think the photosensitive area is pretty small here (and then the current it generates will be in the range of 1pA or even less), but it would be interesting to test them as their are super cheap and you can get them with any spectral range you want (different led colors).

The TSL237 is one of the most sensitive (well, tied with the TSL238, which is just the same but in other package format) photodiodes with integrated amp op and voltage to freq in the market now, but you will probably want to use some kind of IR-cut filter to cover the sensor because it's sensibility peaks on the red - near IR. The Sky Quality Meter (SQM) uses it as it's sensor, I think Corpze just want to build one of those himself.

One of the problems of these sensors is the huge range of frequencies you want to measure, from ~ 0.1 Hz (or even less in 'pristine skies' !) to nearly 1MHz.

I'm also doing some test in this field with the TSL238 and arduino, using FreqCounter (High Frequencies) and pulseIn for low frequencies, but this mix is far from perfect and it's giving me some headaches hehe.

Yep, thats right, i am gonna build my own SQM, IR and UV-filter is already on its way :slight_smile: But i still haven´t found any lens that matches the SQM-L lens... (40 degree, -20 - +20 degrees)

This is the code i am talking about: How to: Light to Frequency Converter - TSL235R? - #17 by madepablo - Interfacing - Arduino Forum

Wouldn't that go?

I wonder how the conversion from uW/cm2 to mag/sq arc second would look like, and print that out to the LCD :confused:

SQM lens is just a half-sphere ball lens (you can get them from Edmund Scientific). Those lenses have a really short focal length and a decent aperture.

About the code, every time I try to write an interrupt-driven counter, I end forgiving it and looking for alternatives because of problems like overflows, freezes with intense light (you can fix them, but I think it's not trivial). And they don't solve themselves the 'slow' frequency reading mode needed in very dark nights (mag>21). For that, you need to count the pulse period (which can be as long as 10 seconds or so on unpolluted skies).

The mag/arcsec2 conversion is as simple as doing

ZP - 2.5*log10(frequency)

where ZP is the zero point, which depends on each individual photometer (sensitivity of your sensor, the filter you are using, the lens characteristics). It's probably the hardest part of the project if you want to be accurate and you won't probably get 'scientific-level' values unless you can access already calibrated photodiodes / lamps to study the response of your system.

The LCD output is nearly trivial in arduino (both in normal LCDs and I2C ones) :wink:

Here is the breadboard of the SQM, i wonder what kind of lens it is?

Is the ZP specified in the datasheet or do i have to find that out for myself?

Best I could hope for would be a relative haze and back-scatter meter. :grin:
I'll leave the rest to you guys, the weather service and NASA.

Just a thought... If you know a star's magnitude as seen from orbit then could you judge sky quality by the apparent brightness?

@GoForSmoke, each star contributes to the 'total' flux on the sky with the same amount of photons no matter how the sky is polluted. In fact, in urban observatories it's very possible to do some limited photometry with objects that are bright enough. You just need to 'subtract' the background flux to the total (background object) flux and you get the net object flux.

The problem with light pollution is the 'photonic' noise it adds. This photonic noise, that scales with the root square of the flux (in photoelectrons) tends to make the observation of a particular object in the sky just impossible if it is dimm. This idea applies to digital astronomical images, but with your eyes the idea is somewhat similar.

@Corpze, the zero point needs to be measured for each individual photometric system, no matter if it's a telescope ccd, a camera with an objective lens or your little TSL photometers with IR-cut filter and lens. One way (maybe the recommended one) to measure it is using calibrated lamps and calibrated photodiodes as reference. But in the end, you can approximately calibrate it if you know someone who has a SQM or you have a digital camera capable to take fixed exposures images (you calibrate the camera filter lens system with absolute photometry as usual in astronomy, then determine the Night Sky Brightness at some point in the sky with your already calibrated camera, take some measures with the TSL pointing at that direction and derive an approximate Zero Point to match both measures).

As I said, this ZP calibration is (repeat after me) hard if you want to make your instrument scientific-grade. Depends of course in your particular interest, but sometimes people (even in scientific projects) just use them 'differentially'. If you just need to measure how the sky at some location compares to the sky at other locations (or how it changes over the time), you can even use the direct 'frequency' as your variable, no need to mess around on these strange unit systems hehe.

The frequency measured with these photodiodes increases linearly with the number of photons.

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. In fact, in urban observatories it's very possible to do some limited photometry with objects that are bright enough. You just need to 'subtract' the background flux to the total (background object) flux and you get the net object flux.

The problem with light pollution is the 'photonic' noise it adds. This photonic noise, that scales with the root square of the flux (in photoelectrons) tends to make the observation of a particular object in the sky just impossible if it is dimm. This idea applies to digital astronomical images, but with your eyes the idea is somewhat similar.

@Corpze, the zero point needs to be measured for each individual photometric system, no matter if it's a telescope ccd, a camera with an objective lens or your little TSL photometers with IR-cut filter and lens. One way (maybe the recommended one) to measure it is using calibrated lamps and calibrated photodiodes as reference. But in the end, you can approximately calibrate it if you know someone who has a SQM or you have a digital camera capable to take fixed exposures images (you calibrate the camera filter lens system with absolute photometry as usual in astronomy, then determine the Night Sky Brightness at some point in the sky with your already calibrated camera, take some measures with the TSL pointing at that direction and derive an approximate Zero Point to match both measures).

As I said, this ZP calibration is (repeat after me) hard if you want to make your instrument scientific-grade. Depends of course in your particular interest, but sometimes people (even in scientific projects) just use them 'differentially'. If you just need to measure how the sky at some location compares to the sky at other locations (or how it changes over the time), you can even use the direct 'frequency' as your variable, no need to mess around on these strange unit systems hehe.

The frequency measured with these photodiodes increases linearly with the number of photons.

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?

SQM-board.jpg

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?