Skip to content

Power Meter

Rui Pires edited this page Jan 31, 2021 · 1 revision

The objective is to measure power, power factor and display in a web page.

1 - Measure current with a clamp

#include <ESP8266WiFi.h>
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance

void setup()
{
Serial.begin(9600);
emon1.current(A0, 111.1); // Current: input pin, calibration.
}

void loop()
{
double Irms = emon1.calcIrms(1480); // Calculate Irms only
Serial.print(Irms*230.0); // Apparent power
Serial.print(" ");
Serial.println(Irms); // Irms
}

2 - Calibrate

The code indeed proposes a parameter for that.
I used the PZEM-022 that I already have in my mains.
I will report for now in VA, estimating the potential to be 230. This is the apparent power.
I will later measure the potential and the Power Factor.
So, i changed the line in the code to:
emon1.current(A0, 97); // Current: input pin, calibration.

3 - Send to MQTT

USed some old examples, and collecting for now in my mobile in the app MQTT Dash. Code here: power_meter_v0.ino

4 - Log data

I am already doing that for other data, so hopefully not to difficult. ongoing 26 Jan

4.1 - calculate averages

plan...

4.2 - include in the web

plan

5 - Measure potential

plan...

5.1 - Log data

5.2 - calculate averages

5.3 - include in the web

#6 - Measure Power factor plan...

5.1 - Log data

5.2 - calculate averages

5.3 - include in the web