Assistance needed for a project involving an Arduino and pyranometer

Hello dear Arduino Community,

I am a PhD student working on a solar engineering project that involves measuring solar radiation using a pyranometer. I have come across a PYR20 Pyranometer Sensor that has three types each with different output interfaces: RS485 Modbus, analogue current 4-20mA and analogue voltage 0-2V. I am wondering which output interface would be the easiest choice for my project so I can buy this one.

I m thinking of using the 0-2V output interface and reading the sensor output through an analogue pin using the code below. However, I am not sure if this is the best way to do it or if there are any drawbacks or limitations to this approach. I would appreciate any advice or feedback from anyone who has experience with this sensor or similar ones.

// Define the reference voltage
#define VREF 5.0

// Define the conversion factor from voltage to irradiance
#define K 1000.0


// the setup routine runs once when you press reset:
void setup() {
  
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int pyr_value = analogRead(A0);

  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float pyr_voltage = pyr_value * (VREF / 1023.0);

  // Convert pyranometer voltage to irradiance in W/m2 using conversion factor
  float pyr_irradiance = (pyr_voltage * K);

// Print the irradiance value to the serial monitor
Serial.print("Solar irradiance: ");
Serial.print(pyr_irradiance);
Serial.println(" W/m2");

// Wait for a second
delay(1000);
}


Also, I am not sure if this code give me a result. Could you please share your insights and suggestions on this matter?

Thank you for your time and help.

Technical details

|Model|PYR20 Pyranometer Series|
|Measurement Range|Up To 2000 w/m^2|
|Range|400-1100nm|
|Accuracy|5%|
|Resolution:|1 w/m^2|
|Power Supply|3.9 to 30V DC|
|Output Signal|Analogue voltage 0-2V|

The sensor has three wire RED for positive , black for Ground, Blue for measuring signal.

I m using Arduino Mega 2560 The picture below is only for illustration.


Screenshot 2023-11-05 110734

with the voltage or current, your precision will depend on how you acquire this analog value. for voltage, the typical Arduino like a UNO, the ADC is not the best in the world (10 bits, influenced by the stability of your power supply unless you use the 1.1V internal reference - but that's too low for your 2V) etc

measuring such current would require possibly amplification, which is another hardware need

the RS485 Modbus is likely giving you the raw data as a numeric value and so you'll have whatever the sensor actually read, without further noise

In summary, voltage is the low hanging fruit because you don't need extra equipment, but the precision might suffer

RS485 Modbus will be the most precise and require an adapter to get the RS485 communication into a Serial port.

Current is probably is third as requires both an extra piece of hardware and will possibly incur loss of precision (unless you get quality amplification / conversion)

given you have a 5% Accuracy from the sensor already, may be you don't want to add further noise and so RS485 Modbus would then be the right choice?

1 Like

Hello kamranrauf87

Welcome to the worldbest Arduino forum ever.

Take a search engine of your choice and ask the WWW for 'PYR20 Pyranometer +arduino' to collect some data to be sorted out to get the needed information.

Have a nice day and enjoy coding in C++.

I would recommend the 0-2V model.

Use a voltage divider to bring down the maximum 2V to 1V and set the Uno Mega to use it's internal 1.1V as the reference.

If you need more precision, I would suggest an ADS1015 or ADS1115 external ADC module.

1 Like

Thank you for your response, sir. I am working with an Arduino Mega 2560 board. The image I shared is only for illustration. So, to obtain accurate measurements, I need to use the RS485 Modbus protocol.

I appreciate your reply, sir. An Arduino Mega 2560 board is what I'm using. I just used the picture as an example.

Apologies, I typed Uno in error. The Mega is the same in this respect.

1 Like

I'm new to Arduino and I wanted to try a 0-2 volt output interface. It seemed simpler than RS485 Modbus, which requires a more complex code. But as you inform me that analog voltage output is not very precise. So if i need more accuracy Modbus is best chose . Thank you for your help.

If you use a MEGA it's worth thinking about buying the voltage 0-2V one, as you basically don't need extra hardware as the MEGA has a special internal reference at 2.56V (see INTERNAL2V56)

The sampling of your voltage will give you 800 values (0 - 2V mapped to 0 - 2.56V sampled with 10 bits sampling over the interval) so each step is roughly 2.5mV. That means for your PYR20 Pyranometer each step will represent 2.5W /m2

if that's granular enough for you then may be this is the easier option

If you use the 1.1volt reference, then that resolution could be 1W/ m2.
That is if you ignore irradiation over ~1100w/m2.

When long wires are involved, then I would consider the 0-20mA version over the voltage version.
Leo..

for than you need to divide by 2 the incoming signal - which can add noise (resistors are not super precise, are somewhat influenced by temperature if you take the simple voltage divider approach...)

No, the analogue input can still take 0-2volt.
If the sensor would output more than ~1.1volt (extremely rare on earth),
then the A/D would just hit 1023.
Leo..

ah good point

So, the Arduino Mega works fine with a 0–2 analog voltage output interface. The only thing is that it can't handle more than 1100 W/m2 of solar power. This is not a big issue for my location, where the maximum solar irradiation recorded was 950 w/m2.

This should do it for a Mega (untested).
Leo..

// 0-2volt sensor
const byte sensorPin = A0;
float irradiation;
float correctionFactor = 1.0123; // calibrate

void setup() {
  Serial.begin(9600);
  analogReference(INTERNAL1V1); // Mega only
}

void loop() {
  irradiation = analogRead(sensorPin) * correctionFactor;
  Serial.print("Irradiation: ");
  Serial.print(irradiation, 0); // no decimal places
  Serial.println(" W/m²");
  delay(1000); // dirty delay
}
1 Like

May I know? How did you calculate the correction factor? I'm not sure if I understand it correctly. if it is possible. Can you explain it to me? Thanks.

I didn't. You must calibrate the final setup in real sunlight, because 1.1volt Aref could be anything between 1.0 and 1.2volt.

If... the sensor outputs 1volt at 1000w/m2, and if... Aref of the board you're using happens to be 1.075volt, then the A/D will output 1 / 1.075 * 1024 = 952, which you have to multiply with 1000 / 952 = 1.0504 to display 1000W/m2 in the serial monitor.
Leo..

Thank you very much, sir. You have been very helpful. From the comments, I realize the voltage output interface causes more headaches, appears to be less accurate, and has a limited range of 1100 w/m2. So, S485 Modbus is the best option, but it needs a MAX485 to change the RS485 communication to a serial port with some complex code.
thanks again

Not that complex

I would suggest to study Serial Input Basics to handle this and if you share the payload format and specifications we can help out

1 Like

If you go for a 0-2volt or 4-20mA sensor, and want better results, then you could add an external A/D, like the ADS1115. That one has fewer limitations than the built-in A/D of an Arduino. With an ADS1115 breakout board you can have that 0-2000W/m2 range, and display with 0.1W resolution.

Not sure, but the one with the modbus/serial interface could have it's own A/D integrated.
Better find out what resolution it is first.

Also tell us the distance between sensor and Arduino. Not every type of interface likes long distances.
Leo..