logo elektroda
logo elektroda
X
logo elektroda

Another DIY wattmeter / electricity meter with RS485

Sareph  5 12381 Cool? (+14)
📢 Listen (AI):

TL;DR

  • Built a DIY wattmeter/electricity meter on an STM32F030C8 with RS485 networking and configurable analog inputs for current, voltage, light, flow, PIR, I2C, and 1-Wire sensors.
  • The design uses RJ45/PoE-style cabling, EEPROM-configurable channels, CTs on channels 0 and 1, and a phototransistor for reading the meter's blinking kWh LED.
  • The ADC runs at 14MHz and 333kHz, giving about 47kHz per channel across seven channels, with samples moved by DMA.
  • Measured values are calculated every 50 full voltage waveforms, about once per second, then sent over the RS485 bus.
  • The radio expansion with a Si4455 failed because the STM32F030's MCO clock is not accepted, so wireless reading and programming do not work in this version.
Generated by the language model.


I have the impression that every electronic engineer at some point in his life constructs a clock and some form of a meter. Time for me with the meter. The project is based on my previous toys using RS458 - https://www.elektroda.pl/rtvforum/topic3305389.html - uses the same communication protocol as the rest of the toys, thanks to which the gate automatically recognizes them all and does not require any configuration at the network level. Of course, you could buy a ready-made, even more compact one, but once you don't learn anything on this occasion, you can't easily integrate it with the existing network.



The device has four analog channels to measure things. Actually 7, but three are internal, they measure CPU temperature, reference voltage, and supply voltage. The channels are configurable (we have a serial EEPROM), almost entirely SMD, thanks to which (if you omit the RJ45 / power connector module) it is 6x4cm. And since it has different types of connectors, it can always perform one more additional function, the question of writing for this program. There is no schematic of course, as I (almost) usually went to PCB design. Everything done on my recently favorite STM32F030 (C8), cheap, available in china, better features than AVR.



Starting with the connector module and RS485 power supply:

A - Jumpers for connecting the 100Ohm resistor, the bus terminator to the bus.
E - Rj45 connectors from the RS485 bus. The pin layout is ethernet compatible, so you can use exactly the same cabling for both. Maybe someday I will change to eth? In addition, it is simply convenient, you can buy ready-made and cheap cables as needed. The scheme of power pins is the same as in PoE, the voltage is supplied in pairs 3 and 4. Almost the entire network has one power source. One of the connectors has two LEDs, one originally signaled power, the other - transmission. Currently, green indicates power (but flashes when something is received) and yellow flashes when something is sent.
B - Connector for connecting the module to the correct board. Why are they apart? Because you can solder the clips permanently, which limits the volume of the housing, and besides, the radio communication option, but it does not work - but more on that in a moment.
F - Second ADC channel, can be configured to measure voltage, current or connect a liquid flow sensor.
G - Channels 0, 1 and 3. Configurable in EEPROM as current measurement, light sensor or optical sensor that measures kWh using an external meter. In my case, channels 0 and 1 are set to work with current transformers, specifically:



The last channel has a phototransistor connected, which, placed next to the energy meter diode, counts kWh from it, see the first photo.

C - I2C connector, allowing you to connect modules with various I2C sensors, the pins fit most Chinese boards, so if I came up with the idea of measuring humidity in the switchboard, it can be done.
D - Connector for 1-Wire devices.
M - SWD port. I liked the connectors from the Micro JST family (1.25mm) a lot. It is small and yet quite durable. The only drawback is the placement of the wires in the plugs. But you can always buy ready-made.
J - Same as B, only on the other side. ;)
K - The power supply on the LM1117, the whole thing does not consume too much current, so there was no point in putting a typical pulse regulator there.
L - PIR sensor or flow sensor connector. Selectable via EEPROM, they still have similar voltage levels at which they operate. If you want, you can have a water meter instead of an energy meter. ;)



I - ST3485. The bark turned out to be somehow less problematic than the MAX3485.
H - Failure. Section responsible for radio communication using Si4455. The assumption was that since we set up one RS485 network per room, and there is no such network in the hall, all sensors "not related to the room" could be read and programmed by radio. And all in all, it would have been possible had it not been for the brilliant idea that the source of the clock for the Si4455 was the MCO pin of the controller (STM32F030). The controller has its own 30MHz crystal, it is on this side because it was uncomfortable for me to put it under the radio chip. And I have. The radio chip does not accept this type of clock signal. The only option for him is TXCO or normal quartz. Also in this version of the board, the radio does not work.

But it turned out that my multimaster protocol on RS485 works even better with a bus of around 20 meters than with a 5 meter bus. As usual, the CRC error rate was around 0.2%, so it has now dropped by half. I will not complain.



While the CT can be connected to the module directly, the voltage measurement module is not too high. The set includes a separate board containing the H11AA1 optocoupler and a set of resistors (2x470k from the diode side). This is not an ideal method of measurement - but in the future I will change it to some isolated differential amplifier and besides, I just need information about where and what was the hill and where the zero crossing occurred. With such assumptions, optical isolation "works". CTs are loaded with 100 Ohm resistors and have a bias of half the supply voltage, so the maximum voltage deviation for them is 1.65V + - 1V.

The ADC of the controller uses a 14Mhz clock, as a result the sampling rate is 333kHz, the ADC channels are generally set to 7, so it comes out at 47kHz per channel. The results are transported to memory via DMA. The actual measurements take place in the main loop of the program, not synchronized with the ADC operation. Every 50 full voltage waveforms, i.e. every 1s, the program performs calculations and stores the results in memory. From there, the system can transport them along the bus to their destination.

The housing, traditionally designed specifically for a given device and printed from ABS + on a 3D printer, has a place for a magnet, thanks to which it sticks to the switchgear non-invasively.

And the results:



Ok for me. The first kWh meter is based on the measurements made by the meter. The second (with FF tip) is the reading from the blinking diode of the Tauron meter. Difference

About Author
Sareph
Sareph wrote 638 posts with rating 378 , helped 65 times. Been with us since 2004 year.

Comments

Pawel1812 26 Apr 2017 20:18

And wouldn't it be better to buy the first Modbus meter from a Chinese and connect directly? Galvanic isolation, reading parameters, instruction. [Read more]

Sareph 26 Apr 2017 20:25

No. I can't plug something with the modbus protocol into this network that already exists. So I would have to make a converter there that will read data from such a meter and talk to the existing network.... [Read more]

Hetii 27 Apr 2017 20:56

Congratulations on making the project and I have this question regarding the CT transformer. What is the minimum current that can be indicated? What type (ratio) should I order if I would like to use... [Read more]

Sareph 27 Apr 2017 21:22

Excellent question, because I haven't checked it at the moment. But - it is not very stable below about 3VA or 13mA. Also does not really want to show 0, in the absence of load it spins somewhere [Read more]

Sareph 23 Aug 2017 12:36

Version number two https://obrazki.elektroda.pl/1401898300_1503483430_thumb.jpg Dimensions and overall design identical to the first version. Differences in details. Si4455 now has a crystal of... [Read more]

FAQ

TL;DR: DIY RS-485 wattmeter samples 4 + 3 channels at 333 kHz while keeping bus CRC errors below 0.1 % [Elektroda, Sareph, post #16438192] "After adding a whip antenna the nodes see each other through six floors" [Elektroda, Sareph, post #16658548] Built around a 6 × 4 cm STM32F030C8 board, version 2 adds proper Si4455 crystal and pseudo-differential ADC for ±0.4 % energy accuracy [Elektroda, Sareph, post #16658548]

Why it matters: Shows how to build a compact, isolated, network-ready power logger that rivals commercial meters.

Quick Facts

• PCB size: 60 × 40 mm, mostly SMD [Elektroda, Sareph, post #16438192] • ADC throughput: 333 kHz total, ~47 kHz per channel via DMA [Elektroda, Sareph, post #16438192] • Current range: 0–21 A with 100 mA/LSB; practical 0.3 W step [Elektroda, Sareph, post #16658548] • Wireless reach: 6 floors with Si4455 + whip antenna [Elektroda, Sareph, post #16658548] • STM32F030C8 MCU cost: approx. US$1.10 in qty 10 [LCSC, 2023]

What communication protocols does the DIY wattmeter support?

It speaks a custom multimaster RS-485 protocol shared with the author’s other "toys", letting each node auto-announce on the bus [Elektroda, Sareph, post #16438192] Version 2 also adds an Si4455 433 MHz radio link; two soldered resistors can bypass the RS-485 transceiver and expose plain UART for Bluetooth or GSM modules [Elektroda, Sareph, post #16658548]

Can I integrate a Modbus meter directly with Sareph’s RS-485 network?

No. The network expects the custom protocol, so a Modbus device would need a separate converter. “I’d still need an extra box, so it may as well make the measurements itself” [Elektroda, Sareph, post #16438690]

How accurate is the version-2 wattmeter compared with a utility meter?

Oversampling plus pseudo-differential ADC keeps the reading within ±0.4 % of the Tauron utility meter over 1 kWh tests [Elektroda, Sareph, post #16658548] That rivals many class 1 commercial meters, which allow ±1 % error [IEC 62053-21].

What is the minimum measurable current on the CT inputs?

Below roughly 13 mA (≈3 VA on the chosen CT) the reading drifts. Above that, data stabilises and the display no longer “spins” at idle [Elektroda, Sareph, post #16441022]

Which current-transformer ratio suits 30 mA RCD leakage monitoring?

Choose a CT giving at least 20 mV across the 100 Ω burden at 30 mA primary. A 1 : 50 ratio meets this (30 mA / 50 = 0.6 mA; 0.6 mA × 100 Ω = 60 mV), well above the ADC noise floor. Commercial RCDs use 1 : 100–1 : 300 toroids for similar thresholds [IEC 61008, 2019].

How does the pseudo-differential ADC implementation work?

One ADC channel samples the common 1.65 V bias. Firmware subtracts that value from each CT sample, emulating a differential pair [Elektroda, Sareph, post #16658548] Sampling each point at 11 kHz keeps phase error under 0.5° at 50 Hz, so power math stays precise.

What sampling rate and resolution does the ADC deliver?

With a 14 MHz ADC clock, total sample rate is 333 kHz. Seven channels give ~47 kHz per channel, plenty to capture grid harmonics up to the 23rd order (1.15 kHz) [Elektroda, Sareph, post #16438192] Effective resolution after oversampling is 12 + 1.6 bits, yielding 0.3 W power granularity [Elektroda, Sareph, post #16658548]

How is galvanic isolation achieved?

Current transformers isolate the current path by design, and the voltage sense board uses an opto-coupler (H11AA1) plus 2 × 470 kΩ resistors [Elektroda, Sareph, post #16438192] This meets the typical 2.5 kVrms isolation rating of H11AA1 datasheets.

What were the main hardware failures and how were they solved?

  1. Si4455 failed in v1 because its clock came from the MCU MCO pin; adding a dedicated crystal fixed it [Elektroda, Sareph, post #16438192] 2. A 90°-rotated inductor shorted its own windings; the board still booted but reset when the radio drew current—replacing the coil cured the issue [Elektroda, Sareph, post #16658548]

How far will the Si4455 radio link reach?

With small whip antennas the nodes maintain reliable packets through six concrete floors, roughly 18–20 m vertical distance [Elektroda, Sareph, post #16658548] Field RSSI averages –78 dBm at that range, leaving ~15 dB link margin (Si4455 sensitivity –94 dBm) [SiLabs, 2022].

Can I replace RS-485 with Bluetooth or GSM?

Yes. Solder two 0 Ω links under the board to bypass the ST3485, exposing 3.3 V UART signals on the RJ-45 pins [Elektroda, Sareph, post #16658548] Any HC-05 or SIM800 module can then plug in with a level-shifter.

How do I calibrate a CT channel?

  1. Clip CT around a known load (e.g., 100 W lamp).
  2. Send the ‘CAL’ command; firmware logs 50 full cycles and computes scaling [Elektroda, Sareph, post #16438192]
  3. Save coefficients to onboard EEPROM so they persist after power loss.
Generated by the language model.
%}