# How to connect Arduino Uno to an energy meter

How do I connect an energy meter, such as the L&T (Larsen & Toubro) Quasar Intelligent meter (datasheet,) which uses Modbus RTU protocol with RS485 communication to an Arduino Uno?

I am using MAX 485 to convert RS485 to TTL and I have written my program using the ModbusMaster library.

I always get a Time Out error or Slave Id error. Please help me out of this situation.

• Welcome to EE.SE. You need to improve your question if you want good help. What's the problem? Physical connection? If so you haven't provided Meter (sic) name and link to datasheet. If it's software well what's the problem? You should add a question mark somewhere to indicate an actual question. – Transistor Mar 20 '16 at 19:30
• I have edited the question and added summary please check if I missed out something. Thank You – user104215 Mar 20 '16 at 19:43
• (1) Links to meter datasheet (as requested already). (2) What's the problem? Physical or software? – Transistor Mar 20 '16 at 19:45
• There's no datasheet on that link. Find the datasheet and edit your post again with the link. – Transistor Mar 20 '16 at 20:31
• Please tell me what you want . I have hard copy of data sheet which is like 20+ pages . Tell me what you want . – user104215 Mar 21 '16 at 18:41

If the device you want to talk to presents its data via Modbus over RS-485, then on your end you have to implement RS-485 in hardware, and a Modbus master in firmware.

You will need a RS-485 transceiver chip between the UART signals of your micro and the RS-485 bus.

The tricky part is knowing when to set the bus transceiver to transmit mode instead of receive mode. Most UARTs that come with micros don't include this. If your does, just connect the data direction line to the transceiver direction line, possibly requiring inversion in between. If not, you will have to create the direction signal in firmware in your UART driver.

A simple way to do this in firmware is to have a periodic interrupt that runs several times per data byte. This will be useful for implementing the Modbus timing too. Whenever the app writes a byte to the UART driver, the direction line is set to sending before anything else is done. The periodic interrupt then sets the line to receiving if there are no bytes waiting in the software write FIFO, in the UART hardware, and the UART is finished clocking out the last character.

You will probably want to use this same periodic interrupt to time the gap between received bytes. Somehow you then communicate to the application whether the gap before each received byte was long enough to indicate the start of a new packet or not. The remaining Modbus logic can then be handled above the low level UART driver layer.

• Sorry sir I will have to study about what you answered because I don't have knowledge of communication. Now let me tell you what I did . I connected device with rs485 to MAX485 and then to arduino. I have done one code which will glow led if data is transmitted. I can't understand what I have to do with RE and DE pin of ic . Could we please discuss on that part – user104215 Mar 21 '16 at 18:37
• Please check my edited question. – user104215 Mar 22 '16 at 17:20
• OK yes that might be the problem. What I did is I used simple MODBUS library and hardware given in it. They have provided to enable transceiver through digital pins on Arduino. I was crosschecking my hardware and trying to analyse signals transmitted by it . I observed in Oscilloscope. I found that the Arduino is sending signal properly but at the meter end the rectangular signal is converted to triangular one. Can this be a problem . Please tell me how to rectify this. – user104215 May 6 '16 at 18:28