Monitor Your Energy Bill via Modbus, MKR WiFi 1010 and RS485

Connect a Modbus energy meter to an Arduino and monitor power consumption via Home Assistant.

Nov 19, 2018

96764 views

58 respects

Components and supplies

1

USB Power Supply

1

Arduino MKR WiFi 1010

1

Arduino MKR 485 Shield

1

USB-A to Micro-USB Cable

1

Twisted single pair shielded cable

Tools and machines

1

Small flathead screwdriver

1

Electrician Scissors

1

Mastech MS8217 Autorange Digital Multimeter

1

Medium size philips screwdriver

Apps and platforms

1

Arduino Web Editor

1

Home Assistant

1

MQTT

Project description

Code

Comments

Only logged in users can leave comments

Immagine
Immagine

Anonymous user

2 years ago

IEC 62056-21 / IEC 61107 - I am interested in Protocol and Reading Data from Electricity Meters. I reviewed your project. I want to read data directly from the 485 port of the electricity meter. How can I do that?

Immagine
Immagine

Anonymous user

2 years ago

http://vrtp.ru/index.php?act=Attach&type=post&id=479714 IEC 62056-21 - Protocol document ...

Immagine
Immagine

Anonymous user

2 years ago

Thank you very much to share this project. It has been very useful since I needed to do something similar. After implementing it, I see it works fine while the Arduino is connected to my laptop with the microusb-USB cable, but the MODBUS fails to read when I unplug it. I power the Arduino with an independent power supply. Is there any interference between the serial port to communicate with the laptop and the serial port used for the Modbus? Any hint is more than welcome.

Immagine
Immagine

Anonymous user

2 years ago

This page is generally very helpful, on the other hand, it caused me a few hours of debugging. Sadly, the Atmega 328 doesn't have a hardware serial port, so the example doesn't work there, but that's okay. The example modbus message is invalid: "01 03 04 00 16 00 02 25 C7" Correctly it would be: "01 03 00 16 00 02 25 CF" The "04" (3rd character) is not needed, because this is the 0x03 (Read Multiple Holding Registers) only needs 2+2 more bytes: 2 bytes for starting address and 2 bytes for number of registers requested (words). So in this case, correctly: 0x01 - slave address (of the finder F7) 0x03 - read multiple holding registers 0x00 0x16 - start from register 0x0016 0x00 0x02 - read 2 words 0x25 0xCF - the checksum (I hope I got it right) There is an online crc calculator at https://www.lammertbies.nl/comm/info/crc-calculation.html just beware that you need to swap the high/low parts.

Immagine
Immagine

Anonymous user

2 years ago

This is very useful and empowering - real time consumption view. This can be made into a good commercial product.

Immagine
Immagine

officine-innesto

2 years ago

Hi Adam. Thanks for your feedback. I really do think so. There are many commercial products aimed for power consumption smart monitoring, this is intended for retrofitting hardware. Unfortunately laws are really different around the world, depending on your country of origin you will or won't be allowed to put your hands in the power cabinet: **we are makers** lol :)

Immagine
Immagine

Anonymous user

2 years ago

How to use this code with Nodemcu (ESP8266 module) ?

Immagine
Immagine

Anonymous user

2 years ago

I think changing `#include <WiFiNINA.h>` to `#include <esp8266WiFi.h>` should work but im not shure

Immagine
Immagine

Anonymous user

2 years ago

Excellent write up! If you add 'Home-Assistant' to the 'Things used in this project' list under 'Software' then this project will get added to the Home-Assistant channel at https://www.hackster.io/home-assistant Cheers

Immagine
Immagine

officine-innesto

2 years ago

Hi Robin. Thanks for your feedback. I really do think we ended up forgetting to hit "save" on the Software Section. Following your advice,I've hadded **Arduino Web Editor**, **Home Assistant** and **MQTT**. Thanks Again.

Immagine
Immagine

Anonymous user

2 years ago

Nice project. Do you know if there is an off the shelf unit similar to the Finder Energy Meter for the US market?

Immagine
Immagine

Anonymous user

2 years ago

Hi @eea123, I don't really know where to address you. Where do you want it to connect to? Your Mobile phone, your Home Automation System? The [market is big and will get bigger](https://www.abiresearch.com/press/smart-electricity-meters-to-total-780-million-in-2/), many players (Finder as well, which hase good documentation and english instruction - I know the site is in Italian but you can google translate it). I advice you to google it and read reviews on Amazon. I don't have a special brand since I'd rather build myself following this guide. Ciao and thanks for commenting!

Immagine
Immagine

Anonymous user

2 years ago

There are quite a few commercial products in the US market, likely all are more expensive than doing it yourself of course: https://sense.com/ http://eyedro.com/ https://www.theenergydetective.com/

Immagine
Immagine

Anonymous user

2 years ago

I can live with an upcharge, just wanting to make sure I can find a single phase 220V main / recording breaker compatible with my residential box before ordering. Thanks for the additional input. I understand this is a DIY project :).

Immagine
Immagine

Anonymous user

2 years ago

Blacksmithtb, thanks for those commercial product links. I suppose a "clamp-on" device to the main panel feed line would be easier than tracking down the United States equivalent Finder Energy Meter CB. I did find a whole panel solution, https://lyntec.com/remote-control-breaker-panel/ but I was just really after the monitoring aspect not load shedding.

Immagine
Immagine

Anonymous user

2 years ago

Not to get too off track, but the Eyedro is a pretty low cost solution, http://eyedro.com/product/ehem1-lv/. Decent 200a clamp-ons are $40/ea, so at $129 it is pretty attractive for an off the shelf solution. That being said, my electrical company is in the process of upgrading their meters to smart meters. We should get one in the next few months that should be ZigBee compatible.

Immagine
Immagine

Anonymous user

2 years ago

This Project is very nice, but where can I find the code now ?

Immagine
Immagine

Anonymous user

2 years ago

Browser issue... sorry closed

Immagine
Immagine

Anonymous user

2 years ago

Off Topic Slightly I know. But.. I've been trying to get the example of RTU Temp sensor with MKR 485 shield for MKR1000 to work anyone ever got that or have wiring diagrams etc. Make it worth your while.....

Immagine
Immagine

Anonymous user

2 years ago

Are you still interested in doing this project? I work closely with arduino and modbus at a company called Machine Saver in Houston. I would like to know your requirements and perhaps I can whip something up. We've had some breaks in development due to Covid so now would be a good time to pick this up. Regards, Leo

Immagine
Immagine

Anonymous user

2 years ago

Hey, Thanks for such a useful project. I have some questions 1. Can we connect multiple rs485 supported meters (30) to a single Arduino using this technique? if yes please guide or refer to some Arduino based project 2. do you have the video of the project? 3. Can you show some pictures for the cloud part.

Immagine
Immagine

Anonymous user

2 years ago

hi. were exactly do i find the mqtt library? i want to have my mkrwifi1010 comunicate with my hassio settup but i dont know what library was used and if its the one showing as just mqtt in platformio(my IDE) theres NO documentation at all

Immagine
Immagine

Anonymous user

3 years ago

Thank you very much to share this project. It has been very useful since I needed to do something similar. After implementing it, I see it works fine while the Arduino is connected to my laptop with the microusb-USB cable, but the MODBUS fails to read when I unplug it. I power the Arduino with an independent power supply. Is there any interference between the serial port to communicate with the laptop and the serial port used for the Modbus? Any hint is more than welcome.

Immagine
Immagine

alirazasiddique

4 years ago

Hey, Thanks for such a useful project. I have some questions 1. Can we connect multiple rs485 supported meters (30) to a single Arduino using this technique? if yes please guide or refer to some Arduino based project 2. do you have the video of the project? 3. Can you show some pictures for the cloud part.

Immagine
Immagine

erilun06

5 years ago

hi. were exactly do i find the mqtt library? i want to have my mkrwifi1010 comunicate with my hassio settup but i dont know what library was used and if its the one showing as just mqtt in platformio(my IDE) theres NO documentation at all

Immagine
Immagine

Anonymous user

5 years ago

Off Topic Slightly I know. But.. I've been trying to get the example of RTU Temp sensor with MKR 485 shield for MKR1000 to work anyone ever got that or have wiring diagrams etc. Make it worth your while.....

Immagine
Immagine

Anonymous user

2 years ago

Are you still interested in doing this project? I work closely with arduino and modbus at a company called Machine Saver in Houston. I would like to know your requirements and perhaps I can whip something up. We've had some breaks in development due to Covid so now would be a good time to pick this up. Regards, Leo

Immagine
Immagine

Anonymous user

5 years ago

This page is generally very helpful, on the other hand, it caused me a few hours of debugging. Sadly, the Atmega 328 doesn't have a hardware serial port, so the example doesn't work there, but that's okay. The example modbus message is invalid: "01 03 04 00 16 00 02 25 C7" Correctly it would be: "01 03 00 16 00 02 25 CF" The "04" (3rd character) is not needed, because this is the 0x03 (Read Multiple Holding Registers) only needs 2+2 more bytes: 2 bytes for starting address and 2 bytes for number of registers requested (words). So in this case, correctly: 0x01 - slave address (of the finder F7) 0x03 - read multiple holding registers 0x00 0x16 - start from register 0x0016 0x00 0x02 - read 2 words 0x25 0xCF - the checksum (I hope I got it right) There is an online crc calculator at https://www.lammertbies.nl/comm/info/crc-calculation.html just beware that you need to swap the high/low parts.

Immagine
Immagine

Anonymous user

6 years ago

How to use this code with Nodemcu (ESP8266 module) ?

Immagine
Immagine

erilun06

2 years ago

I think changing `#include <WiFiNINA.h>` to `#include <esp8266WiFi.h>` should work but im not shure

Immagine
Immagine

Anonymous user

6 years ago

IEC 62056-21 / IEC 61107 - I am interested in Protocol and Reading Data from Electricity Meters. I reviewed your project. I want to read data directly from the 485 port of the electricity meter. How can I do that?

Immagine
Immagine

Anonymous user

2 years ago

http://vrtp.ru/index.php?act=Attach&type=post&id=479714 IEC 62056-21 - Protocol document ...

Immagine
Immagine

Anonymous user

6 years ago

This Project is very nice, but where can I find the code now ?

Immagine
Immagine

Anonymous user

2 years ago

Browser issue... sorry closed

Immagine
Immagine

Anonymous user

6 years ago

Awesome project! I´m making a mobile app for monitoring power analyzer data with Unity (Analyzer + UNO + Ethernet Shield + max485 shield) but I´m doing something wrong with the request. I´d like to know what´s HOLDING_REGISTERS in the code and how do you insert the CRC byte? Thanks!

Immagine
Immagine

Anonymous user

6 years ago

Nice project. Do you know if there is an off the shelf unit similar to the Finder Energy Meter for the US market?

Immagine
Immagine

Anonymous user

2 years ago

Hi @eea123, I don't really know where to address you. Where do you want it to connect to? Your Mobile phone, your Home Automation System? The [market is big and will get bigger](https://www.abiresearch.com/press/smart-electricity-meters-to-total-780-million-in-2/), many players (Finder as well, which hase good documentation and english instruction - I know the site is in Italian but you can google translate it). I advice you to google it and read reviews on Amazon. I don't have a special brand since I'd rather build myself following this guide. Ciao and thanks for commenting!

Immagine
Immagine

blacksmithtb

2 years ago

There are quite a few commercial products in the US market, likely all are more expensive than doing it yourself of course: https://sense.com/ http://eyedro.com/ https://www.theenergydetective.com/

Immagine
Immagine

Anonymous user

2 years ago

Blacksmithtb, thanks for those commercial product links. I suppose a "clamp-on" device to the main panel feed line would be easier than tracking down the United States equivalent Finder Energy Meter CB. I did find a whole panel solution, https://lyntec.com/remote-control-breaker-panel/ but I was just really after the monitoring aspect not load shedding.

Immagine
Immagine

Anonymous user

2 years ago

I can live with an upcharge, just wanting to make sure I can find a single phase 220V main / recording breaker compatible with my residential box before ordering. Thanks for the additional input. I understand this is a DIY project :).

Immagine
Immagine

Anonymous user

2 years ago

Not to get too off track, but the Eyedro is a pretty low cost solution, http://eyedro.com/product/ehem1-lv/. Decent 200a clamp-ons are $40/ea, so at $129 it is pretty attractive for an off the shelf solution. That being said, my electrical company is in the process of upgrading their meters to smart meters. We should get one in the next few months that should be ZigBee compatible.

Immagine
Immagine

Anonymous user

6 years ago

Excellent write up! If you add 'Home-Assistant' to the 'Things used in this project' list under 'Software' then this project will get added to the Home-Assistant channel at https://www.hackster.io/home-assistant Cheers

Immagine
Immagine

officine-innesto

2 years ago

Hi Robin. Thanks for your feedback. I really do think we ended up forgetting to hit "save" on the Software Section. Following your advice,I've hadded **Arduino Web Editor**, **Home Assistant** and **MQTT**. Thanks Again.

Immagine
Immagine

Anonymous user

6 years ago

This is very useful and empowering - real time consumption view. This can be made into a good commercial product.

Immagine
Immagine

officine-innesto

2 years ago

Hi Adam. Thanks for your feedback. I really do think so. There are many commercial products aimed for power consumption smart monitoring, this is intended for retrofitting hardware. Unfortunately laws are really different around the world, depending on your country of origin you will or won't be allowed to put your hands in the power cabinet: **we are makers** lol :)