Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interfacing Energy Meter having MODBUS RTU protocol with Arduino Uno

#include <LiquidCrystal.h>

#include <ModbusMaster.h>


#define LEDPIN 13

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Create a software interface for meter (create a ModBusMaster node)

ModbusMaster node(METERSLAVEID);

void setup() {

// Initialising communication with meter


// Setting up led


// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

// Print a message to the LCD.

lcd.print("hello, world!");

//set data output enable pin to output mode


void loop() {

// Reading data from meter

// 1. Request data using readHoldingRegisters() (i think we need to enable the outputs before this)

// 2. Check whether data is available using node.ku8MBSuccess flag

// 3. If valid read data from buffer using node.getResponseBuffer()

uint16_t data[ 2]; //We are using array of two 16 bit because we are reading two registers of 16 bit from meter

uint8_t flag; //8 bit flag is required for error checking because we get 8 bit status

int final; //final result

//see comment 1

flag = node.readInputRegisters(30001, 2);

lcd.setCursor(0, 1);

// print the number of seconds since reset:



case 0x01:

lcd.print("Illegal Function");


case 0x02:

lcd.print("Illegal DataAddress");


case 0x03:

lcd.print("Illegal DataValue");


case 0x04:

lcd.print("Slave device Failure");


case 0x00:



case 0xE0:

lcd.print("Invalud Slave");


case 0xE1:

lcd.print("Invalid Function");


case 0xE2:

lcd.print("Time Out");


case 0xE3:

lcd.print("Invalid CRC");



if(flag == node.ku8MBSuccess){

//glow a led

digitalWrite(LEDPIN, HIGH);

//read data

data[0] = node.getResponseBuffer(0);

data[1] = node.getResponseBuffer(1);

final = data[0];

if(data[1] == 0xFF) //sign check


final = ( data[0]) + 1;

final = final * (-1);




//unglow a led

digitalWrite(LEDPIN, LOW);



Please help me to interface rishabh energy meter EM 1340 with Arduino Uno. I have tried using ModbusMaster Library and SimpleModbus Library for coding in arduino. I have build RS485 to TTL converter using MAX485 IC and circuit which is given in SimpleModbus Library . I can share the code with you . My problem is that i am always getting Timeout Error . I checked on DSO the query at the converter end is not what is accepted , I mean when arduino sends query the message in form of square wave but at converter end their is loading . Please tell me what to do?

I am ready to share all information which , you just ask anything and please help me. Thank YOU Smile

The interface definition for meter is available online. I am not allowed to post page link here sorry just google search Rishabh Interface Definition and click on page link havin EM13XX and EM23XX

Important Note..!

If you are not satisfied with above reply ,..Please


So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: modbus implementation flowchart pdf, avr modbus implementation, arm processor lpc2148 modbus address, macular edema detection thesis having matlab codes, adaptive blind noise suppression in some speech processing applications report pdf of rtu, modbus implementation in c, lex program to find that a string is having three consecutive a,

Forum Jump:

Users browsing this thread: 1 Guest(s)