Hello!
I am trying to connect JXCT RS485 Soil PH sensor to Arduino Due using RS485 to TTL Converter (Two Way Converter) Transceiver XY-485 and I am stuck I assume that I am sending the inquiry frame as the TX led is blinking but I am not receiving anything.
#define SENSOR_ADDRESS 0x01
#define BAUD_RATE 9600
#define RX_PIN 19 // RX1 on Arduino DUE
#define TX_PIN 18 // TX1 on Arduino DUE
byte sendData[] = {0x01, 0x03, 0x00, 0x06, 0x00, 0x01, 0x64, 0x0B};
byte receivedData[8]; // Buffer to store received data
void setup() {
// Start serial communication for debugging
Serial.begin(9600);
// Start Modbus communication
Serial1.begin(BAUD_RATE); // Serial1 uses RX1 and TX1 pins
}
void loop() {
// Send the inquiry frame
Serial1.write(sendData, sizeof(sendData));
delay(500); // Wait for the sensor to process and respond
// Read the response
int i = 0;
while (Serial1.available()) {
receivedData[i] = Serial1.read();
i++;
delay(10); // Give some time for the next byte to arrive
}
if (i > 4) { // Check if enough data is received
int pHData = receivedData[4];
float pHValue = pHData * 0.01;
Serial.print("pH Value: ");
Serial.println(pHValue, 2);
} else {
Serial.println("Failed to read from sensor!");
}
delay(1000); // Wait for 1 second before the next reading
}
The connections:
Common ground between the sensor and the RS485 wing in the module
Blue wire of the sensor connected to B- in RS485 wing in the module
Yellow wire of the sensor connected to A+ in RS485 wing in the module
VCC in TTL wing of the module connected to 5V of the DUE
TXD to RX1, RXD to TX1
GND of the module to GND of the DUE
JXCT Soil PH Sensor Datasheet.pdf (300.1 KB)
XY485.pdf (1.5 MB)