XY-MD02 Temperature and Humidity Sensor

I had ordered months ago a XY-MD02 Temperature and Humidity Transmitter Detection Sensor Module Modbus SHT40 Temperature Sensor from some Chinese source (it is available from many on-line shops). Now I had finally some time to test it.

20240226_200104

Parameters:
Product name: temperature and humidity transmitter
DC power supply: DC 5V-30V
Output signal: RS485 signal
Temperature accuracy: ±0.5℃ (25℃)
Humidity accuracy: ±3%RH
Temperature range: 0%RH-80%RJ
Temperature resolution: 0.1℃
Humidity resolution: 0.1%RH
Equipment power consumption: ≤0.2W
Communication address: 1-247 can be set, default 1
Communication protocol: Modbus-RTU protocol and custom common protocol
Baud rate: configurable, default 9600, 8-bit data, 1-bit stop, no parity

This product integrates the MODBUS protocol and the common protocol Using RS485 hardware interface. The user can choose the communication protocol. The product adopts industrial grade chip, high-precision SHT40 temperature and humidity sensor.

Wiring:
xywiring

My plan was to first test it with Modbus protocol. I wired this sensor to PC using a cheap “no name” USB to RS-485 adapter. For powering the sensor I used 5V from USB port (wired to sensor with cut USB cable).

20240226_195043

Here is the overview of the supported Modbus communications protocol.

xymd02modbus

I think I need to read the temperature and humidity register. To use it I need some software to handle Modbus communications and help testing if it works.

CAS Modbus Scanner is a free proprietary application from Chipkin Automation Systems that I used as first tool to verify that basic Modbus communications works and devices could be found on but. It’s Discover functionality allowed to find that device is there, but for some reason the software did not seem to get successfully data from it.

casmodbus

So it seems that I needed some other tool to make communications work. PowerHud Mobbus Tester from https://www.modbustester.com/ could read the data successfully from the sensor.

powerhud

How to interpret data info from https://www.aliexpress.com/item/1005001475675808.html

xymd02commands

In addition to Modbus protocol, there is another protocol called common protocol. That “common protocol” is a simple ASCII protocol that can be used with any common serial port terminal program. I followed the instructions from XY-MD02 Temp Humidity Serial UART Communication article and video. Here is the most important takeout of special Putty settings in addition to serial port (9600 BPS 8N1) needed to get communications to work:

xy-md02-temperature-humidity-serial-uart-communication-310-min

I got this other protocol to work with Putty program. The READ command reads the temperature and humidity values.

xy_uart

The common protocol has said to have an automatic upload function (connecting RS485 through the serial port adjustment tool will automatically output temperature and humidity). That can be started using command AUTO.

Links to more material:

XY-MD02 Sensor Setting – Modbus RTU Network
https://accautomation.ca/xy-md02-sensor-setting-modbus-rtu-network/

XY-MD02 Temp Humidity Serial UART Communication
https://accautomation.ca/xy-md02-temp-humidity-serial-uart-communication/

https://www.instructables.com/XY-MD02-Temperature-and-Humidity-Sensor-Module-Mod/

Product pages with data:
https://www.aliexpress.com/item/1005001475675808.html

Videos:
https://www.youtube.com/watch?v=V0_IqkWIPG0
https://www.youtube.com/watch?v=e_1QHtkOf6k

Source code links:
https://github.com/TitusSetiawan/XYMD02-ESP32-modbus
https://github.com/cesgarma/modbus-XY-MD02

0 Comments

Be the first to post a comment.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

*