// Emon (Energy Monitor) Library
#include "EmonLib.h"
// CONSTANTS
// Anslog current senson is connected to GPIO 34 (Analog ADC1_CH6)
const int currentPin = 34;
// Standart RMS voltage
const double Vrms = 220.0;
// Current sensor calibration, iCalibration is the current that gives 1V at the ADC input
const double iCalibration = 111.1;
// Number of current samples
const int iSamples = 1480;
// INITIALIZATION
// EnergyMonitor instance
EnergyMonitor energyMonitor;
// variable for storing the RMS current value
double Irms = 0.0;
// variable for storing the RMS Power usage
double Prms = 0.0;
void setup() {
// Setup code here, run once
Serial.begin(9600);
// Setup EnergyMonitor
energyMonitor.current(currentPin, iCalibration);
}
void loop() {
// main code here, run repeatedly
// Calculate RMS current
Irms = energyMonitor.calcIrms(iSamples);
// Calculate RMS Power usage
Prms = Irms*Vrms;
Serial.print("Instant power usage: ");
Serial.print(Prms);
Serial.println(" W");
// Update delay
delay(100);
}