Solar irradiance

Hello,

I'm trying to read solar irradiance with pt202c phototransistor and with normal sensor codes it is working on serial printing but I don't know honestly with code and I can't understand what should I do. I found someone did on youtube a solar meter and I used that in this link.

and his code

#include <LiquidCrystal.h>


#define BPW34pin        A0
#define samples         16


LiquidCrystal lcd(2, 3, 4, 5, 6, 7);


unsigned int sample[samples];

unsigned char s = 0;
unsigned int avg = 0;
unsigned long sum = 0;
float irValue = 0;


void setup()
{
  memset(sample, 0, samples);
  lcd.begin(16, 2);
}



void loop()
{
   sum -= sample[s];
   sample[s] = analogRead(BPW34pin);  
   sum += sample[s];
   s += 1;
   
   if(s >= samples) 
   {
      s = 0;      
      avg = (sum >> 4); 
      irValue = ((16.3366 * avg) - 30.69);
      irValue *= 0.0079;
      
      if(irValue < 0)
      {
        irValue = 0;
      }
      
      lcd.clear(); 
      lcd.setCursor(0, 0);
      lcd.print("Irradiance Meter");
      lcd.setCursor(0, 1);
      lcd.print("Ir W/m2: ");
   
      lcd.setCursor(9, 1);
      lcd.print(irValue);
      delay(600);
   }
}

I don't understand what is s or avg why he did this. If I use this code I'm getting max 130 - 80 W/m2
and I also I'm trying to make this meter from an article in this link:

they got 40w/m2 max in chile so I should get lower than this also they made correct the magnitude error equation to get close readings for irradiance with real solar irradiance meter.

I need guidance and help with this coding. thanks.

The code averages 16 samples. "s" counts them.

I would not recommend that code, as it contains undocumented "mystery constants".

Lots of good advice on measuring solar irradiance at this site.

jremington:
The code averages 16 samples. "s" counts them.

Strictly speaking, "s" is the current position in the "circular buffer" used to hold the previous 16 readings.

jremington:
I would not recommend that code, as it contains undocumented "mystery constants".

I agree, and not just for those reasons. The first 15 readings printed to the lcd will be too low because the the missing readings are assumed to be zero, which will drag down the average.

Also, this line is incorrect:

  memset(sample, 0, samples);

It only zeroes half the buffer because the array contains int values (2 bytes), so 32 bytes should be zeroed. In practice, the array will be zero on startup, so the line of code is not needed. However, the error indicates the coder may be inexperienced with C/C++.

jremington:
The code averages 16 samples. "s" counts them.

I would not recommend that code, as it contains undocumented "mystery constants".

Lots of good advice on measuring solar irradiance at this site.

I read almost everything about how they made etc. but they used expensive stuff still to read sensor. I read it before too and still feeling like dumb.

PaulRB:
Strictly speaking, "s" is the current position in the "circular buffer" used to hold the previous 16 readings.I agree, and not just for those reasons. The first 15 readings printed to the lcd will be too low because the the missing readings are assumed to be zero, which will drag down the average.

Also, this line is incorrect:

  memset(sample, 0, samples);

It only zeroes half the buffer because the array contains int values (2 bytes), so 32 bytes should be zeroed. In practice, the array will be zero on startup, so the line of code is not needed. However, the error indicates the coder may be inexperienced with C/C++.

I'm an environmental engineer and I really feel like dumb in this coding if I can't find a way to do it, I guess better not do it at all and not include in my thesis.

The Arduino is a learning tool, and is really easy to use, so this is your chance to learn about programming!

If you want to measure solar irradiance and have the numbers actually mean something, you really need to buy or make a pyranometer that measures radiation from the entire sky. High school students do this and have fun at the same time.

Arduino can be used to measure the pyranometer output quite accurately and cheaply. There is absolutely no need for expensive data loggers.