Solar radiation sensor SEM228A

Hello everyone,

I am working on a project where I am trying to read solar radiation data using a SEM228 total solar radiation sensor. I am using an Arduino Uno and a MAX485 module for RS485 communication. However, I am having trouble receiving data from the sensor. I have followed the datasheet instructions and tried multiple troubleshooting steps, but I still get "no response from the sensor" on the Serial Monitor. Here are the details:

Hardware :

  • Microcontroller: Arduino Uno
  • Sensor: SEM228 total solar radiation sensor
  • RS485 Module: MAX485
  • Power Supply: The solar radiation sensor is powered by 12v power supply and the MAX485 is powered directly from the 5V pin of the Arduino.

Code: Here is the code I am currently using:

#include <SoftwareSerial.h>

#define RE 8
#define DE 7

const byte pyranometer[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
byte values[8];
SoftwareSerial mod(2, 3);

void setup()
{
  Serial.begin(9600);
  mod.begin(4800);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);
  digitalWrite(RE, LOW);
  digitalWrite(DE, LOW);
  delay(1000);
}

unsigned int calculateCRC(byte *array, int length)
{
  unsigned int crc = 0xFFFF;
  for (int pos = 0; pos < length; pos++) {
    crc ^= (unsigned int)array[pos];
    for (int i = 8; i != 0; i--) {
      if ((crc & 0x0001) != 0) {
        crc >>= 1;
        crc ^= 0xA001;
      }
      else
        crc >>= 1;
    }
  }
  return crc;
}

void loop()
{
  // Transmit the request to the sensor
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  
  mod.write(pyranometer, sizeof(pyranometer));
  mod.flush();
  
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);
  delay(10); // Allow time for the sensor to respond

  unsigned long startTime = millis();
  byte index = 0;
  while (mod.available() < 7 && millis() - startTime < 1000) 
  {
    delay(1);
  }
  
  // Read sensor response
  if (mod.available() >= 7) {
    while (mod.available() && index < 8) 
    {
      values[index] = mod.read();
      Serial.print(values[index], HEX);
      Serial.print(" ");
      index++;
    }
    Serial.println();
    
    // Verification CRC
    unsigned int receivedCRC = (values[index - 1] << 8) | values[index - 2];
    unsigned int calculatedCRC = calculateCRC(values, index - 2);
    
    if (calculatedCRC == receivedCRC) {
      int Solar_Radiation = int(values[3] << 8 | values[4]);
      Serial.print("Solar Radiation: ");
      Serial.print(Solar_Radiation);
      Serial.println(" W/m^2");
    } else {
      Serial.println("Error CRC - invalid data");
    }
  } else {
    Serial.println("No response from the sensor");
  }
  
  delay(3000);
}

Problem: Even after these attempts, I always get "no response from the sensor" on the Serial Monitor.

I would appreciate any advice or suggestions on what might be wrong with my setup or code. If anyone has experience with this sensor or RS485 communication, your help would be greatly appreciated!

Thank you in advance!

Please explain what conditions cause this message to be printed? Be specific!

For that, we need to see a schematic diagram of the wiring and a close up, focused photo of the setup. A hand drawn wiring diagram is fine, with all pins and connections clearly labeled.

Please post links to the sensor data sheet, and to the product page for the RS485 interface.

The message "No response from the sensor" is printed when the sensor does not respond with the expected data within a specific timeframe. More specifically, this happens under the following conditions:

After sending the request to the sensor via RS485, the code waits for the sensor to respond by monitoring the mod.available() function. This function checks how many bytes have been received from the sensor.

The code uses a timeout of 1 second (1000 ms) to wait for the response. If fewer than 7 bytes have been received within that time, the loop exits, and the message "No response from the sensor" is printed.

The timeout ensures that the program does not get stuck waiting indefinitely if the sensor fails to respond or if there is an issue with the communication.

Perhaps a different message for this condition would help with the problem.

Here is the link for the sensor manual https://fr.scribd.com/document/713510753/SEM228A-manual and the MAX485 datasheet https://www.alldatasheet.com/view.jsp?Searchword=Max485

Very few people on this forum will sign up for an account just to read your manual. Best if you find a different way to supply the manual information.

Thanks for your suggestions and assistance. I identified the problem: the issue was a faulty MAX485 module. After replacing it with a new one, the sensor started communicating correctly, and I am now able to receive accurate solar radiation data.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.