Water EC/TDS Sensor with Modbus communication

Protonest IoT
3 min readJun 21, 2024

--

In this guide, we will walk through the process of connecting and reading data from a Water EC/TDS sensor from CWT CO., LIMITED.

This transmitter features online calibration, automatic temperature compensation, over-current and overvoltage protection, and standard industrial signal outputs. We will use Modbus communication to interface with the transmitter and extract sensor readings.

Materials Needed

Specifications

The EC/TDS transmitter supports various output signals including 0–5V, 0–10V, 4–20mA, and RS485 (Modbus RTU). For this guide, we will focus on using the RS485 output.

Wiring the Transmitter

Arduino Code for Modbus Communication

#include <ModbusMaster.h>

#define RXD2 16
#define TXD2 17

#define MAX485_DE 32
#define MAX485_RE_NEG 33

ModbusMaster node;

void preTransmission() {
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}

void postTransmission() {
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}

void setup() {
Serial.begin(9600);

pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);

Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
node.begin(0, Serial2);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}

void loop() {

uint8_t result = node.readHoldingRegisters(0x00, 2); // Request 2 registers starting from address 04

if (result == node.ku8MBSuccess) {
uint16_t calibrationValues = node.getResponseBuffer(0); // First register: Calibration values
uint16_t sensorReadings = node.getResponseBuffer(1); // Second register: Sensor readings

Serial.print("Calibration Values: ");
Serial.println(calibrationValues);
Serial.print("Sensor Readings: ");
Serial.println(sensorReadings);
} else {
Serial.print("Error reading registers: ");
Serial.println(result, HEX);
}

delay(2000); // Delay before the next read
}

Identifying the Correct Slave ID

The default slave ID for the transmitter is 1, as specified in the datasheet.

If you encounter issues with communication, it is crucial to verify the slave ID. Here’s a method to identify the correct slave ID,

Note: Although the transmitter is rated for 12–24V, it was found that supplying 14V ensures proper functionality. Ensure your power supply can provide a stable 14V to avoid any issues.

Detailed Code Explanation

Modbus Registers

The datasheet can be accessed through the link.

The register at address 0x00 (40001 in decimal) holds the calibration solution value, and the register at 0x01 (40002 in decimal) holds the EC/TDS value.

We request two registers to get both calibration value and EC/TDS Values.

uint8_t result = node.readHoldingRegisters(0x00, 2);

Final Calculations can be done according to,

Conclusion

By following this guide, you should be able to successfully connect and read data from the Water EC/TDS transmitter using Modbus communication.

This setup allows for real-time monitoring of EC/TDS levels in various industrial applications.

Contact us for any consultations or projects related to any RS485 sensor.

Protonest for more details.

Protonest specializes in transforming IoT ideas into reality. We offer prototyping services from concept to completion. Our commitment ensures that your visionary IoT concepts become tangible, innovative, and advanced prototypes.

Our Website: https://www.protonest.co/

Email: udara@protonest.co

If you enjoyed this article and would like to show some support, consider buying me a coffee on Ko-Fi.

Your support not only helps me keep creating content like this but also fuels me! ☕️📚

Thank you for being an amazing reader!

Here’s my Ko-Fi link: https://ko-fi.com/udarakumarasena

Cheers!

--

--

Protonest IoT
Protonest IoT

Written by Protonest IoT

We make your IoT ideas a reality

No responses yet