Measure nightsky with TSL237

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