1. Introduction
With the development of embedded system card technology and the decrease in microcontroller prices, microcontroller-based data collection systems have begun to be developed to store and monitor data. Although they are used in many different areas, they are especially preferred in buildings and in the continuous monitoring and control of renewable energy resources 24/7 [
1,
2,
3]. Thanks to micro-controlled data acquisition systems, much more convenient storage systems can be established.
In order to accurately quantify the energy consumption of an electrical device, it is crucial to first determine the type of current upon which the device operates. Since there is no time-changing signal in circuits operating with direct current, there is no phase difference between current and voltage, and the power factor does not occur in these circuits. It will be sufficient to know the current and voltage values of these devices to calculate the power they consume. In circuits operating with alternating current, it is mandatory to use the power factor in calculations due to the time difference between the current and voltage values occurring in inductive and capacitive loads.
There has been much research and new studies in the literature on energy management, energy monitoring, smart energy meters, and energy analysers, and this trend continues. Karthichk et al. [
4] designed an IoT-based commercial building energy management system to address IoT power quality problems and control the system. The system was tested at M/s Quantanics Techserve Private Limited. The system includes a real-time operating system and Advanced Reduced Instruction Set Computing (RISC) Machines (ARM). The energy meter in the proposed system was tested and compared with the Elmeasure iM-8000 meter. The results indicate that power quality issues are detected with over 90% accuracy. Mudaliar and Sivakumar [
5] applied a real-time energy monitoring and management system in their paper. The system they used included IoT and Raspberry Pi. This system, implemented in an industrial facility, is reported to be economical, compatible with new sensors, and highly efficient and accurate. Ferdiansyah and Wardana [
6] proposed a home energy power monitoring system. Their proposed system includes current-voltage sensors, an Arduino Uno, a relay, an LCD display, a cloud system, and IoT-based software. The system has been tested and found to have average voltage and current error rates of 0.30% and 0.28%, respectively, and provides real-time monitoring and management. Athanasiadis et al. [
7] developed a real-time power monitoring and estimation system for home appliances. A new power estimation algorithm is proposed, which includes non-invasive load monitoring (NILM) and a convolutional neural network classifier. Various tests have shown that the system has high accuracy, fast response, low-latency computation, high performance, and an efficient structure.
In their article, Hariharan et al. [
8] used an energy analyser system for a smart home management system. The system, which includes an Arduino Uno, has an Android application and is IoT-based. With its energy measurement feature, which can be recorded via the cloud, various system-related data can be accessed from mobile devices. Hussain et al. [
9] designed and tested an online energy control system. The system, which includes a SCADA server, an IoT-based energy monitoring system, and a LoRa-based system, consists of a microcontroller, a Raspberry Pi, a Data Communication Network (DCN), and a Data Acquisition System (DAQ). The designed system was tested with simulation programs such as MATLAB and Proteus, and experimental system design and results were examined, demonstrating its efficiency and flexibility in real-time implementation and measurement. Khanna et al. [
10] proposed a real-time energy meter for home and industrial usage. The proposed architecture, which allows for AC and DC measurements, used a Raspberry Pi. The system, which offers features such as high measurement accuracy, cost-effective implementation, ease of use, and integration with the EmonCMS web application, was tested with a PM3000 energy analyser. Elkholy et al. [
11] designed a smart home management system for energy savings. The system, which also integrates a PV system, includes a Raspberry Pi 4B. The Cayenne IoT system was used to implement energy management for a smart home. Testing and analysing the results revealed a 23.13% percent cost reduction. The proposed system is remotely accessible, efficient, economical, and reliable.
Chen et al. [
12] conducted an analysis of home electricity consumption. The study primarily focused on calibrating electricity meters. A smart energy analyzer was installed in the study home. The results were monitored and interpreted for four months. Similar pilot applications were implemented at the relevant electricity distribution company. Customer feedback was collected, and improvements were made. The study resulted in electricity savings, identification of actual energy demands, increased customer satisfaction, and improved service quality for the electricity distribution company. In the article, Paul and Manohar [
13] integrated an energy analysis system for smart grids. They automated energy measurement and billing in the proposed system. The IoT-based system provides customers with information about their consumption by communicating with them when necessary. The Arduino-integrated system provides efficient power analysis and user-friendly energy monitoring. Kumar et al. [
14] developed an IoT-based energy meter. The developed system utilises Fast Fourier Transform (FFT) calculations. The design utilises an ATMega328-P microcontroller to process sensor data to determine power. The system was tested against three Fluke power analysers and found to offer superior features, including low cost, efficiency, cloud storage, and accurate power measurement (<5% error rate). Kumar et al. [
15] implemented home energy management using a smart energy meter in their study. In a home energy management system that includes a PV system and batteries, various electrical information is obtained using meter data. Customer electricity consumption behaviour is determined in the system, and solutions are implemented. The designed analyser was tested with the Typhoon HIL simulation program, and it was determined that the proposed system achieved the best results compared to the other compared methods.
Radhika et al. [
16] implemented a home energy meter. In the designed system, the meter monitors home power consumption and sends a warning to the customer. Additionally, a power cut off feature can be activated based on consumption. The proposed system incorporates IoT integration using NodeMCU. Simulation and experimental results demonstrate the system’s accuracy and efficiency. Midul et al. [
17] introduced their internet-integrated smart energy meter design. Using Arduino Nano, the system performs energy monitoring and provides customers with power and energy information via Short Message Services (SMS). The system’s primary purpose is energy monitoring and billing. The system, which includes an ESP-8266 Wi-Fi module and a GSM module, was designed using Proteus software. Hassan et al. [
18] introduced a smart energy meter with billing features in their paper. The energy meter has an IoT-based system. The proposed system provides customer awareness through SMS and a mobile application. Muralidhara et al. [
19] designed an energy meter capable of device-based monitoring in their article. Their proposed system is IoT-enabled and efficient. The design, which includes a Wi-Fi module and an Arduino Uno, aims to raise awareness among home customers about the energy consumed by individual devices. The system can also record the resulting power data and send it to the ThingSpeak application.
Muthu et al. [
20] proposed the design of a remote-access smart energy analyser. The system, like similar studies, includes an IoT-based meter. The system includes a GSM module, Arduino, and sensors. The designed energy meter measures and stores the power data of each home appliance, and transmits it to an online storage unit via the GSM module. Ajay et al. [
21] implemented an energy management meter in their paper. The designed structure includes mechanisms such as an IoT system, a GSM module, an SMS system, two-way communication, and power outage management with a relay. Energy measurements can be sent to customers via SMS. In article [
22], Martinez-Blanco et al. designed and tested an IoT-based smart energy meter for homes. The study described an internet-connected smart meter that can analyse electricity and power consumption in homes. The proposed system includes an ESP32 microcontroller, an ACS712 current sensor, a relay, and an LM385 operational amplifier. Various tests were conducted with the Arduino-controlled system, allowing the energy analysis of different electrical appliances in a home to be observed. A literature review study for energy consumption analysis was conducted by Purwania et al. [
23]. This study provided information about the microcontrollers, sensors, IoT technology, devices, and other system requirements used. The comparative table of previous researches and this study can be seen in
Table 1.
When previous studies are reviewed, it is seen that in calculations where power factor is needed, the values from the central power factor measuring device located in the main distribution panel are used instead of individual measurements or the power factor is accepted as a constant value [
24]. As a result of measuring the power factor centrally, corrections to the power factor with the help of compensation panels is important in order to achieve the desired active/reactive power ratio. Power factor correction has beneficial results such as; increasing the energy quality, preventing fines due to low power factor, saving on the electricity bill, the opportunity to switch to more affordable tariffs, reducing the power drawn from the grid, reducing losses, enabling the purchase of less costly devices in electricity-related investments [
25,
26]. However, using the power factor value that is obtained from the central measurement when calculating the power consumed by a single device will cause the make a mistake in the calculations. The integration of the PZEM module in each sensor node facilitates independent measurements of values such as current, voltage, power and power factor without the need for any other devices, thus eliminating the dependency on the power factor (cos
).
The error rate obtained in the measurement will also be reflected on the electricity bill. For this reason, in order to obtain correct values in the measurements, it is necessary to measure the current and voltage drawn by each device and the power factor value of the device correctly. In this study, it is aimed to obtain accurate power consumption by measuring instantaneous power factor, current and voltage values with the proposed device.
In the developed application, communication between nodes done by RF transmission. For the RF module nRF24L01 is used. nRF24L01 is a single chip 2.4GHz transceiver having embedded baseband protocol engine, specially designed to provide support to ultra-low power wireless applications. It is capable of transmit and receive data in half duplex and full duplex modes when programmed using a microcontroller. It uses SPI communication protocol and uses four data lines MOSI, MISO, SCK and CLK. It has multiple bit rate options 250kbps, 1Mbps and 2Mbps, and bit rate can be changed by developers based on specific needs by programming initials of the module [
27]. It has features like auto-retransmission that activates when there is packet loss, and automatic acknowledgment that provides reliable data transmissions, making it suitable for applications where data integrity is crucial. nRF24L01 provides cost-effective and efficient solutions for wireless communication applications like sensor networks, remote control systems, home automation and robotics [
28]. For these features, it has chosen for the application of this study.
PZEM-004T is another module that is used in the developed application. It is the measurement unit of the application. It measures key electrical parameters such as Voltage, Current, Real Power, Apparent Power, Reactive Power and Power Factor. It uses UART communication protocol and has four pinouts, VCC, GND, TX and RX. TX an RX pins are used in communication one transmits and other one receives [
29]. PZEM-004T could have slightly low accuracy when comparing it with other measurement devices but it has compact and durable design, better stability then the compared ones and ease of integration with IoT platforms [
30]. These features making it suitable for the developed project.
The ESP8266 (NodeMCU) was selected for this application because it offers an integrated, low-cost solution that combines a microcontroller, memory, and a built-in 2.4 GHz Wi-Fi module, enabling seamless Internet connectivity essential for IoT systems. With its Tensilica Xtensa 32-bit LX106 processor, 128 KB of RAM, and up to 4 MB of Flash memory, it provides sufficient processing power and storage for both control logic and data handling while leaving resources available for user applications [
31]. Despite having a limited number of GPIO pins, its compatibility with shift registers such as the 74HC165 allows flexible input expansion for interactive elements [
32]. Furthermore, its support for both station (client) and soft-AP (access point) modes, built-in TCP/IP networking capabilities, and a strong open-source ecosystem make it highly adaptable for IoT development [
33]. These features, combined with affordability and wide community support, make the ESP8266 an ideal choice for implementing efficient, scalable, and cost-effective IoT solutions.
Thanks to this new design, the measured values were recorded in the defined time period from the moment the system was commissioned until it was deactivated. In the developed system, date, time, voltage, current, active power, reactive power, apparent power, frequency, and power factor values are recorded. In this system, characterized by its flexible architecture, new parameters such as humidity, temperature, and others can also be integrated by selecting the appropriate devices. The most important point to consider here is the number of input and output pins and the supply voltage range of the microcontroller used. The sensors to be connected to the input terminals of the microcontroller must have maximum value of 5 V.
The developed system additionally has the following features. After the system is activated, it records the measured values every second for a duration of 1 second per sensor node. This sampling time can be adjusted if desired. The system has a flexible structure. It can be improved by adding new sensors. Since the system has its own MicroSD card, it does not need a separate computer. The requested data is saved directly to the file with CSV (Comma-Separated Variables) extension. This recording format can be converted to TXT (Text) by simply changing the file extension. Since both writing formats are alike and the only difference between them is that the delimited fields are tab or comma separated, the format can be adjusted according to the preference of the person using the device. Since the data is saved on the SD card compatible with different operating systems, it can be used in any Windows, Linux or MACOS operating system without the need for any additional software. The data is also saved on a PostgreSQL database via Wi-Fi as JSON to a Node.js API server, which securely stores the data.
Additionally, the resulting txt file can be opened with Notepad or can be easily transferred to application programs such as MATLAB, Excel, R, etc., where graphical results can be obtained by performing mathematical analysis. Thanks to the LCD (Liquid Crystal Display) in the system, the desired data can be displayed on the screen, thus eliminating the need for an additional external display. Finally, the file in which the data is saved can be transferred to the computer by means of the Micro SD card slot or wireless network.
The main contributions of this study are listed as follows;
The energy consumption of all desired household appliances can be measured and recorded without the need for a computer. Additionally, all measurements can be controlled via Web and mobile applications to prevent overconsumption.
The instantaneous power consumption and power factor of individual household appliances can be monitored.
The sampling interval for energy measurements can be adjusted,
The proposed system provides low data usage for data recording and consumes minimal memory space,
The system has a data output structure suitable for detailed data analysis in different computer programs,
Data can be stored on the server with the PostgreSQL database recording feature,
This paper contributes to the literature for future energy monitoring system studies,
Additionally, the study results show the energy consumption trends of household appliances.
The system has a flexible structure. Regardless of brand, the system can be expanded depending on the number of pins on the microcontroller and the input and output voltages of the new sensors/devices to be connected.
Moreover, environmental functions such as temperature, humidity, gas sensors, etc.can be easily integrated into the system.
In order to improve the measurement accuracy of the measurements, an ADC with a higher number of bits can be added.
In the proposed system, coordinator nodes can control different and independent sensor nodes. By placing sensor nodes at all electrical outlets in a home, energy monitoring of all connected appliances can be achieved from a single point. Communication between the sensor nodes and the coordinator node is achieved remotely via Wi-Fi and RF.
By easily changing the embedded system software, the system can work with different communication protocols such as ZigBee in addition to Radio Frequency and Wi-Fi.
As a result of the measurements, it is observed that the measurement error in voltage, current, power factor, and power is generally a maximum of 1% when the results are compared with a more sensitive etalon device.
In consequence of power measurements, it was determined that the average absolute percentage error was 1.71%.
2. Design and Implementation of Project
The system’s architecture employs a star network topology, a configuration that is particularly advantageous for IoT applications involving multiple distributed nodes communicating with a central entity. The configuration of the architecture in question has been demonstrated to facilitate the streamlining of network administration and ensure the efficient transmission of data from measurement points to the central aggregation and logging unit [
34].
The system is composed of two distinct categories of devices: The Sensor Node(s) and the Coordinator Node. The Sensor Node(s) consist of one or more units that are dedicated to the measurement of electrical parameters at designated locations. Conversely, the Coordinator Node functions as a centralized hub that collects, displays and records the data transmitted by all sensor nodes.
The Sensor Node’s primary function is to operate as a remote data acquisition unit. The primary functions of the device encompass measurement, RF transmission, and user configuration. For measurement purposes, the device interfaces with the PZEM-004T v3.0 energy meter via a serial connection, enabling the periodic acquisition of a comprehensive set of electrical parameters. These parameters include voltage, current, power, energy, frequency, and power factor [
35]. With regard to RF transmission, the collected data are encapsulated into a custom data structure and wirelessly transmitted to the Coordinator Node via the nRF24L01 module [
36]. With regard to user configuration, the Sensor Node instigates a self-contained web server in the absence of a connection to a known Wi-Fi network. The server in question provides an interface that enables users to scan available networks and submit their credentials. This facilitates a user-friendly initial setup, obviating the need for prior programming or serial communication. Sensor node also shows the needed information such as IP address, Voltage, Current, Power, etc. on the LCD screen.
The Coordinator Node is the system’s central control unit and data repository. The core responsibilities of the system encompass RF reception, data processing and visualisation, data logging, and time synchronisation. With regard to RF reception, the system under discussion perpetually monitors the receipt of data packets from all registered sensor nodes. With regard to data processing and visualisation, the system parses the received packets and presents real-time information from a selected sensor on the integrated OLED display. A physical button is also present, enabling the user to cycle through the active sensors. In the context of data logging, each received data packet is appended to a CSV file stored on a MicroSD card, along with a Unix timestamp, to a CSV file stored on a MicroSD card and PostgreSQL database. This process ensures the creation of a permanent and long-term record of the system’s energy consumption. In order to achieve time synchronisation, the node is required to establish a connection with a user-specified Wi-Fi network during the initialisation process. This is done exclusively to align the node’s internal real-time clock (RTC) with an NTP server. The purpose of this alignment is to ensure that all logged data is accompanied by globally accurate timestamps. As illustrated in
Figure 1, a general block diagram is provided which demonstrates the relationship between the sensor nodes and the Coordinator Node.
2.1. Communication Protocols Used in Proposed System and Data Flow
In the proposed system, the connection and communication with the computer are facilitated through a Universal Serial Bus (USB) interface. It is evident that microcontrollers utilise serial communication protocols for the purpose of interacting with peripheral devices. Specifically, the protocols employed for facilitating device-to-device communication include Universal Asynchronous Receiver Transmitter (UART), Inter-Integrated Circuit (I
2C), and Serial Peripheral Interface (SPI). The various types of serial communication connections utilised within the system are illustrated in
Figure 2 [
37].
By default, the UART port on the microcontroller operates through digital pins 0 and 1, designated as TX (Transmit Data) and RX (Receive Data), respectively. In order to facilitate effective communication, it is necessary for the corresponding terminals of the devices to be interconnected. It is evident that UART communication facilitates data exchange between two devices, yet it does not necessitate the utilization of a synchronous clock signal. The overall system architecture incorporates a set of communication protocols, each of which has been selected for its particular advantages within the context of the project [
38]. The protocol employed for enabling point-to-point communication between the ESP8266 microcontroller and the PZEM-004T energy meter within each Sensor Node is the Universal Asynchronous Receiver-Transmitter (UART) protocol. This protocol, utilizing merely two lines (TX and RX), provides an efficient means of acquiring the digital measurements generated by the sensor. The ubiquity of UART as a standard for inter-chip communication can be attributed to two key characteristics: simplicity and robustness.
Another communication protocol employed by the microcontroller is the I
2C (Inter-Integrated Circuit) protocol. The protocol necessitates two lines and pull-up resistors for physical connectivity, a characteristic that has led to its designation as the Two-Wire Interface (TWI). The I
2C interface, initially developed by Philips, employs SDA (Serial Data) and SCL (Serial Clock) terminals. The protocol supports data transfer speeds of up to 400 Kbps, with SDA facilitating data transmission between devices and SCL ensuring proper timing synchronization [
39]. In the proposed system, the Coordinator Node employs the I
2C protocol to interface with the OLED display. The I
2C bus is particularly well-suited to this application due to its ability to share a bus between multiple devices, thereby optimizing the utilization of GPIO pins on the microcontroller.
The SPI protocol, developed by Motorola, is a protocol that is commonly employed for communication with pre-assembled expansion modules (shields) in embedded systems due to its high-speed data transfer capabilities [
40]. In contrast to UART, SPI facilitates concurrent communication with multiple devices. Like I
2C, it necessitates a master device that functions as the orchestrator of communication, controls device selection, and manages the timing of data exchanges. SPI communication utilises four primary terminals: The MOSI (Master Out Slave In), MISO (Master In Slave Out), SS (Slave Select), and SCK (Serial Clock) are also used. The MOSI transmits commands from the master to the slave devices, the MISO returns data from the slaves to the master, the SS selects the active slave device, and the SCK synchronizes data transmission. The extant research indicates that SPI exhibits lower energy consumption than I
2C and UART, while achieving superior data transfer speeds. Indeed, SPI supports rates of 4 Mbps and higher [
41]. In the proposed system, the SPI protocol is utilised by the microcontrollers to interface with both the nRF24L01 RF module and the SD Card module. Despite the aforementioned similarities, it is important to note that both peripherals share common data and clock lines (MOSI, MISO, SCK). However, independent Chip Select (CS) pins ensure exclusive control, thereby allowing the microcontroller to activate only the intended device. This configuration facilitates the sharing of a common bus by multiple high-throughput devices without the occurrence of conflicts [
42].
The wireless energy monitoring system employs a variety of complementary communication protocols to ensure reliable data acquisition, transmission, and logging. As illustrated in
Figure 3, the specific protocols employed and their respective functions within the overall data flow architecture are mapped to their corresponding layers in the OSI (Open Systems Interconnection) reference model. This highlights their roles in ensuring structured and efficient communication across the system [
43].
Radio Frequency (RF) via nRF24L01 is the primary data link between the sensor(s) and the coordinator. The nRF24L01’s “Enhanced ShockBurst” protocol provides features like packet acknowledgment and retransmission, creating a reliable link. The network is configured with the coordinator listening on multiple “pipes (ports)”, allowing it to receive data from up to six sensor nodes concurrently without data collision. Data is sent as a compact binary struct, which is far more efficient than text-based formats like JSON for this application, reducing transmission time and power consumption [
36].
The IEEE 802.11 standard, commonly referred to as Wi-Fi, plays a dual role in this context. Initially, the Sensor Node operates in Access Point (AP) mode to provide a secure, password-protected, web-based configuration portal, including a captive portal that automatically redirects users to the setup interface. Following configuration, the Sensor Node transitions to Station (STA) mode to establish a connection with the user’s network. In this mode, the Node hosts a password-protected web dashboard, facilitating real-time data monitoring and device management. On the Coordinator Node, Wi-Fi operates solely in Station (STA) mode, primarily to perform an NTP query at start-up to obtain the current time [
44]. In the event of a connection failure, the Coordinator Node has the capacity to receive updated network credentials from a Sensor Node via the RF handshake mechanism.
As demonstrated in
Figure 4, the system’s operation is facilitated by a meticulously structured data flow. The process under discussion may be subdivided into three distinct phases: initial setup, coordinator synchronization (including a specialized handshake for configuration), and the primary operational loop. The sequence diagram provides a clear representation of the data flow within the system.
The initial device setup is a user-driven phase that is required only once for each sensor node. The user is required to establish a connection between a computer or smartphone and the Wi-Fi Access Point that is broadcast by the Sensor Node. This is then followed by the user accessing the configuration portal via a web browser. It is via this interface that the user selects the local Wi-Fi network and submits the corresponding password. The Sensor Node is responsible for storing these credentials in its non-volatile EEPROM memory, and subsequently reboots in order to apply the new configuration [
45].
The process of Node Initialization and Configuration Handshake is initiated. Upon initiation, both the Sensor and Coordinator Nodes initialize their nRF24L01 modules to operate on the same RF channel and communication pipes. Subsequently, the Coordinator Node endeavours to establish a connection with the Wi-Fi network that has been stored. In the event of a successful outcome, the system synchronizes its internal clock with an NTP server, thereby ensuring the provision of precise timestamps for data logging. In the event of a connection failure, such as the presence of missing or incorrect credentials, the coordinator enters a specialized Requesting Config state. In this state, the system transmits a request packet to a Sensor Node via the RF link. Upon receipt of the request, the Sensor Node responds by transmitting its verified Wi-Fi credentials to the coordinator, which stores them in its EEPROM and reboots. This mechanism enables the coordinator to be configured without the need for direct user intervention, a critical feature for headless deployment.
Main Operational Loop: This phase constitutes the continuous core operation of the system. The Sensor Node periodically polls the PZEM-004T sensor to acquire the latest electrical measurements, packages the data into a compact binary structure, and computes a checksum for preliminary data integrity verification. Subsequently, the packet is transmitted to the Coordinator Node, where the nRF24L01 module automatically verifies the CRC. In the event that the CRC is valid, the coordinator firmware will proceed to verify the internal checksum. Upon successful completion of the full validation process, the Coordinator’s RF module transmits an acknowledgment (ACK) to the Sensor Node, thereby confirming the successful delivery of the message. The coordinator then processes the data by retrieving the current timestamp, formatting the data as a CSV string, appending it to the SD card log, and updating the OLED display. In the event that the Sensor Node does not receive an acknowledgement (ACK), due to packet loss, corruption, or a lost acknowledgment, the nRF24L01’s Enhanced ShockBurst protocol will automatically retransmit the packet. This ensures a highly reliable communication link [
42].
The system aims to improve data reliability and enable remote backup by combining local SD card storage with a secure, scalable architecture. While sensor data is still logged to an SD card on the ESP8266 device, it is also transmitted via Wi-Fi as JSON to a Node.js API server, which securely stores the data in a PostgreSQL database. This hybrid approach protects against SD card failures, ensures structured long-term storage, and provides remote access to measurements. Depending on project needs, the API server and database can run locally on a laptop for development, on a Raspberry Pi for low-cost continuous operation, or in the cloud for global accessibility, high availability, and scalability.
2.2. Hardware Components
The hardware selection was guided by criteria emphasizing low cost, high availability, modularity, and robust community support.
The ESP8266 is a low-cost Wi-Fi microchip featuring a complete TCP/IP stack and integrated microcontroller functionality. The device is powered by a 32-bit Tensilica L106 RISC processor, which provides sufficient computational capability for the tasks required in this project. The device’s defining feature is the incorporation of a 2.4 GHz Wi-Fi transceiver, which conforms to the IEEE 802.11 b/g/n standards, thus facilitating connectivity to wireless networks or its utilisation as an access point. The NodeMCU development board integrates the ESP8266 chip with essential peripherals, encompassing a USB-to-serial converter for programming and debugging, a 3.3 V voltage regulator, and breadboard-compatible I/O pins. The ESP8266 functions as the central processing unit for both the Sensor and Coordinator Nodes, with its high-performance processor and integrated Wi-Fi facilitating the project’s user-friendly web-based configuration and monitoring interface [
35].
The PZEM-004T is a compact, self-contained energy metering module. The device is able to measure voltage through direct connection to the AC line within a range of 80–260 V and measure current using a non-invasive current transformer (CT). The CT is designed to clamp around a single AC conductor, thereby detecting the magnetic field that is generated by the current flowing through it; this configuration obviates the requirement for physical contact with high-voltage wiring. The onboard circuitry, which includes a dedicated metering IC, processes these signals to compute RMS voltage, RMS current, active power (W), power factor, frequency (Hz), and cumulative energy (Wh). The parameters are made accessible through a 5 V TTL serial (UART) interface, employing the Modbus-RTU protocol. The primary function of the module is to facilitate the abstraction of the complexity and safety risks associated with direct AC power measurement. The utilisation of complex analog signal conditioning and computational circuits is circumvented by the microcontroller, which has the capacity to directly request precise digital measurements from the module via serial commands. This approach has been shown to significantly simplify the design of the Sensor Node, enhance measurement accuracy, and improve the overall safety of the system [
46].
The nRF24L01+ module operates within the 2.4 GHz Industrial, Scientific, and Medical (ISM) radio band. Despite the absence of Wi-Fi functionality, the device utilises a proprietary communication protocol, designated as ’Enhanced ShockBurst, to facilitate communication. This packet-based transport layer protocol has been developed to automatically manage critical low-level functions, including packet framing, CRC-based error detection, and, most importantly, automatic packet acknowledgment (ACK) and retransmission (ART). Upon transmission of a data packet by a Sensor Node (Transmitter, PTX), a response in the form of an ACK from the Coordinator (Receiver, PRX) is awaited. In the absence of acknowledgement within a predefined interval, the module automatically retransmits the packet, thereby significantly enhancing link reliability without imposing complex logic on the microcontroller firmware. The selection of the nRF24L01+ module was informed by the intentional preference for establishing a private data network over Wi-Fi for inter-node communication. The advantages of this decision include low latency, simplicity, network isolation and reliability. This configuration provides enhanced communication speed and reliability in comparison to a full TCP/IP link, whilst maintaining the separation of sensor traffic from the primary Wi-Fi network. This approach has the dual benefits of enhancing both network security and performance. The ’Enhanced ShockBurst’ protocol is an innovative piece of technology that solves a number of problems inherent to the field. By handling acknowledgments and retransmissions at the hardware level, it ensures a highly reliable link without the need for extensive software overhead [
36].
The project employs two types of displays, each tailored to the specific function of its respective node. Both types of display utilise the I2C protocol to minimize microcontroller pin usage. The Sensor Node incorporates a standard 16x2 (16 columns, 2 rows) character LCD. These displays typically necessitate a multitude of parallel data pins; nevertheless, to streamline the wiring process, an I2C ’backpack’ module has been integrated with the LCD. The present module incorporates a PCF8574 I/O expander chip, thereby functioning as a bridge, translating two-wire I2C commands (SDA and SCL) from the microcontroller into the parallel signals required to operate the LCD. As has been confirmed in the Sensor Node firmware, the I2C LCD provides immediate on-site visual feedback of electrical measurements, cycling through voltage, current, power, and other critical parameters. This feature enables the preliminary configuration and diagnostic procedures to be conducted without the requirement of accessing the web interface.
LCD screen was used to instantly monitor the data obtained in the control section It can be connected to the microcontroller by different methods, and care has been taken to use the minimum number of terminals. There are a total of 16 pins on the LCD board. The first terminal, Vss, is used for ground, and the second terminal, Vdd, is used for the supply voltage. V0, the third pin of the LCD, is used to adjust the contrast of the LCD screen by using a
potentiometer. If contrast adjustment is not desired, this terminal must be grounded. The fourth pin, RS (Register Select), is used to switch between sending commands or reading data. When the RS terminal is 1 (HIGH), the data option will be selected. In this case, pins D0-D7 will be used for data. When the RS pin is 0 (LOW), the command option will be selected instead of data and D0-D7 pins will be defined for the command. R/W (Read/Write) terminal is the fifth terminal and is used to determine whether the data will be written to the LCD or the data will be read from the LCD. When the R/W pin has a value of 0, it indicates that data will be written to the LCD, and when it has a value of 1, it indicates that data will be read from the LCD. E (Enable) terminal is the sixth terminal and enables writing to Registers. There are eight D0-D7 terminals and these terminals are used as data bus. Commands or data are sent to the LCD from these terminals. When the LCD is operated as 4 bit, D4-D7 pins will be used. The remaining 4 ends (D0-D3) will not be connected. When the LCD is first powered on, it starts working in 8-bit mode. Start-up commands are sent in 8 bits. Since the D0-D3 pins are not connected, they cannot carry the bits they receive. After the first 4 commands, the LCD is switched to 4-bit operation. When the LCD is operated as 8 bits, all D0-D7 pins will be actively used. The last two pins on the LCD board are the fifteenth and sixteenth pins and are designated A and K. These terminals are used to illuminate the background of the LCD screen. Since the LCD screen is illuminated with an LED lamp, the A terminal represents the anode (+ terminal) and the K terminal represents the cathode (- terminal). For screen illumination, 5 V must be entered at the A terminal and 0V must be entered at the K terminal. In case of direct connection of the LCD board to the microcontroller board, it is necessary to use many pins on the microcontroller. If 4 bits are used, 12 bits will be used, and if 8 bits are used, a total of 16 bits will be used. I
2C converter card was used in the project to use fewer pins. Thanks to this card, pin savings are achieved on the microcontroller card, which uses only four pins on the microcontroller [
2,
47]. The LCD card, which has 16 pins, is connected to the microcontroller with the help of the I
2C converter card is shown in
Figure 5. The jumper on I
2C is used for addressing. Since only one LCD screen with I
2C converter was used in the project, there was no need for addressing. When more than one LCD screen is wanted to be used with an I
2C converter, it must be addressed using the A0, A1 and A2 (Address input 0,1,2 = Address input 0,1,2) terminals with the help of a connecting wire.
The Coordinator Node utilises a 128x64 pixel monochrome Organic Light Emitting Diode (OLED) display. In contradistinction to LCDs, which necessitate a backlight, each OLED pixel emits its own light. This results in superior contrast (true blacks), wider viewing angles, and reduced power consumption, particularly when large portions of the screen remain dark. The communication with the microcontroller is facilitated by the I
2C protocol, typically through an SSD1306 driver chip [
48]. The OLED display, which functions as the primary user interface in accordance with the Coordinator Node firmware, provides a rich graphical representation of real-time data from the Sensor Nodes. This graphical representation includes system status indicators, such as Wi-Fi connectivity and time, as well as the ability to identify the currently selected sensor. The higher resolution of the device’s display relative to that of the character LCD facilitates the presentation of more detailed and user-friendly information.
The MicroSD Card module constitutes a compact breakout board that integrates a MicroSD card socket in conjunction with level-shifting circuitry, thereby facilitating the interface between a 3.3 V microcontroller and a 5 V SD card. It communicates with the microcontroller via the SPI bus. In this configuration, the data and clock lines are shared between the two components, namely the nRF24L01+ module and the aforementioned microcontroller.
The firmware utilises the standard SD library, which implements the FAT (File Allocation Table) file system. Consequently, the generated files are able to be readily accessed by any computer. The MicroSD card module, a standard component, offers persistent and high-capacity storage. The utilisation of the FAT (File Allocation Table) file system ensures that the resulting CSV (Comma Separated Values) log files are universally compatible. The provision of a reliable power supply is of critical importance for the stability of embedded systems. In order to guarantee uninterrupted and reliable functioning of the Sensor Node, a compact 220 VAC to 5 VDC power supply module is employed. This configuration enables the system to be powered directly from a standard wall outlet, thereby eliminating the requirement for external USB adapters and ensuring consistent performance. The 5 V output from this converter is supplied to the VIN pin of the NodeMCU boards.
The system’s modules have varying voltage requirements: the ESP8266 and nRF24L01+ operate at 3.3 V, whereas the PZEM-004T and LCD can function at 5 V. The NodeMCU board’s onboard 3.3 V regulator adequately powers the ESP8266 and nRF24L01+; however, the nRF24L01+ is particularly sensitive to power supply fluctuations, especially during transmission bursts. To maintain stable operation, a decoupling capacitor (e.g., 10 µF) is commonly placed directly across the module’s VCC and GND pins to mitigate voltage drops [
49].
The system consists of two ESP8266-based nodes with distinct pin assignments for their respective functions. The sensor node utilises pins D4 (GPIO2) and D0 (GPIO16) for UART communication with the PZEM-004T energy monitoring module. For wireless communication, pins D3 (GPIO0) and D8 (GPIO15) control the nRF24L01 transreceiver’s CE and CSN signals, while SPI communication employs pins D5 (GPIO14) for SCK, D7 (GPIO13) for MOSI, and D6 (GPIO12) for MISO. The sensor node’s LCD display connects via I
2C using pins D2 (GPIO4) for SDA and D1 (GPIO5) for SCL [
49].
The Coordinator Node employs the same nRF24L01 and SPI pin configuration used by the Sensor Node. Furthermore, it interfaces with an SD card module using pin D4 (GPIO2) as the chip select, whilst sharing the common SPI bus. The OLED display employs the same I
2C pins as the Sensor Node’s LCD, with D2 (GPIO4) for SDA and D1 (GPIO5) for SCL. This configuration has been demonstrated to guarantee effective use of hardware resources, whilst concurrently ensuring that clear functional separation between the two nodes is maintained. As demonstrated in
Figure 6 and
Figure 7 the pin configurations of the Sensor and Coordinator Nodes are illustrated respectively. The sensor nodes and the coordinator node communicate with each other via RF.
2.3. Software Implementation for Embedded Cards
The firmware for both nodes was developed in the programming language C++, utilising the embedded framework provided by the PlatformIO integrated development environment (IDE). The development process was executed within the Visual Studio Code environment, utilising PlatformIO’s sophisticated features for dependency management and project organisation [
50].
The key interfaces employed in the project are as follows: The following header files are required for interfacing with the PZEM-004T v3.0 module: PZEM004Tv30.h. The following header files are required for managing nRF24L01+ RF communication: RF24.h. The following header files are required for implementing the non-blocking web server on the Sensor Node: ESPAsyncWebServer.h. The following header files are required for controlling the I2C LCD on the Sensor Node: LiquidCrystal_I2C.h. The following header files are required for operating the I2C OLED on the Coordinator Node: Adafruit_SSD1306.h. The following header files are required for interfacing with the MicroSD card module: SPI.h and SD.h. The following header file is required for persistent storage of configuration data: EEPROM.h. The Sensor Node firmware (sensor_node.cpp) can be regarded as a sophisticated application, in that it is capable of harmonising real-time data acquisition with a user-friendly and secure Wi-Fi configuration interface.
The firmware’s operation is structured around a state machine implemented within the main loop function. The device operates in two primary modes, as illustrated in the state diagram shown in
Figure 8.
Station (STA) Mode is the default mode. It connects to a known Wi-Fi network to enable its web interface and potentially other network services. It continuously reads sensor data and transmits it to the coordinator. If it fails to connect to a saved network, it creates its own Wi- Fi network. In Access Point (AP) mode, its sole purpose is to serve a web page that allows the user to configure new Wi-Fi credentials. This fail-safe mechanism ensures the device is always configurable.
Security represents a primary concern in the system’s design, with multi-layered measures incorporated to ensure protection. These include the use of Secure AP Mode, a web interface subject to authentication, management of sessions, and the configuration of credentials. Upon entering AP (Access Point) mode for configuration, the device does not generate an open network. In the implementation of the sensor_node.cpp, the AP is secured with WPA2 encryption using a hardcoded password. For a production environment, this password is made unique per device, it is derived from their MAC address, to prevent unauthorized initial setup. Once connected in STA mode, access to the web interface is not public. The firmware implements a login system (handleLogin, authenticate). Users must provide a valid username and password to access any page. This prevents unauthorized users on the same Wi-Fi network from viewing energy data or changing device settings. Upon successful login, the server creates a session cookie (PZEMTOKEN) to keep the user logged in for a set period, providing a seamless user experience without requiring a login for every page click. Users are not stuck with default credentials. The /user-settings page allows them to change the login username and password, which are then saved securely to the device’s EEPROM. The user’s password is not written to EEPROM in plain text. Instead, a random "salt" value is generated for each password and the password’s "salted hash" (salted SHA-256 hash) is stored. This makes it impossible to obtain the original password even if the EEPROM is read.
The Coordinator Node firmware (coordinator_node.cpp) places particular emphasis on reliability, data integrity, and ease of management. The system has been engineered to ensure uninterrupted data acquisition, even in the face of network challenges. The firmware functions in accordance with a state machine that determines the coordinator’s operational mode based on Wi-Fi connectivity. As demonstrated in
Figure 9, the ’Data Processing’ path remains continuously active.
Multi-Pipe listening and Wi-Fi configuration handshake are advanced communication protocols. The nRF24L01 is configured to listen on multiple “reading pipes” each with a unique address corresponding to a sensor. This configuration facilitates the Coordinator Node’s reception of data from multiple Sensor Nodes concurrently without the occurrence of packet collisions. The coordinator is distinguished by a distinctive mechanism that facilitates configuration without the necessity of a direct user interface. In the event of an unsuccessful attempt to connect to the Wi-Fi network, the device transitions into a state designated as REQUESTING CONFIGURATION. During this phase, the device initiates the transmission of a unique request packet to Sensor Node 1. Upon receipt of the aforementioned request, the Sensor Node returns its stored Wi-Fi credentials to the coordinator. The coordinator then saves the aforementioned credentials and reboots, automatically joining the network. This handshake protocol has been demonstrated to significantly simplify the deployment of new coordinators within an existing system.
During the developmental process, a number of practical challenges were encountered. With regard to RF interference, preliminary testing revealed sporadic packet loss, attributable to interference from proximate Wi-Fi networks operating within the same 2.4 GHz band. This issue was mitigated in a number of ways. Firstly, a less congested RF channel was selected, which was located within the operational range of the nRF24L01 module. Secondly, the module’s built-in error correction and retransmission features were utilised. With regard to power stability, the nRF24L01+ module has been shown to be particularly sensitive to fluctuations in supply. Early prototypes demonstrated reliability concerns until the implementation of a stable 3.3 V power supply, which occasionally necessitated the integration of an additional decoupling capacitor directly across the module’s power pins to mitigate current spikes during transmission.
2.4. User Interface (UI) Analysis
The Sensor Node provides a comprehensive, self-hosted web interface for configuration, real-time monitoring, and data analysis. The interface has been designed to prioritise security, user-friendliness and accessibility from any contemporary web browser within the same network. Access to the system is protected by a username and password authentication system. The ensuing sections are devoted to a detailed description of each page of the web interface, including its intended purpose and its most salient features.
The login page functions as the primary security gateway for the system, thereby preventing unauthorised access to energy data and device settings. In order to successfully complete the authentication process, it is necessary to provide a valid username and password. The default credentials are provided during the initial setup process. In the event of erroneous credentials being entered, the system displays a generic error message without indicating which part of the credential was invalid. In the event of a successful login, the server generates a session cookie (PZEMTOKEN) for the purpose of maintaining user authentication across different pages for a defined period.
The dashboard functions as the centralised control panel for real-time data visualisation, thereby providing an overview of all critical electrical parameters measured by the PZEM-004T sensor. The page employs JavaScript to retrieve updated data from the /data API endpoint at 500 millisecond intervals, thereby ensuring that the values displayed remain current without requiring a page refresh. The primary dashboard provides a comprehensive data display, incorporating voltage (V) and current (A) with graphical gauges denoting levels relative to predefined maxima, real power (W), apparent power (VA), and reactive power (VAR). This offers a complete view of power consumption. Furthermore, the display incorporates dedicated value cards and gauges to present cumulative energy (kWh), frequency (Hz), and power factor (PF). A status bar situated at the top of the screen provides information regarding the connected Wi-Fi network (SSID), the device’s IP address, its unique Device ID, the status of the nRF24L01 connection, and the current system time if synchronised with an NTP server. A persistent navigation menu facilitates straightforward access to additional interface sections, encompassing Charts, Wi-Fi Settings, Device Settings, User Settings, and Logout. The user interface is illustrated in
Figure 10.
Charts page offers a powerful tool for historical data analysis, allowing the user to visualize trends in energy consumption over time. Interactive graphing utilises the Chart.js library to render dynamic, interactive line charts. Users can select which parameters (e.g., Voltage, Current, Power) to display on the chart using a series of checkboxes. The chart intelligently groups related data on different Y-axes for clarity. It fetches the buffered data and provides it to the user as a PZEM data.csv file for offline analysis in spreadsheet software. Users can clear the device’s internal data buffer.
The Wi-Fi Settings page offers a user-friendly interface for connecting the Sensor Node to a local Wi-Fi network, which is imperative for initial device setup, particularly when operating in Access Point (AP) mode. The initiation of an asynchronous request to the /scan endpoint is facilitated by the ’Scan Wi-Fi Networks’ button. The results are presented in a dropdown list, which displays each network’s SSID and signal strength (RSSI), thus enabling the user to select the desired network with ease. The Wi-Fi credentials can be entered in a standard password field. Upon submission, the credentials are stored in the EEPROM of the device and the device subsequently reboots automatically in order to establish a connection with the new network.
The User Settings page facilitates the management of security credentials for accessing the web interface. The system incorporates a designated interface to modify usernames and passwords, a crucial aspect for ensuring device security following the preliminary configuration. It is notable that the ’Reset Zone’ section facilitates access to critical operations that have the potential to be destructive; these include links to the ’/factory-reset’ page and the ’/reset-energy’ page. The latter enables the user to reset the cumulative energy (kWh) counter on the PZEM module to zero.
Device Settings page is used to configure the unique identifier for the sensor node within the nRF24L01 network.
The Device ID configuration feature incorporates a dropdown menu that enables the user to assign the Device ID to either 1 or 2. This functionality is pivotal in facilitating communication between multiple Sensor Nodes and the Coordinator, thereby preventing address conflicts. The Status Display provides information regarding the current Device ID and the operational status of the nRF24L01 radio connection. Subsequent to any alteration in the Device ID, the nRF24L01 module is automatically reinitialised with the updated address settings, thus ensuring seamless communication.
System Action pages are a type of informational interface that functions as a confirmation or status page, designed for specific operations. The /factory-reset page presents a conspicuous cautionary notice concerning the ramifications of executing a factory reset, a process that results in the complete removal of both Wi-Fi and user settings. It is important to note that this action is only undertaken upon the explicit confirmation of the user. The /reset-energy page displays a confirmation dialog prior to issuing the command to the PZEM module to reset its cumulative energy counter, thereby initiating a new measurement period. The logout page serves to inform the user of a successful logout, and automatically redirects to the login page after a brief interval.
4. Sample Results
Subsequent to the design and installation stages, an evaluation of the system’s precision was conducted utilising a calibrated reference device (Hioki 3334), a model that has garnered recognition for its superior measurement accuracy. The developed device’s sampling rate is 5Hz as default, and it gives the results by 1 second intervals. These rates can be changed by needs.
The initial testing procedure entailed the execution of instantaneous measurements while varying loads were in use. These loads included a 1200W resistive element connected to an electric stove (with selectable operating times), two 20W compact fluorescent lamps (CFLs), a 1600W hair dryer, and a water dispenser. Subsequently, the software was updated to account for any measurement errors. The LCD display provides a comprehensive overview of the system’s status, including the date, time, voltage, current, and power factor measurements. The summary of the instantaneous measurement results is presented in
Table 4, with voltage (V) measured in volts and current (I) measured in amperes. The observed error was consistently below 1% across all measurements, with the maximum recorded error being 1.86%.
Subsequent to the execution of instantaneous measurements and sensitivity tests, the device was connected to a selection of domestic electrical appliances. Concurrently, both instantaneous and periodic measurements were conducted. The measurement of the parameters was conducted at regular intervals, with the data being recorded on an SD card via the data acquisition system in accordance with the stipulated sampling interval as defined within the programme. The results of the instantaneous measurements are presented in
Table 2, with voltage (V) measured in volts, current (I) measured in amperes, and power (P) measured in watts. The magnitude of the error as indicated by the measurements was found to be no greater than 2.11% for voltage, current and power factor. The Average Absolute Percentage Error (MAPE) was calculated across all measurements, yielding a result of 1.71%.
As illustrated by the graphs presented in
Figure 12, the operating durations of the devices, and the corresponding power consumed during these periods, are demonstrated. The measurements obtained facilitated the identification of the energy consumption patterns exhibited by the devices.
Table 5.
Power measurements and error percentages
Table 5.
Power measurements and error percentages
| Device |
Development Device |
Etalon Device |
Percentage Errors
|
| V |
I |
cos |
P |
V |
I |
cos |
P |
| Refrigerator |
227.2 |
1.692 |
0.459 |
176.45 |
227.0 |
1.685 |
0.455 |
174.04 |
1.39% |
| Oven |
224.2 |
9.486 |
1.000 |
2,126.76 |
223.2 |
9.446 |
0.999 |
2,106.24 |
0.97% |
| Dishes M. |
220.2 |
8.704 |
0.999 |
1,914.70 |
220.0 |
8.600 |
0.999 |
1,890.11 |
1.30% |
| Water Heat. |
219.2 |
8.710 |
1.000 |
1,909.23 |
219.0 |
8.670 |
1.000 |
1,898.73 |
0.55% |
| Washing M. |
219.9 |
9.320 |
0.935 |
1,916.25 |
220.8 |
9.390 |
0.944 |
1,957.21 |
-2.09% |
| Dryer M. |
224.7 |
3.446 |
0.988 |
765.02 |
224.5 |
3.426 |
0.988 |
759.91 |
0.67% |
| Television |
227.8 |
0.283 |
0.887 |
57.16 |
228.4 |
0.289 |
0.902 |
59.54 |
-3.99% |
| Laptop |
227.3 |
0.405 |
0.916 |
84.41 |
227.5 |
0.414 |
0.934 |
87.97 |
-4.05% |
| Vacuum C. |
224.6 |
5.865 |
0.967 |
1,273.81 |
222.5 |
5.840 |
0.967 |
1,256.52 |
1.38% |
| Iron |
222.8 |
8.543 |
1.000 |
1,903.38 |
222.2 |
8.505 |
1.000 |
1,889.81 |
0.72% |
| Mean Absolute Percentage Error (MAPE) |
1.71% |
The calculation of MAPE is as follows:
Where is the number of data points, is the reference value, is the measured value, and multiplying by 100 expresses the error as a percentage.
All measurements were conducted at ambient temperature, with temperature and humidity values recorded throughout the process. The mean temperature was 24.13°C, and the mean relative humidity was 62.04%. Appliances with program-based operation, including dishwashers, washing machines, and dryers, were monitored until the completion of their respective programs. The kettle was operated for a period of 5–6 minutes, after which measurements were taken. For devices operating on a continuous basis, such as refrigerators, measurements were recorded over a 120-minute period. The oven was operated for a period of 20 minutes in order to obtain the required measurements. For devices that are used intermittently, such as the television, laptop, and vacuum cleaner, measurements were conducted over a period of 15 minutes. The iron, which exhibits irregular starting and stopping behaviour, necessitated a sampling interval of 10 seconds as opposed to the standard 1-minute interval, in order to accurately capture its operational characteristics. A total of 15 consecutive measurements were analysed. It was demonstrated that power consumption increased by approximately 13 W when the refrigerator door was opened, due to the activation of interior lighting. This increase in power consumption was observed to be consistent over a period of 120 minutes. The duration of the drying process is influenced by the load size; nevertheless, subsequent to the conclusion of the drying process, the appliance continues to operate at a low power setting until the program duration is complete. It was observed that the laptop consumed a greater quantity of power than the television. This was due to the laptop’s high-power charging adapter, which enabled faster charging.