Member-only story

Integrating an RS485 Sensor with ESP32

Protonest IoT
4 min readMay 3, 2024

--

In this guide, we will explore how to connect an RS485 sensor, the XY-MD02, to an ESP32 microcontroller using an MAX485 module. We’ll go through the necessary components, wiring setup, and the code required to get temperature readings from the sensor.

What You Need

Wiring

Please follow the following wiring diagram,

Code

Here is the complete code I used.


#include <ModbusMaster.h>

#define MAX485_DE 32
#define MAX485_RE_NEG 33

#define RXD2 16
#define TXD2 17

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…

--

--

Protonest IoT
Protonest IoT

Written by Protonest IoT

We make your IoT ideas a reality

No responses yet