AC Power Meter Using a Microcontroller (ESP-32)
by fahadqalbi in Circuits > Arduino
3526 Views, 1 Favorites, 0 Comments
AC Power Meter Using a Microcontroller (ESP-32)
In this project i made an AC-power meter using a microcontroller and displayed it on a 16*2 LCD, For the coding i used the emon.lib library in arduino IDE. This library has formulas for power measurements already defined, one can use the calibration factor to fine tune output values of AC current and voltage. there is a ccp file or txt file included to understand emon.lib library also a project report that can be used to understand whats happening.
Supplies
ESP32 Module:
It is a versatile, feature-packed development board
produced by Espressif that is designed around their powerful ESP32 system on
a chip (SoC). The ESP32 is a powerful dual-core microcontroller with
integrated Wi-Fi and Bluetooth capabilities, making it suitable for a wide range
of applications from simple prototyping to complex IoT deployments.
ZMPT101B module:
It is a voltage transformer ideal for measuring AC
voltage. It can transform the AC signal into a smaller amplitude signal.
ZHT103 module:
Is a current sensor module that can be used to measure
AC current.
16x2 LCD display:
In this project, I also used a 16x2 LCD display, which is an alphanumeric
display that can show up to 32 characters in two lines (16 characters each). It is
connected to the ESP32 using an I2C module, a simple, reliable communication
protocol, allowing the LCD to receive data from the ESP32 over just two wires.
The I2C bus uses two lines: a serial data line (SDA) and a serial clock line
(SCL). SCL stands for Serial Clock. It's one of the two signals used in the I2C
communication protocol, the other being the Serial Data (SDA) line. In I2C
communication, the SCL line is used to synchronize all data transfers over the
I2C bus. It's controlled by the master device, which generates the clock signal.
Emon Library:
The Emon library is used. This library has been designed to make energy
monitoring easier by providing calibration and phase correction for AC power
measurements. The library calculates real power, apparent power, power factor,
Vrms, and Irms.
LiquidCrystal_I2C Library:
The LiquidCrystal_I2C library is used to control the LCD display via I2C
communication. This allows us to write to the display and control the backlight
and cursor position, among other things.
Coding in Audrino IDE
Here is the code that i wrote. You can download EmonLibrary in Audrino IDE.
// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3
#include <LiquidCrystal_I2C.h>
#include "EmonLib.h" // Include Emon Library
int lcdColumns = 16;
int lcdRows = 2;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
EnergyMonitor emon1; // Create an instance
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.cursor_off();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("AC Power Meter");
delay(1000);
emon1.voltage(35,366, 0);
emon1.current(34, 1.100999); // Current: input pin, calibration.
lcd.clear();
}
void loop() {
lcd.print("Sequence: I+V,P");
emon1.calcVI(20, 2000);
double Vrms = emon1.Vrms;
double Irms = emon1.calcIrms(2000); // Calculate Irms only
float watt=(Irms*Vrms);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Vrms:");
lcd.setCursor(6,0);
lcd.print(Vrms);
lcd.setCursor(14,0);
lcd.print("V");
Serial.print(Vrms);
Serial.print(" V, ");
lcd.setCursor(0,1);
lcd.print("Irms:");
lcd.setCursor(6,1);
lcd.print(Irms);
lcd.setCursor(11,1);
lcd.print("A");
Serial.print(Irms);
Serial.println(" A, ");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Power:");
lcd.setCursor(8,0);
lcd.print(watt);
lcd.setCursor(15, 0);
lcd.print("W");
delay(1000);
lcd.clear();
}
Component Interconnections
As shown in the picture above, the ZMPT101B module is
connected to the ESP32 to measure the AC voltage.
The ZHT103 module is also connected to the ESP32 to measure AC
current.
The LCD display module is connected to the ESP32 using an I2C
module, allowing it to display voltage, current, and power readings.
The code handles the interaction between these components, collecting
measurements from the voltage and current sensors and outputting the results to
the LCD display.
Here is a link for files of this project:
https://github.com/fahadqalbi/AC-power-meter-using-a-microcontroller-ESP-32