Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
KFMAKR
Published © GPL3+

Pyranometer

Like a real pyranometer, realize a measurement of sun power.

IntermediateWork in progress10,625
Pyranometer

Things used in this project

Story

Read more

Custom parts and enclosures

Technical Drawing

All parts are PLA 3D printing

Schematics

Electrical Diagram

Code

SunPowerOnly.ino

Arduino
Code extracted from the main program of my weather station. Building successful but could hold some useless lines
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
#define dataPin  5
#define clockPin 4

volatile int top, top60, top10, Count_Rain, topD;
volatile float SunPower, SunPowerInt, varCompteur;

float SunPowerAvg, temperature, humidity, dewpoint, pressure,SunPowerMin, SunPowerMax, voltage, angle;
const int chipSelect = 10, LedOnTimeRTC = 20, LedOnTimeWIND = 10;
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
String File_record = "Test341A", Dir;

//------------------------------------------------------------------------------------------------------------------------
void setup ()
{
  Serial.begin(9600);
 
  Serial.print("Version: "); Serial.println(File_record);
  Serial.println("Initializing SD card...");
  if (!SD.begin(chipSelect)) {Serial.println("Card failed, or not present");return;}
  Serial.println("card initialized.");
  
  File dataFile = SD.open(File_record, FILE_WRITE); 
  if (dataFile) { dataFile.println("Date ; Heure ; Max Speed ; Average speed ; Rafale ; Direction ; SunPowerAvg; SunPowerMin; SunPowerMax; Rain Level; Temperature ; Humidity ; Dewpoint; Pressure; Lux Avg; Lux Min; Lux Max; Index_day; Index_Hour; glitch; AvgWSFS; MxWSFS; altFOV10; tObjetFOV10; AmbientFOV10; MaxtObjetFOV10; altFOV90; tObjetFOV90; AmbienFOV90; MaxtObjetFOV90; Version; File"); dataFile.close();}  
    

  attachInterrupt (digitalPinToInterrupt(18), Flash_RTC , RISING );    // SQW RTC

  
  Wire.begin();                     // Join i2c bus for TSL2561 , MPL3115A2 & DS1307
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0x07);
  Wire.write(0x10);
  Wire.endTransmission();

  TCCR3A = 0b00000001;
  TCCR3B = 0b00000001; //no prescaling => period 1micro-s    
  TIFR3  = 0b00000001;   


  // Delai de synchronisation sur la minute pleine------------------------------------------------------------------------
  
  do {getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); top = -1;} while(second  != 0);

  top10 = 0 ;
  top60 = 0 ;

} 

//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
// BOUCLE PRINCIPALE
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
void loop ()
{ 
 
  if (bitRead (TIFR3, 0) == 1) {bitSet (TIFR3, TOV3) ; varCompteur++ ;}
  
  SunPower = (analogRead(A1) * (5.0 / 1023.0)) * 698;
  
  if ( top == 600 ) 
  {
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  Serial.print(minute);Serial.print(":");Serial.println(second);
  SunPowerAvg = SunPowerInt / 600;
  RECORD(); 
  }
  
}


void Flash_RTC ()
{
  
  top = top + 1;
  top60 = top60 + 1;
  top10 = top10 +1;
  
  SunPowerInt = SunPowerInt + SunPower;
  if (SunPower > SunPowerMax) {SunPowerMax = SunPower;} else {SunPowerMax = SunPowerMax;}
  if (SunPower < SunPowerMin) {SunPowerMin = SunPower;} else {SunPowerMin = SunPowerMin;}
      
}


byte bcdToDec(byte val) 
{ return ( (val/16*10) + (val%16) );}

void getDateDs1307(byte *second,byte *minute,byte *hour,byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year) //---
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  *second     = (bcdToDec(Wire.read() & 0x7f));
  *minute     = (bcdToDec(Wire.read()));
  *hour       = (bcdToDec(Wire.read() & 0x3f));  // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month      = bcdToDec(Wire.read());
  *year       = bcdToDec(Wire.read());
}


void RECORD()

{
    File dataFile = SD.open(File_record, FILE_WRITE); 
  
  Serial.print(hour);Serial.print(":");Serial.print(minute);Serial.print(":");Serial.print(second);Serial.print(" <> ");
  Serial.print(SunPowerAvg);Serial.print(" <> ");
  Serial.print(SunPowerMin);Serial.print(" <> ");
  Serial.print(SunPowerMax);Serial.print(" <> ");
  Serial.println(File_record); 
    
    if (dataFile) 
    {              
      dataFile.print(dayOfMonth);dataFile.print("/");dataFile.print(month);dataFile.print("/");dataFile.print(year);dataFile.print(" ; ");             
      dataFile.print(hour);dataFile.print(":");dataFile.print(minute);dataFile.print(":");dataFile.print(second);dataFile.print(" ; ");
      dataFile.print(SunPowerAvg,0) ;dataFile.print(" ; ");
      dataFile.print(SunPowerMin,0) ;dataFile.print(" ; ");
      dataFile.print(SunPowerMax,0) ;dataFile.print(" ; ");
      dataFile.println(File_record );dataFile.close(); 
    }

 
}

Credits

KFMAKR
0 projects • 18 followers
Contact

Comments

Please log in or sign up to comment.