Smart Energy Sensor: DIY Electricity Consumption Monitor

A project detailing the construction and implementation of a wireless sensor to monitor household electricity usage by detecting LED flashes from the meter.

Introduction

In an era of rising electricity prices, methods to reduce consumption offer tangible benefits for both personal finances and environmental protection. Modern home automation systems assist users by collecting and visualizing household energy usage. To enable this, a device for measuring electricity consumption is necessary. This project presents a sensor that effectively serves this purpose.

Measuring Electricity Consumption

There are several ways to measure electricity consumption. The simplest might seem to be installing a SMART electricity meter that can send data directly to a server. However, electricity meters are legally owned by the utility provider, and any tampering can lead to severe consequences. A more practical approach is to install a secondary meter behind the main one, equipped with an RS232 or RS485 interface, or an SO+ / SO- pulse output for connecting a pulse-counting device. This is feasible if sufficient space is available in the fuse box, but three-phase meters are costly. Alternatively, one could build a custom meter using current transformer modules, but ready-made solutions are expensive, and DIY construction requires expertise.

A compromise solution utilizes a feature common to most modern electricity meters: an LED indicator that signals correct operation. The flashing frequency of this LED corresponds to the current electricity consumption. This project leverages this feature to read electricity usage without interfering with the meter or the electrical installation.

[Diagram Description: A line graph showing electricity consumption (Wh) over a 24-hour period, with timestamps from 10:00 to 10:00.]

Project Overview

The project consists of two modules: a transmitter and a receiver.

Transmitter Module

The transmitter module counts the flashes of the electricity meter's LED over a one-hour period and transmits this count to the receiver module.

Receiver Module

The receiver module processes the received data and sends it to a server, such as Domoticz, or another system as required by the user.

Key Project Goals:

  • Counting LED flashes from a distance of up to 30cm from the meter (non-invasive).
  • Measuring the battery level of the power supply.
  • Ensuring a transmitter battery life of at least 1 year.
  • Minimizing device dimensions while maintaining reasonable radio range.
  • Allowing multiple transmitters to be associated with a single receiver.
  • Compatibility with the Domoticz system.
  • Ability to send data to other servers, e.g., Thingspeak.
  • Easy user configuration (e.g., setting pulses per kWh, Wi-Fi access).
  • Low construction cost with readily available components.

[Advertisement Description: Offer for AVT AVT-5690 kit, detailing features like non-invasive energy reading, 65535 impulses/h capability, low standby current (4.5 µA), 5-6 year battery life, and Domoticz compatibility.]

Transmitter Module Details

The transmitter's operation is based on the STM32L031F4P6 low-power microcontroller. It utilizes the STOP MODE, where the processor core is halted, and only the LSE oscillator and RTC are active, reducing current consumption to below 1 µA. RAM content is preserved, eliminating the need for re-initialization upon wake-up. The Low Power Timer (LPTIM) is used for counting external pulses. The LPTIM is a 16-bit timer that can operate without an internal clock source and can count external pulses. Pulses are fed into the LPTIM external Input1. A slight delay occurs after LPTIM activation before it correctly processes pulses; the first five pulses may be lost, which is generally not critical for this application.

The Programmable Voltage Detector (PVD) prevents uncontrolled processor operation at low supply voltages, with a trigger threshold set at 1.9V. If the battery voltage drops below this level, the device stops operating, indicating the need for battery replacement. This low battery status is communicated to the receiver during data transmission.

To detect light pulses from the meter's LED, a detection and shaping circuit is employed, comprising a phototransistor, an operational amplifier, and a comparator. A narrow-band phototransistor sensitive to the red LED's wavelength (approx. 610-650 nm), specifically the Vishay TEPT4400, is used. Its sensitivity in the relevant spectrum is at least 90% of its maximum (at 570 nm).

For minimal power consumption, a dual operational amplifier (MCP6142) is used, drawing only 600 nA per amplifier in standby. The first stage amplifies the phototransistor's pulses and allows gain adjustment via potentiometer R4. The second stage acts as a comparator with a switching threshold around 320 mV, determined by resistors R6 and R7, featuring slight hysteresis. With R4 set to its middle position, the circuit correctly detects and counts light pulses from up to 20 cm away. The comparator output feeds the LPTIM's counting input (PA0-CK_IN). The processor also measures the battery voltage upon each wake-up. A CRC16 checksum is calculated based on the pulse count and battery voltage. This data is then formatted into a data frame and sent to the RFM119 radio module.

The transmitter module in standby mode consumes 4.35 µA. The number of light pulses per kWh from the meter (ranging from 1000 to 10000 imp/kWh) affects operation time. During a light pulse, the circuit draws approximately 28 µA at a distance of 5 cm from the LED.

Radio communication uses HOPE-RF modules: RFM119 as the transmitter and RFM219 as the receiver, chosen for their simple control, good technical parameters, and low cost.

[Diagram Description: Electrical schematic of the transmitter module, showing connections between the STM32L031F4P6 microcontroller, RFM119W radio module, MCP6142 operational amplifier, TEPT4400 phototransistor, and power components (CR2477 battery, crystal oscillator).]

Transmitter Component List:

  • Resistors: R1, R2, R9: 100 kΩ SMD0805; R3, R5: 10 kΩ SMD0805; R4: 220 kΩ miniature potentiometer; R6: 1.5 MΩ SMD0805; R7: 180 kΩ SMD0805; R8: 1 MΩ SMD0805
  • Capacitors: C1: 1 µF SMD0805; C2: 100 nF SMD0805; C3, C4: 4.3 pF SMD0805
  • Semiconductors: T1: TEPT4400; IC1: MCP6142 SMD; IC3: STM32F031F4P6; RF: RFM119W
  • Other: X1: 32.768 kHz watch crystal; JP1, JP3: goldpin; BAT: CR2477 coin cell holder + battery; Enclosure: Z94

[Diagram Description: Top view of the transmitter module's Printed Circuit Board (PCB).]

[Diagram Description: Bottom view of the transmitter module's PCB.]

[Photo Description: A multimeter measuring current consumption of the transmitter module in standby and during transmission.]

The transmitter PCB measures 59x37 mm and fits into the Z94 enclosure. This compact size allows easy placement opposite the meter's LED. The phototransistor (T1) is mounted approximately 0.5 cm below the enclosure's top edge. A 2mm hole is drilled in the enclosure directly above the phototransistor for light entry. This setup also provides a filter against ambient light. A 17cm wire serves as a 1/4λ antenna for the 434 MHz band. Potentiometer R4 is set to the middle position. The transmitter requires programming using a programmer like ST-LINK, connecting to pins SWDIO, SWCLK, and RESET on connector JP1.

Receiver Module Details

The receiver module's schematic comprises four main blocks: a power supply, the STM32F030F4P6 microcontroller, a Wi-Fi communication module (ESP8266 Wroom-02 or ESP-07), and a 433 MHz radio receiver (RFM219).

The receiver consumes less than 0.4W. A standard LM1117 3.3V regulator powered by a micro USB connector serves as the power supply. Filter capacitors (C1-C6) and a PWR LED indicate power presence. Resistors R1-R4 configure the ESP modules for proper operation. The ESP-07s version offers a u.fl connector for an external antenna, providing extended range with home Wi-Fi networks.

The STM32F030 microcontroller in the receiver is clocked by an internal HSI 8 MHz oscillator. The program initializes peripherals and processes data received from the RFM219, forwarding it to the ESP8266 for transmission to the server. Communication with the RFM219 uses a half-duplex SPI interface, necessitating the F030 as an intermediary since the ESP8266 does not support this mode directly.

The receiver's operational algorithm begins with configuring the STM32's clocks and peripherals, and the RFM219 receiver. The main loop waits for data from the RFM219, received via two interrupts: INT_FIFO (signaling data availability in the FIFO buffer, allowing RSSI reading) and INT_PKT (indicating data ready for retrieval). The program verifies data integrity using checksums. If checksums mismatch, the ERROR LED lights up, indicating a weak or disturbed signal, suggesting reducing the distance between modules. If checksums match, the STM32 sends the data packet (including RSSI, pulse count, and transmitter battery voltage) via UART to the ESP8266.

The ESP8266 module calculates the power consumption based on the received pulse count and the configured pulses-per-kWh value, then sends it to the Domoticz server. This configuration is stored in the ESP8266's memory and is the only user setup required during initialisation. To switch from configuration mode to normal operation, the CONFIG jumper is removed, the WORK jumper is applied, and the RST_ESP button is pressed.

The ESP8266 firmware, written in Arduino, is straightforward. Data formatting for Domoticz is shown in Listing 2.

[Diagram Description: Electrical schematic of the receiver module, detailing connections for the ESP8266 Wi-Fi module, STM32F030F4P6 microcontroller, LM1117 voltage regulator, RFM219SW radio receiver, and associated components.]

Receiver Component List:

  • Resistors: R1, R3, R4, R7, R8: 10 kΩ SMD0805; R2: 4.7 kΩ SMD0805; R5, R6, R9: 1 kΩ SMD0805
  • Capacitors: C1, C4, C6: 100 µF/6.3V SMD; C2, C3, C5, C7: 100 nF SMD0805
  • Semiconductors: PWR, Wi-Fi_CONN, ERROR: SMD0805 LEDs; D1: SK14; IC1, IC2: Wroom02 or ESP07; IC3: STM32F030F4P6; IC4: LM1117 3.3V SMD; RF1: RFM219SW
  • Other: USB: Micro USB connector; RST_ESP: microswitch; Goldpin: 1x20 + jumper; Enclosure: Z123

[Diagram Description: Top view of the receiver module's PCB.]

[Diagram Description: Bottom view of the receiver module's PCB.]

[Diagram Description: Flowchart illustrating the receiver module's operation, including peripheral configuration, RFM219 data reception (INT_FIFO, INT_PKT), CRC check, and data forwarding to the ESP8266.]

[Photo Description: Example of the transmitter module mounted near an electricity meter.]

The ESP8266 module calculates the power consumption based on the received pulse count and the configured pulses-per-kWh value, then sends it to the Domoticz server. This configuration is stored in the ESP8266's memory and is the only user setup required during initialisation. To switch from configuration mode to normal operation, the CONFIG jumper is removed, the WORK jumper is applied, and the RST_ESP button is pressed.

Assembly and Setup

Transmitter Assembly: Start by soldering the microcontroller, followed by other components. Solder the battery holder last due to its size. Mount the phototransistor (T1) approximately 0.5 cm below the enclosure's top edge. Drill a 2mm hole in the enclosure directly above the phototransistor for light entry. Use a 17cm wire as a 1/4λ antenna for the 434 MHz band. Set potentiometer R4 to the middle position. The transmitter requires programming using a programmer like ST-LINK, connecting to pins SWDIO, SWCLK, and RESET on connector JP1.

Receiver Assembly: Begin with the power supply. After successful setup, solder the remaining components, starting with the smallest SMD parts. Attach a 17cm wire as an antenna. Program the STM32 microcontroller and the ESP8266. The STM32 can be programmed using an ST-LINK programmer or a USB/UART adapter (connecting to GRT pins for RX/TX and using the BOOT_STM32 jumper). The ESP8266 can be programmed via the PROG_UART interface. To enter programming mode, place a jumper on the BOOT_ESP connector and briefly press the RST_ESP button.

ESP8266 Configuration: After programming the ESP module, configure Wi-Fi connection parameters. Three short flashes of the Wi-Fi_CONN LED indicate missing data. To enter configuration mode, place a jumper on the CONFIG connector and press RST_ESP. The ESP8266 will then enter AP mode named "Smart Energy Sensor" and host an HTML configuration page at 192.168.4.1. The user needs to input the Wi-Fi network name (SSID), password, Domoticz server IP address, the meter's pulse constant (pulses/kWh), and the sensor ID (1-255).

[Diagram Description: Screenshot of the Domoticz configuration form for the Smart Energy Sensor, with fields for Wi-Fi SSID, password, Domoticz server IP, meter pulse constant, and sensor ID.]

The sensor ID is found in Domoticz under Configuration > Hardware. Note this ID for the receiver configuration. After saving the data, move the jumper from CONFIG to WORK and reset the ESP module. The module will attempt to connect to the Wi-Fi network; the Wi-Fi_CONN LED will blink during this process. Once connected, the LED will turn off. If it continues blinking, the entered data is incorrect and must be re-entered.

The GRT connector (gnd/rx/tx) can be used for diagnostics via a terminal program (115200 8N1) to monitor connection status and data sent to Domoticz.

Integrating with Domoticz

To add the sensor to Domoticz:

  1. In Domoticz, navigate to Configuration > Hardware and add a new hardware device.
  2. [Diagram Description: Screenshot of the Domoticz interface showing how to add a new hardware device (virtual sensor).]
  3. Name it (e.g., ESP8266_GATE) and set the Type to "Dummy". Click "Add".
  4. Click "Create Virtual Sensors". Select "Counter Incremental" and name it "Energia elektryczna" (Electricity Energy). Click "OK".
  5. [Diagram Description: Screenshot showing the assigned ID for the newly created virtual sensor in Domoticz.] The system will assign an ID to the sensor. Note this ID for the receiver configuration.
  6. The Domoticz log updates hourly.
  7. [Diagram Description: Screenshot of the Domoticz 'User' tab displaying sensor data, including energy consumption over time.] The data provides insights for analyzing potential electricity savings.
  8. [Diagram Description: Graphs showing electricity consumption over the last day, week, month, and year.]

Nucleo-F091RC Development Board

The article also mentions the Nucleo-F091RC development board from STMicroelectronics, a starter kit for STM32 microcontrollers. It features an STM32F091RCT6 microcontroller with 256KB Flash and 32KB SRAM, an embedded ST-LINK/V2-1 debugger/programmer, and Arduino-compatible connectors. It's presented as an accessible platform for learning STM32 microcontrollers and prototyping electronic devices.

[Diagram Description: Image and description of the Nucleo-F091RC development board, highlighting its features and connectivity.]

Summary

The presented module has been operating continuously for over a year without issues, contributing to an approximate 20% reduction in electricity consumption. Data can also be sent to other servers like Thingspeak by appropriately programming the ESP8266 module.

The data received from the STM32F030 is a string with separators, e.g., "89%1D2980V5670#", indicating RSSI (89%), sensor ID (1), transmitter battery voltage (2890 mV), and pulse count (5670). This data can be monitored via a terminal connected to the GRT connector.

References

PDF preview unavailable. Download the PDF instead.

AVT5690 Adobe PDF Library 15.0

Related Documents

Preview Modułowy odbiornik nasłuchowy na pasma 80 m i 40 m „Dosia” (6) – Moduł VFO
Technical article detailing the design, assembly, and tuning of the VFO (Voltage-Controlled Oscillator) module for the 'Dosia' 80m and 40m band receiver project. Includes circuit schematics, component lists, and operational principles.
Preview AVT 1996 Bedlight Motion Detector Controller Kit Assembly Guide
Detailed guide for assembling the AVT 1996 Bedlight Night-Light Controller kit, featuring a motion detector and adjustable timer for LED strips. Includes specifications, circuit description, component list, and connection instructions.
Preview AVT 2728 Microphone Amplifier Kit - Assembly Guide and Specifications
Comprehensive guide for the AVT 2728 universal microphone amplifier kit, detailing its features, circuit design, component list, and step-by-step assembly instructions. Suitable for electret and dynamic microphones.
Preview Handy LED Flashlight Educational Soldering Kit by AVT
Build a functional LED flashlight with the AVT EDU627 educational soldering kit. Learn basic electronics and soldering techniques. Includes detailed assembly instructions and specifications.
Preview AVT EDU622 Twilight Switch LED Lamp Educational Soldering Kit
Build the AVT EDU622 Twilight Switch LED Lamp educational soldering kit. This guide provides specifications, schematic, assembly instructions, and safety information for creating a functional LED night lamp.
Preview AVT DMX512: USB to DMX Converter for Lighting Control
The AVT DMX512 is a USB to DMX converter designed for lighting control systems. It supports up to 512 devices, offers full galvanic isolation, and connects via USB and 3-pin XLR. Features include USB 1.1/2.0 compatibility and direct USB power, making it ideal for professional lighting operators.
Preview AVT 1995 Precise Timer 1 Second to 99 Minutes Assembly Instructions
Detailed technical overview and assembly guide for the AVT 1995 Precise Timer, a 1-second to 99-minute countdown timer kit with a relay output. Includes specifications, circuit description, operation, and component list.
Preview Elektronika dla Wszystkich - Kwiecień 2019
Magazyn Elektronika dla Wszystkich z kwietnia 2019 roku, oferujący projekty elektroniczne, artykuły techniczne, recenzje gadżetów i analizy nowości technologicznych, w tym serwomechanizm DMX i kursy Arduino.