ESP8266 AC Power Meter with Relay Control
Building an AC Power Meter with ESP8266 and HLW8012 |
In this article, we will explore the process of building an AC power meter using two relays, ESP8266, and HLW8012 AC power monitoring IC. This project can measure current up to 40 amps and voltage up to 280 volts AC, making it suitable for high-current demanding applications. |
Overview of the Project |
The project utilizes two 30-amp relays that can be individually controlled. The circuit is not isolated, so it's essential to exercise caution and avoid touching it while it's connected to mains voltage. This power meter can be integrated with home assistant devices, allowing for wireless monitoring. |
Designing the PCB |
The project began with designing the semantics and converting them into Gerber files. The Gerber files were then used to create a printed circuit board (PCB) using JLCPCB's assembly service. This process made it easy to order the PCBs in various quantities, with discounts available for larger orders. |
Assembling the Components |
After receiving the PCBs, the components were gathered and soldered onto the board. It's crucial to apply extra thick solder to specific pads to ensure a secure connection. |
Flashing the Code |
The code was flashed onto the ESP8266, and the power meter was tested using a heat gun as a load. The results showed that the device was working as expected. |
Bill of Materials (BOM) and Circuit Diagram |
A comprehensive list of parts, along with purchasing links and a circuit diagram, is available for reference. This information will be invaluable in replicating the project. |
Improvements and Future Development |
This project is considered the first version, and there are many areas that can be improved upon. Suggestions and ideas for future development are welcome. |
Purchasing Information |
For those interested in purchasing the power meter or other products, please contact via Instagram (link provided below). |
Conclusion |
This article has provided a comprehensive overview of building an AC power meter using ESP8266 and HLW8012. With its ability to measure high currents and voltages, this project is ideal for various applications, including integration with home assistant devices. |
Power Meter |
A power meter is an instrument used to measure and display the amount of electrical power being consumed by a device or system. |
Background |
The need for accurate measurement of electrical power arose with the widespread use of electricity in industrial and domestic settings. In the late 19th century, the development of alternating current (AC) systems led to a greater demand for reliable power meters. |
History |
The first power meters were electro-mechanical devices that used spinning disks or rotating coils to measure power. The invention of the wattmeter by James Watt in the late 18th century marked an important milestone in the development of power measurement technology. |
Types |
There are several types of power meters, including: |
Digital Power Meters |
Digital power meters use electronic circuits and displays to measure and display power consumption. They offer high accuracy and ease of use. |
Analog Power Meters |
Analog power meters use mechanical or electromechanical mechanisms to display power consumption on a dial or meter face. |
Smart Power Meters |
Smart power meters are advanced digital devices that can measure and record detailed information about electrical energy usage. They often include features such as remote monitoring, data logging, and communication capabilities. |
ESP8266 AC Power Meter with Relay Control |
Introduction |
The ESP8266 is a low-cost, Wi-Fi enabled microcontroller that has gained popularity in the IoT and maker communities. In this project, we will use the ESP8266 to create an AC power meter with relay control, allowing us to measure and control AC appliances remotely. |
Hardware Components |
- ESP8266 module (e.g. NodeMCU or ESP-12E)
- AC power meter IC (e.g. HLW8012 or BL0937L)
- Relay module (e.g. 5V or 12V relay)
- Breadboard and jumper wires
|
Circuit Diagram |
The circuit diagram for this project is as follows:
- Connect the ESP8266 module to a breadboard.
- Connect the AC power meter IC to the breadboard, ensuring that the IC's VCC pin is connected to the ESP8266's 5V output.
- Connect the relay module to the breadboard, ensuring that the relay's IN pin is connected to one of the ESP8266's GPIO pins (e.g. D1).
|
Software Components |
- Arduino IDE with ESP8266 board support
- ESP8266 library for the AC power meter IC (e.g. HLW8012 or BL0937L)
- ESP8266 library for the relay module (e.g. RelayModule)
|
Code Example |
The following is an example code snippet that demonstrates how to read data from the AC power meter IC and control the relay module:
```cpp
#include
#include
#include
const int RELAY_PIN = D1; // Relay pin connected to ESP8266 GPIO pin
HLW8012 hlw8012;
RelayModule relay;
void setup() {
Serial.begin(115200);
hlw8012.begin();
relay.begin(RELAY_PIN);
}
void loop() {
float voltage, current, power;
hlw8012.getValues(voltage, current, power);
if (power > 10) { // Turn on relay if power consumption is above 10W
relay.on();
} else {
relay.off();
}
Serial.print("Voltage: ");
Serial.print(voltage);
Serial.print(", Current: ");
Serial.print(current);
Serial.print(", Power: ");
Serial.println(power);
delay(1000);
}
```
|
Working Principle |
The ESP8266 reads data from the AC power meter IC, which measures the voltage, current, and power consumption of an AC appliance. The ESP8266 then controls the relay module based on the measured values, allowing for remote control of the appliance. |
Advantages |
- Remote monitoring and control of AC appliances
- Low-cost solution using ESP8266 and relay module
- Easy to integrate with other IoT devices and platforms
|
Conclusion |
In this project, we have demonstrated how to create an AC power meter with relay control using the ESP8266. This solution provides a low-cost and easy-to-implement way to remotely monitor and control AC appliances. |
Q1: What is an ESP8266 AC Power Meter with Relay Control? |
The ESP8266 AC Power Meter with Relay Control is a device that measures the power consumption of an AC load and can control it using a relay, all controlled by an ESP8266 microcontroller. |
Q2: What are the main components of this project? |
The main components include the ESP8266 module, a current transformer (CT) sensor, a relay module, and an AC load (e.g., a light bulb or appliance). |
Q3: How does the CT sensor measure power consumption? |
The CT sensor measures the current flowing through the AC load by wrapping around the wire and detecting the magnetic field. This value is then converted to a voltage signal, which is read by the ESP8266. |
Q4: What is the purpose of the relay module? |
The relay module acts as an electrically operated switch that can turn the AC load on or off based on commands from the ESP8266. |
Q5: Can I control the device remotely? |
|
Q6: What are some safety considerations when working with this project? |
Always use proper insulation and follow safety guidelines when working with AC power. Also, ensure the relay module is rated for the load's current and voltage. |
Q7: Can I integrate this device with other smart home systems? |
|
Q8: How do I calibrate the CT sensor for accurate readings? |
Calibration typically involves using a known load (e.g., a light bulb) and adjusting the CT sensor's sensitivity until the measured power consumption matches the actual value. |
Q9: Can I monitor multiple loads with this device? |
|
Q10: What is the power consumption of the ESP8266 itself? |
The ESP8266 module typically consumes around 80-120 mA when connected to Wi-Fi, but this value can vary depending on the specific configuration and usage. |
Pioneers/Companies |
Description |
1. Espressif Systems |
Developed the ESP8266 microcontroller, a key component in many AC power meter projects. |
2. Adafruit Industries |
Offers a range of ESP8266-based boards and tutorials for building IoT projects, including energy monitoring systems. |
3. SparkFun Electronics |
Provides ESP8266 modules and development boards, as well as tutorials and example projects for building AC power meters with relay control. |
4. ITEAD Studio |
Developed the Sonoff smart switch series, which uses ESP8266 and offers a range of features including energy monitoring and relay control. |
5. Shelly Company |
Offers a range of smart home devices, including AC power meters with relay control based on the ESP8266 microcontroller. |
6. OpenEnergyMonitor (OEM) |
An open-source project that provides hardware and software solutions for energy monitoring, including support for ESP8266-based devices. |
7. EmonTx |
A low-power energy monitoring system based on the ESP8266 microcontroller, designed for IoT applications. |
8. Respeaker |
A smart speaker project that uses ESP8266 and offers a range of features including energy monitoring and relay control. |
9. Tasmota |
An open-source firmware for ESP8266-based devices, offering a range of features including energy monitoring and relay control. |
10. DIY Projects with ESP8266 |
A community-driven platform that showcases various DIY projects based on the ESP8266 microcontroller, including AC power meters with relay control. |
Component |
Description |
Technical Details |
Microcontroller |
ESP8266 |
- 32-bit RISC CPU: Tensilica L106
- Operating Frequency: up to 160 MHz
- Flash Memory: 4 MB (32 Mbit)
- SRAM: 96 KB
- WiFi: IEEE 802.11 b/g/n, supports WEP/WPA/WPA2 encryption
|
Power Metering IC |
HLW8012 |
- Measures Voltage, Current, and Power (Active and Reactive)
- Input Range: 0-100V, 0-10A
- Accuracy: ±1% for voltage, current, and power measurement
- Communication Interface: I2C/SPI/UART
|
Relay Module |
5V Relay Module |
- Relay Type: Single Pole Double Throw (SPDT)
- Control Voltage: 5V DC
- Switching Current: up to 10A
- Isolation Voltage: 2500Vrms
|
Power Supply |
AC-DC Switch Mode Power Supply |
- Input Range: 85-265V AC, 50/60 Hz
- Output Voltage: 5V DC
- Output Current: up to 1A
- Efficiency: ≥80%
|
Sensing and Control |
Current Transformer (CT) and Voltage Sensor |
- CT Ratio: 1000:1
- Voltage Sensor Range: 0-250V AC
- Sensing Accuracy: ±1% for voltage, current measurement
- Control Interface: I2C/SPI/UART
|
Communication Interface |
WiFi and Web Server |
- Protocols: HTTP, HTTPS, FTP, MQTT, etc.
- Web Server: supports static web pages and dynamic data exchange
- Remote Monitoring and Control through Mobile App or Web Interface
|
|