Building a Smart Power Meter with ESP8266

Building a Power Meter using ESP8266 and INA226 Current Sensor

In this article, we will explore the process of building a power meter using an ESP8266 microcontroller and an INA226 current sensor. This project allows for the measurement of current up to 100A and voltage up to 100VDC, as well as temperature and humidity readings.

Hardware Requirements

  • ESP8266 microcontroller (VMOS D1 mini)
  • INA226 current sensor
  • DHT11 temperature and humidity sensor
  • 0.96 inch OLED display
  • SMD resistors and capacitors
  • Female headers
  • 100 amp shunt

Software Requirements

The code for this project was built using ESP Home, a popular framework for building IoT projects. The code is available in the description below and can be flashed onto the ESP8266 microcontroller.

Project Overview

This project allows for the measurement of current up to 100A and voltage up to 100VDC, as well as temperature and humidity readings. The INA226 current sensor is capable of measuring negative current, making it suitable for a wide range of applications.

The power meter also features a 0.96 inch OLED display, which shows the measured values in real-time. The project can be integrated with Home Assistant, allowing users to view the readings wirelessly.

PCB Design and Manufacturing

The PCB design for this project was created using a CAD software and converted into Gerber files. The files were then uploaded to JLCPCV, a popular online PCB manufacturing service.

JLCPCV offers a convenient and cost-effective way to manufacture PCBs in small quantities. The service allows users to select the quantity of PCBs they want to order, with higher quantities resulting in lower prices per unit.

Assembly and Testing

Once the PCBs arrived, the components were assembled onto the board. The code was then flashed onto the ESP8266 microcontroller, and the power meter was tested to ensure that it was working as expected.

Potential Applications

This power meter can be used in a wide range of applications, including capacity testing of lithium-ion phosphate batteries. The ability to measure negative current makes it suitable for use with batteries that have a built-in battery management system (BMS).

Additionally, the power meter's compact size and wireless connectivity make it an ideal solution for IoT projects where space is limited.

Future Improvements

This project is still in its early stages, and there are many potential improvements that can be made. Some possible areas for improvement include:

  • Adding more sensors to measure additional parameters such as temperature and humidity
  • Improving the user interface to make it easier to use and understand
  • Increasing the accuracy of the measurements

Conclusion

This project demonstrates the potential for building a compact and accurate power meter using an ESP8266 microcontroller and an INA226 current sensor. With its ability to measure negative current and integrate with Home Assistant, this power meter is suitable for use in a wide range of applications.



Power Meter A power meter is an electronic device used to measure various electrical parameters such as voltage, current, power, and energy consumption in a circuit or system.
Background The concept of measuring power dates back to the early days of electricity. As the use of electricity became widespread, the need for accurate measurement of electrical parameters grew. In the late 19th and early 20th centuries, mechanical meters were used to measure energy consumption. However, these meters had limitations in terms of accuracy and reliability.
Evolution The development of electronic power meters began in the mid-20th century with the introduction of analog devices that used thermocouples or electrodynamic principles to measure power. The advent of digital technology led to the creation of more accurate and reliable digital power meters, which have become ubiquitous in various industries and applications.
Types Power meters can be classified into several types based on their functionality and application. These include:
    Analog Power Meters Use analog circuits to measure electrical parameters.
    Digital Power Meters Utilize digital signal processing to provide accurate measurements and additional features such as data logging and communication interfaces.
    Multifunction Power Meters Capture a range of electrical parameters, including voltage, current, power factor, and energy consumption.
Applications Power meters are used in various industries and applications, including:
    Industrial Automation To monitor and control electrical systems in manufacturing processes.
    Energy Management To track energy consumption and optimize usage in commercial buildings, data centers, and residential areas.
    Medical Equipment To ensure precise power delivery to medical devices, such as defibrillators and ventilators.


Building a Smart Power Meter with ESP8266

In this article, we will explore how to build a smart power meter using the popular ESP8266 microcontroller. The smart power meter will be able to measure and monitor the electrical power consumption of a household or office in real-time, and send the data to a cloud server for further analysis and visualization.

Components Required

  • ESP8266 microcontroller (e.g. NodeMCU board)
  • Current Transformer (CT) sensor
  • Voltage Sensor (e.g. ZMPT101B)
  • Breadboard and jumper wires
  • Power supply (e.g. USB cable)

Circuit Diagram

Circuit Diagram

The circuit diagram shows the connections between the ESP8266, CT sensor, voltage sensor, and power supply. The CT sensor is connected to the current-carrying wire of the electrical circuit being monitored. The voltage sensor is connected across the voltage terminals of the electrical circuit.

Software Components

  • Arduino IDE (for programming the ESP8266)
  • ESP8266 library (for WiFi and HTTP communication)
  • ThingSpeak library (for cloud data logging)

Programming the ESP8266

The ESP8266 is programmed using the Arduino IDE. The program reads the current and voltage values from the sensors, calculates the power consumption, and sends the data to a ThingSpeak channel for cloud logging.

        // Import libraries
        #include <WiFi.h>
        #include <ThingSpeak.h>

        // Define constants
        const char* ssid = "your_wifi_ssid";
        const char* password = "your_wifi_password";

        // Initialize variables
        float current, voltage, power;

        void setup() {
          Serial.begin(115200);
          WiFi.begin(ssid, password);
          while (WiFi.status() != WL_CONNECTED) {
            delay(1000);
            Serial.println("Connecting to WiFi...");
          }
          Serial.println("Connected to WiFi");
          ThingSpeak.begin(WiFi.client);
        }

        void loop() {
          // Read current and voltage values
          current = analogRead(A0);
          voltage = analogRead(A1);

          // Calculate power consumption
          power = current * voltage;

          // Send data to ThingSpeak channel
          ThingSpeak.setField(1, power);
          ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
          delay(10000); // Wait 10 seconds before sending next reading
        }
      

ThingSpeak Configuration

Create a new ThingSpeak channel and configure it to receive data from the ESP8266. You will need to create an API key for writing data to the channel.

Conclusion

In this article, we have shown how to build a smart power meter using the ESP8266 microcontroller. The system measures current and voltage values from sensors and sends the calculated power consumption data to a ThingSpeak channel for cloud logging.



Q1: What is a smart power meter? A smart power meter is an advanced metering device that measures and records electricity usage in real-time, providing detailed insights into energy consumption patterns.
Q2: What is ESP8266? ESP8266 is a low-cost, Wi-Fi enabled microcontroller board that can be used to build IoT (Internet of Things) projects, including smart power meters.
Q3: What are the advantages of building a smart power meter with ESP8266? The advantages include low cost, ease of use, Wi-Fi connectivity for remote monitoring and control, and the ability to measure energy usage in real-time.
Q4: What are the components required to build a smart power meter with ESP8266? The components include an ESP8266 board, a current transformer (CT) sensor, a voltage sensor, a relay module, and a breadboard or PCB for connecting the components.
Q5: How does the smart power meter measure energy usage? The smart power meter measures energy usage by using the CT sensor to measure current flow and the voltage sensor to measure voltage, then calculating the power consumption using the measured values.
Q6: Can the smart power meter be controlled remotely? Yes, the smart power meter can be controlled remotely using a mobile app or web interface, allowing users to monitor and control energy usage in real-time.
Q7: What is the role of the relay module in the smart power meter? The relay module acts as an electrical switch that can be controlled by the ESP8266 board, allowing users to remotely turn appliances on or off.
Q8: Can the smart power meter measure energy usage for multiple appliances?
Q9: What are some potential applications of a smart power meter? Potential applications include home automation, industrial energy monitoring, and grid management for utility companies.
Q10: Can the smart power meter be integrated with other IoT devices?




Rank Pioneers/Companies Description
1 Espressif Systems Developed the ESP8266, a low-cost, low-power Wi-Fi microcontroller that enables IoT applications like smart power meters.
2 Landis+Gyr A leading provider of grid management solutions, including smart meters that utilize IoT technologies like the ESP8266.
3 ABB A pioneering technology company that offers a range of IoT-enabled smart metering solutions, including those using the ESP8266.
4 Schneider Electric A global specialist in energy management and automation that develops smart power meters using IoT technologies like the ESP8266.
5 Semtech Corporation A leading supplier of high-performance analog and mixed-signal semiconductors, including those used in IoT-enabled smart power meters.
6 Texas Instruments A multinational semiconductor company that produces a range of microcontrollers, including those used in IoT-enabled smart power meters.
7 NXP Semiconductors A leading provider of secure connectivity solutions for the Internet of Things (IoT), including those used in smart power meters.
8 STMicroelectronics A global semiconductor company that produces a range of microcontrollers, sensors, and other components used in IoT-enabled smart power meters.
9 Microchip Technology A leading provider of microcontroller and analog semiconductors, including those used in IoT-enabled smart power meters.
10 ON Semiconductor A leading supplier of semiconductor-based solutions, including those used in IoT-enabled smart power meters.




Hardware Components Description
ESP8266 Module (e.g., ESP-12E) A low-cost, low-power microcontroller with Wi-Fi capabilities.
Current Transformer (CT) Sensor A non-invasive sensor to measure current flowing through a wire.
Voltage Sensor (e.g., ACS712) A module to measure voltage levels.
Resistive Load (e.g., 10kΩ, 1/4W) A load resistor for the CT sensor.
Breadboard and Jumper Wires For prototyping and connecting components.
Software Components Description
Arduino IDE (or compatible alternatives) A development environment for programming the ESP8266.
ESP8266 Board Package (e.g., Arduino ESP8266 package) A software package to support the ESP8266 board in the Arduino IDE.
WiFi Library (e.g., WiFiManager) A library for managing Wi-Fi connections and configurations.
MQTT Library (optional, e.g., PubSubClient) A lightweight messaging protocol library for IoT applications.
Circuit Connections Description
CT Sensor → ESP8266 (A0 pin) Connect the CT sensor's output to an analog input pin on the ESP8266.
Voltage Sensor → ESP8266 (A1 pin) Connect the voltage sensor's output to an analog input pin on the ESP8266.
Resistive Load → CT Sensor Connect the load resistor in series with the CT sensor.
ESP8266 (VIN pin) → Power Source Connect a power source (e.g., USB, battery) to the VIN pin on the ESP8266.
Calibration and Configuration Description
CT Sensor Calibration Calibrate the CT sensor using a known current source and measure the output voltage.
Voltage Sensor Calibration Calibrate the voltage sensor by applying a known voltage and measuring the output voltage.
ESP8266 Configuration Configure the ESP8266 with Wi-Fi credentials, MQTT settings (if using), and other relevant parameters.
Code Snippets Description
`const int ctSensorPin = A0;` Define the CT sensor pin as an integer variable.
`const int voltageSensorPin = A1;` Define the voltage sensor pin as an integer variable.
`int ctReading = analogRead(ctSensorPin);` Read the CT sensor value using the `analogRead()` function.
`float voltageReading = (voltageSensorPin * 5.0) / 1024.0;` Calculate the voltage reading from the analog input pin.
`WiFi.begin(ssid, password);` Establish a Wi-Fi connection using the `WiFi.begin()` function.
Data Processing and Transmission Description
Current Calculation Calculate the current flowing through the wire using the CT sensor reading.
Voltage Calculation Calculate the voltage level using the voltage sensor reading.
Power Consumption Calculation Calculate the power consumption by multiplying current and voltage values.
MQTT Publishing (if using) Publish data to an MQTT broker for remote monitoring or logging.
Data Logging Store data in a local log file or database for historical analysis.
Note: The above tables provide a general outline of the technical details involved in building a smart power meter using an ESP8266. However, this is not an exhaustive list and may require modifications based on specific requirements and hardware configurations.