Electronics project notes/DIY home resource metering

From Helpful
Revision as of 16:24, 20 April 2024 by Helpful (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

⚠ This is for beginners and very much by a beginner / hobbyist

It's intended to get an intuitive overview for hobbyist needs. It may get you started, but to be able to do anything remotely clever, follow a proper course or read a good book.

Some basics and reference: Volts, amps, energy, power · batteries · resistors · transistors · fuses · diodes · capacitors · inductors and transformers · ground

Slightly less basic: amplifier notes · varistors · changing voltage · baluns · frequency generation · Transmission lines · skin effect

And some more applied stuff:

IO: Input and output pins · wired local IO · wired local-ish IO · ·  Various wireless · 802.11 (WiFi) · cell phone

Sensors: General sensor notes, voltage and current sensing · Knobs and dials · Pressure sensing · Temperature sensing · humidity sensing · Light sensing · Movement sensing · Capacitive sensing · Touch screen notes

Actuators: General actuator notes, circuit protection · Motors and servos · Solenoids

Noise stuff: Stray signals and noise · sound-related noise names · electronic non-coupled noise names · electronic coupled noise · ground loop · strategies to avoid coupled noise · Sampling, reproduction, and transmission distortions

Audio notes: See avnotes

Platform specific

Arduino and AVR notes · (Ethernet)
Microcontroller and computer platforms ··· ESP series notes · STM32 series notes

Less sorted: Ground · device voltage and impedance (+ audio-specific) · electricity and humans · power supply considerations · Common terms, useful basics, soldering · landline phones · pulse modulation · signal reflection · Project boxes · resource metering · SDR · PLL · vacuum tubes · Multimeter notes Unsorted stuff

Some stuff I've messed with: Avrusb500v2 · GPS · Hilo GPRS · JY-MCU · DMX · Thermal printer ·

See also Category:Electronics.

DIY home resource metering


Piggybacking on a digital meter

If you have a digital meter (depends on where you live, and whether you've been upgraded to one yet), that meter is potentially doing all the work for you (and be more accurate than current clamps), if it has:

  • a LED (visible or IR) that pulses for every so-many kW-hours (or VARh, Volt-Amperes Reactive hour).


  • an a optical serial port (IEC61107/DIN 66258, IEC 62056-21; see also below), which may potentially be more interesting, but also more work. (see #Notes on IEC 62056-21 for details)

If you have the impulse LED, you'll need to not miss pulses. Probably some simple dedicated hardware.

Our previous meter emitted 10000 pulses per kWh (one pulse = 0.1 Wh, and a 1kW load makes for approx 2.8 flashes per second, a 200Wh load for a flash every ~2.1 sec), each pulse being ~2ms long.
Both of those are pretty practical orders of magnitude to listen to and record, and not very hard to do with an Arduino/AVR.
It got replaced by a meter that does 500 pulses per kWh (Pulse = 2Wh, a 1kW load means 30 pulses/minute, so 1/sec is an averge of 2kW, one every 10 sec is 200W), each pulse being 40ms long.
This means less accuracy in time, which makes near-real-time graph generation a little less exciting, but also means it's harder to miss a pulse (in a microcontroller that isn't completely dedicated).

Current clamp

You can also use a current jaw/clamp.

These refer to any design of current transformers which are fairly simple simple coils set up to you a tiny current, proportional to the current on the wire you're snooping on.

However, clamping all directions in a wire will give you a zero reading, so this is only possible if the individual wires are visible at some point, such as one group or phase of your house, without others or the return cable, or a single wire from an extension cord to measure a single devices or a handful of them.

You're probably using an ADC, so want to see a voltage level proportional to the current from the clamp, perhaps best done with a simple opamp circuit, such as [1], though could be done with a resistor (possibly a calibration pot to be able to set its range).

Also, being a simple transformer, its output will be AC if its input is AC, which means you either want to sample fast enough to be able to get an RMS, or condition the signal before sampling - particularly if you are measuring more specific devices, like TRIAC style dimmers or motors.

You do still have to make some situation-based assumptions, about transformer accuracy and power factor, though a little calibration goes a long way.

There are multimeter variations that include clamps, which are great tools for electricians. They rarely allow easy logging, and good ones are not cheap.

...so DIYers may want to buy a separate clamp and interface it with something. You can expect to spend EUR 20 on a basic clamp, and a bunch more for the rest of the electronics (op amp, microcontroller dedicated to watching and counting, communication to something. There are other options.)

See projects like:

If you want something shiny and convenient, there are ready-made products, for on the order of 250 EUR (probably less now), which add convenient readout displays, wireless stuff, and such.

A few of these:

You may be able to leech values from some of these for your own graphs (e.g. simple enough in the case of Current Cost).


This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

For more localized power measurement you can use wall-plug power meters, which are now fairly cheap devices.

A number of these are hackable at some level or other, meaning you can automate data collection. For example, see this Kill-a-watt XBee hack (piggybacks on low-voltage part of the device after sampling; needs soldering), though there are simpler, cheaper, wired alternatives to using XBee.



Semi-sorted notes


You may like interfacing with phototransistors on an Arduino or so.

Many projects you'll find transmit the data via an XBee, some via ethernet interface. If you like hacking access points, you could perhaps abuse its serial interface.

Metering bus protocol notes

This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

Between various types of meter reading and other SCADA and telemetry, the protocols that may be involved (the lower half of this list is mostly stuff I came across while searching): (verify)

  • IEC 61107 (which was IEC 1107 before a renumbering)
    • Absorbed into IEC 62056 (its 62056-21 subpart seems mostly equivalent to IEC 61107(verify)), and the IEC considers 61107 to be superseded by 62056(-21). See also below.
    • but still common sort of as just this part, because it's simple(r)
  • IEC 62056 series of standards
    • absorbed DLMS and IEC 61107 (verify)
    • consists of a bunch of parts, more details below
  • ANSI C12.18
  • Power Line Carrier (PLC)
    • Shared local medium, collected by a local data concentrator and sent on to grid operators in whatever way it chooses to(verify)
    • modulation on a frequency in 3kHz..148.5kHz range (see EN 50065-1)
    • range is a few hundred meters, with option to use (meters as?) repeaters as controlled by the concentrator?(verify)
    • Physical layer details: See IEC 61334-5-1, http://en.wikipedia.org/wiki/IEC_61334
  • ZigBee Smart Energy (mostly an interconnection?)

DLMS (Device Language Message Specification), an application layer protocol mostly about communicating object entities, fairly generic. Merged into IEC 65056(verify)

xDLMS - extended form that knows about COSEM?(verify)

There is software that accesses via DLMS/COSEM, though may be somewhat specific to a meter.


See also:

There is various software that can read out DLMS, IEC 62056-21, including

  • MAP110, MAP120 software (from Landis+Gyr)

IEC 62056
This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

Consists of various parts. Some of the more relevant:

Lower-level parts:

  • IEC 62056-21: local data exchange (is the 3d edition of IEC 61107): COSEM over a optical port or current loop.
    • Has a few different modes that meters can choose to use/implement, see below
  • IEC 62056-46: Data link layer using HDLC protocol (See also [2]) - alternative to more ASCII-over-classical-serial exchange. (Used in 62056-21 mode E?)
  • IEC 62056-42: Physical layer services and procedures for connection-oriented asynchronous data exchange


  • IEC 62056-62: Interface classes. A model specific for metering that defines named classes, some inheritance, and queryable attributes. The COSEM model's objects are instantiations of these classes(verify). (Seems to mostly be background information that programmers might want to know)
  • IEC 62056-53: COSEM Application layer (where COSEM is the COmpanion Specification for Energy Metering, a application later protocol specific data model for energy metering)
  • IEC 62056-61: Object identification system (OBIS), for domain-specific enumation of things you commonly want to ask for (things in IEC 62056-62 and a few more(verify))

Also related:

  • IEC 62056-47: COSEM transport layers for IPv4 networks (not very common?(verify))
  • IEC 62051:1999, Electricity metering – Glossary of terms

Notes on IEC 62056-21

Physical media for local access is usually a half-duplex serial port affair, often either an optical port (infrared LED + infrared photodiode), or wired (often RS-485?).

There are fancy conformant reader heads for the infrared one, but they're damn expensive for what they are (LED, photosensor, magnet). With a few components and some creativity you can build your own much cheaper.

If you do: It looks like the IR LEDs are on a 38kHz carrier (which is NOT IrDA, IrDA is baseband). The simplest way to send and receive this is probably to buy components that already use that -- and note that TV remote LEDs and their receivers are a good place to start (these seem to usually be 36kHz or 38kHz(verify)).

See also:

Meters often choose to default to a particular mode, and may implement only one. When they do, mode C seems a favourite(verify). They may also prefer a specific speed. This is typically mentioned in the meters's documentation.

The modes:

  • A (initial mode, until otherwise negotiated)
    • ASCII based protocol
    • all parts at 300 baud, 7N1(verify)
    • readout, programming
  • B
    • ASCII based protocol
    • starts at 300 baud, has baud switching
    • readout, programming
  • C
    • ASCII based protocol
    • starts at 300 baud, has baud switching
    • readout, programming
    • adds optional security, manufacturer-specific functionality
    • allows partial block communication (...which is?)
  • D
    • ASCII based protocol
    • fixed at 2400 baud throughout
    • readout only (the only mode that isn't bidirectional, initiated by a button or such)
  • E

A baud switch, requested or not, will only happen when acknowledged/dictated by the meter. In mode B it seems to be a command, in mode C the readout hardware can ask for another rate(verify).

Standard baud rates are 300, 600, 1200, 2400, 4800, 9600, and 19200. (Further rates can be defined by specific meters, but will have to be mentioned by their documentation, and implemented by readout hardware)

All modes except D (possibly E depending on implementation?) allow you to switch to programming (after readout?). Programming mode is due to one of various security levels and their conditions - basic alterations may require a password, some things may require the meter being opened at the time (which is considered tampering, and registered as such in the meter). Don't do that. ...but you generally need not worry about changing something without meaning to, because even the meters without particularly good security aren't that bad...

Optical interface

The optical interface has an IR transmitter (LED) and receiver (photodiode) side by side (with some standard-specced distances, isolation from environment light, separation between LED and photodiode, etc.)

The commercial things that fit onto many meters many have a magnet for convenient temporary attachment. There seems to be no physical means (e.g. notches) of aligning the led/photodiode. The heads presumably mark how they should be positioned (typically wire down?)

  • half duplex communication
  • led off is SPACE, transmitting a 38kHz pulse sequence is MARK(verify)


Modes A, B, C, and D resemble each other, but vary in details like baud switching, exact commands, and sequence.

An ASCII line-base protocol, using CRLF line termination, largely readable characters, and using some control codes for specific functions, including:

  • 0x06 is ACK, acknowledge
  • 0x02 is STX, frame start
  • 0x03 is ETX, end of block
  • 0x01 is SOH, start of heading

References to BCC are a Block Check Character, a single character that acts as a checksum of the data block just sent. This seems to be ISO/IEC 1155:1978, also known as LRC (longitudinal redundancy check)(verify). This checksums bytes starting at the first STX or SOH (excluding it), up to the ETX character (including it). Calculation is apparently(verify):

  • value=0
  • for each byte in buffer:
    • value = value XOR byte (which is equivalent to adding and and-masking with 0xff)
  • value = ((value XOR 0xff) + 1) AND 0xff (...apparently.)

Mode C

Request for setup (at 300 baud) to a specific device ID, usually 1(verify)

  • /?1!

Returns device identification, which consists of

  • 3 characters: manufacturer string
  • 1 character: baud rate
  • rest of line: device ID?

Mode switch request (still at 300 baud)

  • ACK (that is, 0x06)
  • 0 (character, i.e. 0x30)
  • character indicating baud rate we wish for (choices listed somewhere below)
  • mode to enter - 0 for readout, 1 for programming mode, 2 for manufacturer specific mode


  • ACK 050 for readout at 9600 baud
  • ACK 000 for readout at 300 baud.

The meter pauses (how long?) to allow the baud rate switch.

In the case of data readout, meter sends data readout, structured like:

0x02 data ! 0x03 BCC

Data readout is a sequence of lines, mentioning OBIS (62056-61) identifiers. Meters choose which of the possible identifiers they use, and may (and often do) add some of their own.

Reducing power/utility usage

This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.