Power Meter – LCD and Arduino based

Power Meter – LCD and Arduino based.


Power Meter

After recently reading Emon’s webpage on monitoring power consumption with a VT, CT an and arduino, I quickly bread-boarded their recommended circuit. Seen HERE.

You need an AC plug pack and a clip on CT. The AC plugpack gives us a directly proportional voltage to the AC mains voltage.  The CT gives us a voltage directly proportional to the AC mains current.

CT

It seemed to work well so I transferred it to a prototyping shield and added an LCD keypad on top.  The code can measure Voltage, current, power factor, resistive power and reactive power.

It’s done by using the fantastic emon library which does all the heavy lifting. Making it possible to do away with rectifying the AC signal and giving us all the calculated values straight to variables.

In the setup these 2 lines initialise everything:

emon1.voltage(3, 225, 1); // Voltage: input pin, calibration, phase_shift
emon1.current(2, 0.3); // Current: input pin, calibration.

Later in the code each variable can be pulled out to use with this code:

emon1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
emon1.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)

float realPower = emon1.realPower; //extract Real Power into variable
float apparentPower = emon1.apparentPower; //extract Apparent Power into variable
float powerFactor = emon1.powerFactor; //extract Power Factor into Variable
float supplyVoltage = emon1.Vrms; //extract Vrms into Variable
float Irms = emon1.Irms; //extract Irms into Variable

Things to Do

I hope to add a web page output and possibly 3 phase measurement.

This project is fantastic for learning about power factor and how each component is measured.

 

2014-04-26 14.55.36

 

2014-04-26 14.55.40

 

2014-04-26 14.55.43Power Shield

 

 

Measuring voltage and current

Measuring voltage and current

 

 

 

Here is the example code. Using the EMON library because its pretty good.

 

 

// Basic sketch for EmonWRT
// Version 1.2

#define FILTERSETTLETIME 15000 // Time (ms) to allow the filters to settle before sending data

const int CT1 = 1;
const int CT2 = 1; // Set to 0 to disable CT channel 2
const int CT3 = 1; // Set to 0 to disable CT channel 3
const int VOLT = 1; // Set to 0 to disable

const int UNO = 1; // Set to 0 if your not using the UNO bootloader (i.e using Duemilanove) – All Atmega’s shipped from OpenEnergyMonitor come with Arduino Uno bootloader
#include <avr/wdt.h>
#include <JeeLib.h> // Download JeeLib: http://github.com/jcw/jeelib
ISR(WDT_vect) { Sleepy::watchdogEvent(); } // Attached JeeLib sleep function to Atmega328 watchdog -enables MCU to be put into sleep mode inbetween readings to reduce power consumption
#include “EmonLib.h”
EnergyMonitor ct1,ct2,ct3; // Create instances for each CT channel
float power1, power2, power3;
float voltage;
const int LEDpin = 9; // On-board emonTx LED

boolean settled = false;
boolean firstsensor = true; // Just to know if a , must be added in the CSV output

void setup()
{
delay(10000);

Serial.begin(9600);
Serial.println(“emonWRT CT123 and Voltage v1.2”);
pinMode(LEDpin, OUTPUT); // Setup indicator LED
digitalWrite(LEDpin, HIGH);

if (UNO) wdt_enable(WDTO_8S); // Enable anti crash (restart) watchdog if UNO bootloader is selected. Watchdog does not work with duemilanove bootloader // Restarts emonTx if sketch hangs for more than 8s
ct1.voltage(3, 225, 1); // Voltage: input pin, calibration, phase_shift

}

void loop()
{

power1 = ct1.Irms; //ct.calcIrms(number of wavelengths sample)*AC RMS voltage
power2 = ct2.Irms;
power3 = ct3.Irms;
voltage = ct1.Vrms; // AC Mains rms voltage

// because millis() returns to zero after 50 days !
if (!settled && millis() > FILTERSETTLETIME) settled = true;

if (settled) // send data only after filters have settled
{
digitalWrite(LEDpin, HIGH); delay(2); digitalWrite(LEDpin, LOW); // flash LED
Serial.print(“EMONWRT “);

if (CT1) {
if (!firstsensor) Serial.print(“,”);
firstsensor = false;
Serial.print(power1);
}

if (CT2) {
if (!firstsensor) Serial.print(“,”);
firstsensor = false;
Serial.print(power2);
}

if (CT3) {
if (!firstsensor) Serial.print(“,”);
firstsensor = false;
Serial.print(power3);
}

if (VOLT) {
if (!firstsensor) Serial.print(“,”);
firstsensor = false;
Serial.print(voltage);
}

firstsensor = true;

//Serial.println(” “);
Serial.println(” “);
delay(100);

Sleepy::loseSomeTime(5000); // sleep or delay in seconds – see emontx_lib
}
}

 

9 Responses

  1. Karoonjhar
    Hey Toby! Please post the circuit and code too.
    • Hi, I have appended the code I chose to use to the end of the post. There are many ways to do it, I liked the EMON library because it calculates power factor and is quick and easy. If your doing your own measurements , I just use Power calculations and display it in a way I think works well for me. At one stage I made a few that sent data from a sender to a remotely placed display. In the end now though I have gone to sending the data to the web, still using EMON to sense, through a serial to a super cheap $30 router, publishes straight to thingspeak, which gives me graphs and stuff..
  2. What lcd monitor u used and how does the connection goes?
    • I Just used an Arduino Uno Lcd keypad shield..
  3. Good day sir...1st of all I would like to say that u have a very nyc project.. I am new to arduino so I have a novice question..what is the specific board that u use in connecting the ct and vt.. is it a board or a shield..hoping for ur response.. tnx in advance
    • Hi, the emonTX s a great place to start, if you search for emonTX you will see a number of boards available, good luck!
  4. Hello Toby, On the first image where all components are put together I see that AC-AC adaptor that you've used has 15V output, not 9. I have the same adaptor, could you please tell the nominals of the resistors used? Especially R1 and R2. I have calculated those by myself (10 and 110 kOhm) but just wondering how accurate those calculations. Thanks in advance
  5. Dear Toby, thanks for the great post! Could you please provide values of the components that are used on your board. From resistor colors I see that for Voltage sensor there is 150kOm R2 divider resistor used and R1 is 10kOm. Capacitor is 330uf instead of 10. Not sure if I see these values correctly, please respond! Thanks in advance!
    • Hi there is a link in post to the schematic, here it is though. https://openenergymonitor.org/forum-archive/node/58.html

Leave a comment