Arduino Sky Quality Meter (SQM)

 

 

Components1. Arduino Mega Controller2. Lignt Sensor TLS237S

3. Temperature Sensor DS18S20

4. 4,7K resistor

5. 0,1uF Capacitor

6. LCD Display

7. 10k Trimmer

8. RF transmitter and receiver 433Mhz MX-05V & MX-FS-03V

9. Fisheye lens

10. IR-Cut filter

 

 

Arduino Micro Controller Sketch

 #include <OneWire.h>
#include <VirtualWire.h>
#include <LiquidCrystal.h>/*Ioannis A. Bouhras – ioannis.bouhras@observatories.eu*/// FREQ START
float Msqm;
const float A = 30.0;
int TSL237S_Pin = 7; //TSL237S output
int TSL237S_samples = 6; //higher = slower but more stable and accurate
// FREQ SENDLiquidCrystal lcd (12, 11, 5, 4, 3, 2);

char charnum[10];

int DS18S20_Pin = 8; //DS18S20 Signal pin on digital 2

//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2

void setup(void) {

Serial.begin(9600);
delay(1000);
lcd.begin(16,2);
lcd.print(“Arduino SQM 1.0″);
delay(3000);
lcd.clear();
float lightLevel = readTSL237S(TSL237S_samples);
lcd.print(lightLevel);
lcd.print(” Mag/As2″);

/*SETUP TRANSMITER*/
vw_set_ptt_inverted(true);  // Required by the RF module
vw_setup(2000);            // bps connection speed
vw_set_tx_pin(9);         // Arduino pin to connect the receiver data pin
}

void loop() {

lcd.print(“OK”);

float Celcius = getTemp();

Serial.print(Celcius);

float Fahrenheit = Celcius * 1.8 + 32;

Serial.print(” “);

Serial.print(Fahrenheit);

Serial.print(” “);

float lightLevel = readTSL237S(TSL237S_samples);
Serial.print(lightLevel);

Serial.print(” “);

Serial.print(lightLevel – 19.00);

Serial.println(” “);

delay(300); //just here to slow down the output so it is easier to read

char buff[30];

/*Transmit our data*/

int tempC1 = (int)Celcius;
int tempC2 = (int)Fahrenheit;
int tempC3 = (int)lightLevel;
int magLim = (int)lightLevel – 19;

char msg[24];

sprintf(msg, “%i %i %i %i”, tempC1,tempC2,tempC3,magLim);

vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();        // We wait to finish sending the message
delay(200);         // We wait to send the message again

}

float readTSL237S(int samples){
//sample light, return reading in frequency
//higher number means brighter

float start = micros();
int readings = 0;

while(readings < samples){
pulseIn(TSL237S_Pin, HIGH);
readings ++;
}

float length = micros() – start;
float freq = (1000000 / (length / samples)) * 10;

Msqm = A – 2.5*log10(freq);

return Msqm;
}

float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}

if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println(“CRC is not valid!”);
return -1000;
}

if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print(“Device is not recognized”);
return -1000;
}

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}

ds.reset_search();

byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB); //using two’s compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;

}

 

 

Sample Output: Celcius Fahrenheit Squims(Mag/As2) NELM(Naked Eye Limiting Magnitude)

 

26 80 19 3
26 79 19 4
26 79 19 4
26 79 19 4
26 79 19 4
26 79 19 4
26 79 19 4
26 79 19 4