SQM Components 

1. 1x Arduino MEGA
2. 1x Light to frequency converter TLS237S
3. 1x Temperature sensor DS18S20
4. 1x Resistor 4,7Κ
5. 1x Capacitor 0,1uF
6. 1x LCD Display  + 10k trimmer
7. 2x Switch ON-OFF
9. 1x RF transmitter and receiver 433Mhz MX-05V & MX-FS-03V
10. Fish eye lens
11. IR-Cut filter

 

 

 

#include <OneWire.h>
#include <VirtualWire.h>
#include <LiquidCrystal.h>

/*Ioannis A. Bouhras - ioannis_bouhras@zeuslinux.gr*/

// 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 SEND


LiquidCrystal 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  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

 te data[12];
 te 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

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

 
 for (int i = 0; i < 9; i++) { // we need 9 tes
  data[i] = ds.read();
 }
 
 ds.reset_search();
 
 te MSB = data[1];
 te LSB = data[0];

 float tempRead = ((MSB << 8)  LSB); //using two's compliment
 float TemperatureSum = tempRead / 16;
 
 return TemperatureSum;
 
}

Sample output

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