Same-day dispatch before 2 PM · Free delivery over ₹999 · GST invoices Get the appPrices incl. GST
Geekobot
Snap & SendNEWGeeko AIWhere's myOrder
Log in
Products
  • Projects
    • Component guidesHow parts work, with code you can run
    • Learning pathsFrom your first LED to your first robot
    • Workshops & eventsOnline sessions for makers and classes
    • ElectrolarkFree guided builds, simulator and certificates
    • Students & teachersStudent discount and classroom help
    • CommunityShare builds and ask other makers
    • CalculatorsOhm's law, LED resistor, 555 and 100+ more
    • Circuit builderWire parts and run the circuit, powered by Electrolark
    • Geeko AIAsk what to buy or how to wire it
    • Snap & SendPhotograph a part or list, we find it
    • Part finderAnswer a few questions, get the right part
    • Compatibility checkWill these two parts work together?
    • Compare partsSpecs side by side
    • Business & bulk ordersGST invoices, credit and volume prices
    • Request a quotationSend your list, get a quote
    • Classroom kitsPer-student kits and lab bundles
    • Gift cardsFor students, teams and events
  • Atal Tinkering Lab
BOM to cart
Geekobot

Components, kits and know-how for makers, students, engineers, labs and businesses across India.

Ask Geeko AIOrders, parts and projects, any timeEmail supportReply within 1 working dayGet the Geekobot appAdd it to your home screen, free

Follow us

Shop

  • Boards & SBCs
  • Sensors & Modules
  • IoT & Wireless
  • Drone & FPV
  • 3D Printing
  • Filaments & Resins
  • Motors & Drivers
  • Power & Batteries
  • Semiconductors
  • Passive
  • Displays & LEDs
  • Switches & Relays
  • Wires & Cables
  • Prototyping
  • Tools & Test
  • Robotics
  • STEM Kits
  • Atal Tinkering Lab
  • Mechanical Parts
  • Audio

Orders

  • Track your order
  • Help & support
  • Shipping and delivery
  • Refunds and cancellation
  • Contact us

Learn

  • Projects
  • Geeko AI project assistant
  • Learning paths
  • Guides
  • Calculators
  • Electrolark: free guided builds

Part tools

  • Part finder
  • Compare parts
  • Will it work with my board?

Institutions

  • Classroom kits
  • Atal Tinkering Lab
  • Students & teachers
  • Workshops & Events

Business

  • Business & education
  • Request a quotation
  • BOM bulk upload
  • Quick order by SKU

Company

  • About Geekobot
  • Community
  • Gift cards
  • Terms & conditions
  • Privacy policy
  • Product directory
  • Sitemap

© 2026 Geekobot, a trade name of OLatus Systems Private Limited. All rights reserved.

20, 1st Floor, Neeladri Complex, 10th Cross, Sampige Rd, 2nd Main, Malleshwaram, Bengaluru, Karnataka 560003 · GSTIN 29AACCO0462F1ZM

+91 91810 15607 · connect@geekobot.in · Monday to Saturday, 10 AM to 2 PM IST

UPI · CARDS · NETBANKING · GST INVOICES

ShopProjectsGeeko AIGuides
Compare 0 parts →
Log in

Shop by category

Shop all components
  • Boards & SBCs1,910 products
    • Alternative Single Board Computers
    • Arduino Ecosystem
    • FPGA & Logic Boards
    • Microcontroller & Wireless Boards
    View all
  • Sensors & Modules4,701 products
    • Biomedical & Heart Rate
    • Current, Voltage & Power
    • Force, Weight & Pressure
    • Gas, Weather & Environmental
    View all
  • IoT & Wireless2,314 products
    • RF Modules
    • RFID & NFC
    • Antennas & RF Accessories
    • Cameras & Smart Vision
    View all
  • Drone & FPV3,558 products
    • Flight Control & Navigation
    • FPV Video & Optics
    • Frames & Structural Parts
    • Motors & Propulsion
    View all
  • 3D Printing2,204 products
    • 3D Printers
    • 3D Scanners & Digitizers
    • Laser Engravers & Cutters
    • Material Management & Upgrades
    View all
  • Filaments & Resins1,472 products
    • Filaments
    • Photopolymer Resins
    View all
  • Motors & Drivers463 products
    • BLDC Motor Drivers
    • DC & Geared Motors
    • DC Motor Drivers
    • Linear Actuators & Solenoids
    View all
  • Power & Batteries557 products
    • Battery Holders & Connectors
    • Breadboard Power
    • Chargers & BMS
    • DC-DC Converters
    View all
  • Semiconductors295 products
    • Diodes & Rectifiers
    • Interface & RF Encoder ICs
    • Logic ICs (74xx)
    • Logic ICs (CD4000)
    View all
  • Passive67 products
    • Capacitors
    • Circuit Protection
    • Crystals & Oscillators
    • Inductors
    View all
  • Displays & LEDs572 products
    • 7-Segment & Dot Matrix
    • Addressable LEDs
    • Character LCDs
    • Graphic LCDs
    View all
  • Switches & Relays184 products
    • Keypads & Touch
    • Push Buttons & Tactile
    • Relay Modules
    • Relays
    View all
  • Wires & Cables233 products
    • Board-to-Wire Connectors
    • Crimp & Splice
    • Headers & Dupont
    • Heat Shrink & Sleeving
    View all
  • Prototyping101 products
    • Breadboards
    • Interface Modules
    • PCBs & Perfboards
    View all
  • Tools & Test717 products
    • Bench Power Supplies
    • Hand Tools
    • Measuring Tools
    • Meters & Testers
    View all
  • Robotics180 products
    • Humanoid & Legged Robots
    • Robot Chassis & Platforms
    • Robotic Arms & Grippers
    • Wheels & Casters
    View all
  • STEM Kits268 products
    • Arduino Learning Kits
    • Coding & IoT Kits
    • Early Coding (Ages 3-8)
    • Invention Kits
    View all
  • Atal Tinkering Lab196 products
    • Package 1: Electronics, Robotics, IoT and Sensors
    • Package 2: Rapid Prototyping Tools
    • Package 3: Mechanical, Electrical and Measurement Tools
    • Package 4: Power Supply, Accessories and Safety Equipment
    View all
  • Mechanical Parts212 products
    • Bearings
    • Brackets & Mounts
    • Couplers
    • Fasteners & Standoffs
    View all
  • Audio109 products
    • Amplifier Modules
    • Buzzers & Sirens
    • Speakers
    View all
  1. Home
  2. ›Guides
  3. ›IoT & Wireless
  4. ›Modbus RTU With Arduino and ESP32

How-to · Advanced · 3 min read

Modbus RTU With Arduino and ESP32

RS485 Wiring, Addresses and Code

By Geekobot Learning Team · Updated 29 Oct 2026

On this page
Short answerHow Modbus RTU worksWiring to an ESP32Reading a register with the ModbusMaster libraryTroubleshootingTry itCommon mistakesFAQsParts and next steps
Short answer

Modbus RTU is a simple master-slave protocol over RS485. An Arduino or ESP32 acts as the master and reads registers from industrial sensors by address. You need a TTL to RS485 module, a twisted pair for A and B, a common ground and a 120 Ω terminator at each end. Match the sensor's baud rate, parity and slave address.

Key specs at a glance

Physical layer
RS485 half-duplex, two-wire A and B with a ground reference
Typical serial setting
9600 baud, 8 data bits, no parity, 1 stop (8N1), but check the sensor
Addresses
1 to 247 for slaves
Common functions
03 read holding registers, 04 read input registers, 06 write a register
Cable length
Up to about 1200 m at low baud
Termination
120 Ω across A and B at each end of the bus
01

How Modbus RTU works

One master (your microcontroller) sends a request to a slave address. The slave replies with data from numbered registers. Each frame ends with a CRC check. Only one device speaks at a time because RS485 is half-duplex. Industrial soil, temperature, dust, weather and energy sensors commonly use Modbus; the datasheet lists the register numbers and scaling.

02

Wiring to an ESP32

Use a TTL to RS485 module (MAX485 or similar) or an auto-direction board.

Module pinConnect to
RO (receiver output)ESP32 RX2 (GPIO16)
DI (driver input)ESP32 TX2 (GPIO17)
DE and RE tied togetherESP32 GPIO4 (direction)
VCC3.3 V or 5 V as the module requires
A / BSensor A / B, twisted pair
GNDSensor GND
Module pinConnect to
RO (receiver output)
ESP32 RX2 (GPIO16)
DI (driver input)
ESP32 TX2 (GPIO17)
DE and RE tied together
ESP32 GPIO4 (direction)
VCC
3.3 V or 5 V as the module requires
A / B
Sensor A / B, twisted pair
GND
Sensor GND
03

Reading a register with the ModbusMaster library

This ESP32 sketch reads two holding registers from slave 1 at 9600 baud. Use your sensor's register map for the address and scaling.

ESP32 Modbus RTU master (ModbusMaster library) · Arduino C++Verify & upload in Electrolark
#include <ModbusMaster.h>
const int DE_RE = 4;
ModbusMaster node;

void preTx()  { digitalWrite(DE_RE, HIGH); }
void postTx() { digitalWrite(DE_RE, LOW); }

void setup() {
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, 16, 17);
  pinMode(DE_RE, OUTPUT); digitalWrite(DE_RE, LOW);
  node.begin(1, Serial2);                    // slave address 1
  node.preTransmission(preTx);
  node.postTransmission(postTx);
}

void loop() {
  uint8_t r = node.readHoldingRegisters(0x0000, 2);   // start register, count
  if (r == node.ku8MBSuccess) {
    Serial.print(node.getResponseBuffer(0));
    Serial.print("  ");
    Serial.println(node.getResponseBuffer(1));
  } else {
    Serial.print("Modbus error "); Serial.println(r, HEX);
  }
  delay(1000);
}
04

Troubleshooting

Timeout

wrong address, baud rate or parity. Check the sensor label and manual.

Garbage data

A and B swapped, missing common ground or no termination on a long cable.

Works on the bench, fails in the field

add a 120 Ω resistor at each end and keep the cable away from power lines.

Two devices answer

each slave on the bus needs a different address.

Use a USB to RS485 adapter and a PC tool

to check the sensor before blaming your code.

05

Try it: Uart baud rate error calculator

Change the values and the diagram and results update as you type.

06

Common mistakes to avoid

  • !Leaving DE and RE unconnected so the module never transmits.
  • !Using the wrong parity or baud rate.
  • !Skipping termination on a long bus.
  • !Giving two slaves the same address.
  • !Assuming register numbers start at 1 when the library starts at 0.
07

Frequently asked questions

What is the difference between RS485 and Modbus?

RS485 is the electrical standard. Modbus is the message protocol that runs over it.

Can I use RS232 instead?

Modbus RTU also runs over RS232 for one device on a short cable. RS485 is better for several devices and long runs.

Which Arduino library should I use?

ModbusMaster for the classic master, or ArduinoModbus on boards that support it.

What does 8N1 mean?

8 data bits, no parity, 1 stop bit.

Do I need the 120 ohm resistors?

For short cables at low baud it often works without, but a long bus or high baud needs termination at both ends.

Parts for this guide

  • RAKwireless RAK5802 RS485 Module w/ TP8485E Chip
    ₹749View
  • WIN-CN-1M-1TCP Modbus RS485 to Modbus TCP Converter
    ₹6,555View
  • Renke RS-WS-N01-8-EX Flat Rail Type Modbus Temperature and Humidity Sensor, -40°C ~ +60°C, 0%RH ~ 95%RH, RS485
    ₹1,549View
  • WIN-IO-4PT100/1000M 4-Channel PT100/PT1000 RTD to Modbus RS485 Module – DIN Rail Mount
    ₹6,293View
Shop RS485, Modbus & CAN Communication Modules

Calculators

Uart baud rate error calculatorSerial transfer time calculator

Terms in this guide

ModbusA simple industrial request-and-reply protocol in which a master polls numbered registers on slave devices, usually over RS-485 (Modbus RTU) or Ethernet (Modbus TCP).Half-duplexA link where devices take turns sending on the same wires, as on RS485. A direction pin switches the driver between transmit and receive.Baud rateThe speed of a serial link in bits per second. Both ends must use the same value; 9600 and 115200 are the usual defaults.UARTUniversal asynchronous receiver-transmitter: two-wire serial (TX and RX) used by GPS, Bluetooth modules and debug output.IP ratingIngress Protection rating (IEC 60529), such as IP65: the first digit rates protection against dust and solids, the second against water.

Projects that use it

Put this into practice: 7 step-by-step builds in our project library use parts from this guide.

Intermediate · 2 hours4G SMS door alarm with an ESP32 and an LTE modemView projectIntermediate · 3 hoursRead RS485 Modbus industrial sensors with an ESP32View projectIntermediate · 2 hoursFind hot spots and heat leaks with an MLX90640 thermal cameraView project
Browse all 7 projects

Keep learning

Component guideIntermediateRS-485 and RS-232 ModulesRS-485 and RS-232 carry UART serial data over longer cables than plain TTL.3 min read · IoT & WirelessConcept explainerBeginnerUART and Serial CommunicationA UART sends data one bit at a time over one wire with no shared clock, so both ends must agree on the speed, called the baud rate (9600 and 115200 are common).4 min read · Electronics FundamentalsComponent guideBeginnerESP32 GuideThe ESP32 is a low-cost 3.3 V microcontroller from Espressif with built-in Wi-Fi and Bluetooth, used for IoT devices, smart-home controllers and web dashboards.5 min read · Boards & MicrocontrollersComponent guideIntermediateUSB to TTL Serial AdaptersA USB to TTL adapter turns a computer USB port into a 3.3 V or 5 V serial port, so you can program boards without USB (Pro Mini, ESP-01, ESP32-CAM) or read a debug console.4 min read · Boards & MicrocontrollersHow-toIntermediate3.3 V vs 5 V LogicYou need level shifting when a 5 V device sends signals to a 3.3 V board such as an ESP32 or Raspberry Pi Pico, because 5 V on their pins can damage them.4 min read · Prototyping & Wiring

Sources

  • Modbus Organization: Modbus application protocol and serial line specifications
  • ModbusMaster library documentation

Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.

On this page
Short answerHow Modbus RTU worksWiring to an ESP32Reading a register with the ModbusMaster libraryTroubleshootingTry itCommon mistakesFAQsParts and next steps
Need a hand?Ask Geeko AI which part fits your project, or talk to the Geekobot team.Ask Geeko AIHelp & support

Parts for this guide4 items · ₹15,146

RAKwireless RAK5802 RS485 Module w/ TP8485E Chip · WIN-CN-1M-1TCP Modbus RS485 to Modbus TCP Converter · Renke RS-WS-N01-8-EX Flat Rail Type Modbus Temperature and Humidity Sensor, -40°C ~ +60°C, 0%RH ~ 95%RH, RS485 · WIN-IO-4PT100/1000M 4-Channel PT100/PT1000 RTD to Modbus RS485 Module – DIN Rail Mount

Run itChange the inputs and watch the output
Serial monitor115200 baud
253  610

A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.

Ask the Community

Ask a question