Guys here me out I use thee code that I found here in the forum
#include <SoftwareSerial.h>
#define RE 33
#define DE 32
const uint32_t TIMEOUT = 500UL;
const byte moist[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
const byte temp[] = {0x01, 0x03, 0x00, 0x01, 0x00, 0x01, 0xD5, 0xCA};
const byte EC[] = {0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x25, 0xCA};
const byte PH[] = {0x01, 0x03, 0x00, 0x03, 0x00, 0x01, 0x74, 0x0A};
const byte nitro[] = {0x01, 0x03, 0x00, 0x04, 0x00, 0x01, 0xc5, 0xcb};
const byte phos[] = {0x01, 0x03, 0x00, 0x05, 0x00, 0x01, 0x94, 0x0b};
const byte pota[] = {0x01, 0x03, 0x00, 0x06, 0x00, 0x01, 0x64, 0x0b};
byte values[11];
SoftwareSerial mod(16, 17); // Rx pin, Tx pin // Software serial for RS485 communication
void setup() {
Serial.begin(4800);
mod.begin(4800);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
delay(500);
}
void loop() {
float moist_val, temp_val, ph_val;
uint16_t ec_val, nitro_val, phos_val, pota_val;
Serial.println("Moisture: ");
moist_val = moisture();
//float Val1 = val1 * 0.1;
delay(1000);
Serial.print(moist_val);
Serial.println(" %\n");
Serial.println("Temperature: ");
temp_val = temperature();
//float Val2 = val2 * 0.1;
delay(1000);
Serial.print(temp_val);
Serial.println(" C\n");
Serial.println("Conductivity: ");
ec_val = conductivity();
delay(1000);
Serial.print(ec_val);
Serial.println(" us/cm\n");
Serial.println("Ph: ");
ph_val = ph();
//float Val4 = val4 * 0.1;
delay(1000);
Serial.print(ph_val);
Serial.println(" pH\n");
Serial.println("Nitrogen (N): ");
nitro_val = nitrogen();
Serial.print(nitro_val);
Serial.println(" mg/kg\n");
delay(1000);
Serial.println("Phosphorous (P): ");
phos_val = phosphorous();
Serial.print(phos_val);
Serial.println(" mg/kg\n");
delay(1000);
Serial.println("Potassium (K): ");
pota_val = potassium();
delay(1000);
Serial.print(pota_val);
Serial.println(" mg/kg\n");
delay(5000);
}
int16_t moisture() {
float MOIST3and4;
uint32_t startTime = 0;
uint8_t byteCount = 0;
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
mod.write(moist, sizeof(moist));
mod.flush();
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount < sizeof(values) ) {
values[byteCount++] = mod.read();
printHexByte(values[byteCount - 1]);
}
MOIST3and4 = (((values[3] * 256.0) + values[4])/10); // converting hexadecimal to decimal
}
Serial.println();
return MOIST3and4;
}
int16_t temperature() {
float TEMP3and4;
uint32_t startTime = 0;
uint8_t byteCount = 0;
// switch RS-485 to transmit mode
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
// write out the message
mod.write(temp, sizeof(temp));
// wait for the transmission to complete
mod.flush();
// switch RS-485 to receive mode
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount < sizeof(values) ) {
values[byteCount++] = mod.read();
printHexByte(values[byteCount - 1]);
}
TEMP3and4 = (((values[3] * 256.0) + values[4])/10); // converting hexadecimal to decimal
}
Serial.println();
return TEMP3and4;
}
int16_t conductivity() {
int16_t EC3and4;
uint32_t startTime = 0;
uint8_t byteCount = 0;
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
mod.write(EC, sizeof(EC));
mod.flush();
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount < sizeof(values) ) {
values[byteCount++] = mod.read();
printHexByte(values[byteCount - 1]);
}
EC3and4 = (((values[3] * 256.0) + values[4])); // converting hexadecimal to decimal
}
Serial.println();
return EC3and4;
}
int16_t ph() {
float PH3and4;
uint32_t startTime = 0;
uint8_t byteCount = 0;
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
mod.write(PH, sizeof(PH));
mod.flush();
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount < sizeof(values) ) {
values[byteCount++] = mod.read();
printHexByte(values[byteCount - 1]);
}
PH3and4 = (((values[3] * 256.0) + values[4])/10); // converting hexadecimal to decimal
}
Serial.println();
return PH3and4;
}
int16_t nitrogen() {
int16_t NITRO3and4;
uint32_t startTime = 0;
uint8_t byteCount = 0;
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
mod.write(nitro, sizeof(nitro));
mod.flush();
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount<sizeof(values) ) {
values[byteCount++] = mod.read();
printHexByte(values[byteCount-1]);
}
NITRO3and4 = (((values[3] * 256.0) + values[4])); // converting hexadecimal to decimal
}
Serial.println();
return NITRO3and4;
}
int16_t phosphorous() {
int16_t PHOS3and4;
uint32_t startTime = 0;
uint8_t byteCount = 0;
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
mod.write(phos, sizeof(phos));
mod.flush();
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount<sizeof(values) ) {
values[byteCount++] = mod.read();
printHexByte(values[byteCount-1]);
}
PHOS3and4 = (((values[3] * 256.0) + values[4])); // converting hexadecimal to decimal
}
Serial.println();
return PHOS3and4;
//return (int16_t)(values[4] << 8 | values[5]);
}
int16_t potassium() {
int16_t POTA3and4;
uint32_t startTime = 0;
uint8_t byteCount = 0;
// switch RS-485 to transmit mode
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
mod.write(pota, sizeof(pota));
mod.flush(); // wait for the transmission to complete
// switch RS-485 to receive mode
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount<sizeof(values) ) {
values[byteCount++] = mod.read();
printHexByte(values[byteCount-1]);
}
POTA3and4 = (((values[3] * 256.0) + values[4])); // converting hexadecimal to decimal
}
Serial.println();
return POTA3and4;
}
void printHexByte(byte b)
{
Serial.print((b >> 4) & 0xF, HEX);
Serial.print(b & 0xF, HEX);
Serial.print(' ');
}
this is the result
Phosphorous (P):
01 03 02 00 0C B8 41
12 mg/kg
Potassium (K):
01 03 02 00 04 B9 87
4 mg/kg
Moisture:
01 03 02 00 A9 78 3A
16.00 %
Temperature:
01 03 02 01 09 79 D2
26.00 C
Conductivity:
01 03 02 00 73 F9 A1
115 us/cm
Ph:
01 03 02 00 44 B8 77
6.00 pH
tell me it already work???