2

I'm try to read some value from a soil NPK sensor using RS485 Modbus e Arduino uno.

I menage to sent the request msg and I got the response but now i don't know how to read the response in order to get the information I need.

the following code sent the request to get moisture value to the sensor:

#include <SoftwareSerial.h>
#define RE 8
#define DE 7
const byte msg[] = {0x01,0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
byte values[11];
SoftwareSerial mod(2, 3);
void setup() {
 
 Serial.begin(4800);
 
 mod.begin(4800);
 pinMode(RE, OUTPUT);
 pinMode(DE, OUTPUT);
 
 delay(500);
}
void loop() {
 test();
}
byte test(){
 digitalWrite(DE,HIGH);
 digitalWrite(RE,HIGH);
 delay(10);
 Serial.flush();
 if(mod.write(msg,sizeof(msg))==8){
 digitalWrite(DE,LOW);
 digitalWrite(RE,LOW);
 for(byte i=0;i<7;i++){
 values[i] = mod.read();
 Serial.print(values[i],HEX);
 
 
 }
 
 Serial.println();
 Serial.flush();
 delay(4000);
 
 }
}

My response is following bits:

114BA4134
1D5112A671
341D2119B
A61341D51
12A671341
E811BBAB13
41DB114BA4
1341DB11
4BA41341DB
114BA4134
1E311CA691
341C911EB
A11341E31
1CA691341
EC11FA6A13
41E4117BA8

looking at the datasheet below there should be a data area in the message response from the sensor.

how to convert this bit info to my humidty value.

pic

my be this example from the datasheet can help

pic 2

asked Apr 13, 2023 at 3:53
1
  • 1
    114BA4134 ... you have to print spaces between the bytes ... looks like leading zeros are not printed ... don't bother trying to decode the mess you have right now ... also, add code to print the leading zero ... if (values[i] < 16) Serial.print(0); Commented Apr 13, 2023 at 4:40

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.