Hello
I recently purchased the sensor as below. (I attach the link.)
Soil Moisture & Temperature & EC Sensor
User Manual
Attempted rs485 communication (with mode bus protocol) after viewing the user manual, but failed to get a response.
I sent an 8-byte Ask command in hexadecimal, but the sensor did not respond.
Ask: 01 04 00 00 00 03 B00B
Sensor Respond:01 04 06 08 90 0E 93 02 4E D2 57 (11 byte)
The success of the Check, use the following formula to calculate the temperature (negative to
complement representation) and conductivity of H at the end of the 16 hexadecimal data:
temperature=(08H256+90H)/100=2192/100=21.92 ℃
volumetric water content =(0EH256+93H)/100=3731/100=37.31%
conductivity =02H256+4EH=2256+78 =590 μs/cm
Based on the contents of the document above, I wrote the Arduino test code and sent the command to the sensor, but there was no response.
The sensor connections are as follows:
The connection followed the basic MCU-MAX485-RS485, and I think there is no problem.
Next, I attach the Arduino code that I tested.
#include <SoftwareSerial.h>
#include <Wire.h>
#define RE 8
#define DE 7
const byte code_num[]= {0x01, 0x04, 0x00, 0x00, 0x00, 0x03, 0xB0, 0x0B};
SoftwareSerial mod(2,3);
int temp;
byte values[11];
void setup() {
Serial.begin(9600);
mod.begin(9600);
delay(100);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
delay(500);
}
void loop() {
val1 = readsensor();
delay(250);
Serial.print("read: ");
Serial.println(val1);
delay(2000);
}
byte readsensor(){
digitalWrite(DE,HIGH);
digitalWrite(RE,HIGH);
delay(50);
if(mod.write(code_num,sizeof(code_num))==8){
digitalWrite(DE,LOW);
digitalWrite(RE,LOW);
for(byte i=0;i<11;i++){
values[i] = mod.read();
// Serial.print(values[i], HEX);
// Serial.println();
}
// Serial.println();
temp = ((int)values[3]*256)+(int)values[4];
Serial.println(temp);
}
return temp;
}
Are there any particular problems?
The sensor is still not responding to the data.
Please help me.