Home / Home made Projects / Arduino Projects / Arduino based energy monitor with Emonlib library

Arduino based energy monitor with Emonlib library

In this article we will discuss the design of Arduino based energy monitor. How to use readily available emonLib library in energy monitor. Which components are used in Arduino based energy monitor. Schematic diagram, simulation results and code are also explained in this article.

Introduction

Energy monitoring is a technique which can be used to figure out how much energy a device, a residence or an office is consuming. It’s a very useful method to keep the track of the power consumed by the appliances at any place. It can be used to find out the capacity of the things being operated and can help to find optimal solutions to consume electrical energy in a much more efficient way. It is being said the:

“You can’t manage what you don’t measure!”

What is an energy monitor?

It’s a device used to monitor the various parameters of the electrical energy being consumed at residences or offices. It is not required to connect different expensive meters to measure the how much electoral energy is consumed by device or in a building. A single energy monitor can provide all the valuable information which can help to monitor the energy consumption. The quantities which are shown by energy monitor are real power, apparent power, power factor, the supplied voltage and the current.

Modeling of CT in Proteus

In order to use the energy for high power circuits, Current transformer must be used between energy monitor and circuit. CT is of the components which can vary the reading of simulation from actual reading is the Current Transformer (CT). Because it has the burden which can alter the current being sensed. CT is not provided in Proteus library , therefore in the following section the simulation of CT is being explained in detail which would help to reduce the error between actual reading and simulation.

interfacing CT with arduino based energy monitor

Calculating a suitable burden resistor size

If it is a voltage output CT you can skip this step and leave out the burden resistor, as the burden resistor is built into the CT.

1) Choose the current range you want to measure

2) Convert maximum RMS current to peak-current by multiplying by √2.

Primary peak-current = RMS current × √2 = 100 A × 1.414 = 141.4A

3) Divide the peak-current by the number of turns in the CT to give the peak-current in the secondary coil.

Suppose the CT has 2000 turns, so the secondary peak current will be:

Secondary peak-current = Primary peak-current / no. of turns = 141.4 A / 2000 = 0.0707A

4) To maximize measurement resolution, the voltage across the burden resistor at peak-current should be equal to one-half of the Arduino analog reference voltage. (AREF / 2)

If you’re using an Arduino running at 5V: AREF / 2 will be 2.5 Volts. So the ideal burden resistance will be:

Ideal burden resistance = (AREF/2) / Secondary peak-current = 2.5 V / 0.0707 A = 35.4 Ω

35 Ω is not a common resistor value. The nearest values either side of 35 Ω are 39 and 33 Ω. Always choose the smaller value, or the maximum load current will create a voltage higher than AREF.

Here are the same calculations a compact form:

Burden Resistor (ohms) = (AREF * CT TURNS) / (2√2 * max primary current)

Note: Calculations have been provided here courtesy of openenergymonitor.org

Interfacing AC-AC adaptor with Arduino:interfacing PT with arduino based energy monitor

Schematic

Following components are used to construct Arduino based energy monitor

  • LCD (16×4)
  • Arduino (UNO R3)
  • Current transformer, CT (for high current circuits)
  • potential transformer PT (for high voltage circuits)
  • Power supply.
  • Capacitor

Above components are connected as shown.

schematic of arduino based energy monitor

Analogue inputs of Arduino only works with positive voltage while the actual singal oscillates around zero between positive and neagitve values. So to enable Arduino to read normal 5V analogue signal, a biasing arrangement is required which can add 2.5V DC to the signal. This arrangement consists of two resistors of 470kΩ and a capacitor of 10uF. Two resistors serve as a voltage divider to add 2.5V DC to the input while capacitor provides low impedance for high frequency components

To display the readings of Arduino based energy monitor, LCD is interfaced with Arduino. To view results on PC screen, data can be sent to PC via USB port using serial communication.

Transformer (TR2) symbolizes CT and TR1 indicating PT.  To accommodate the burden of CT, 1.5Ω resistance is connected across transformer. Voltage of circuit is given to TR2 while current will be given to TR1.  To enable the deivce to be used in high voltage high current circuits, current and voltages need to be stepped down. So the voltage stepdown ratio of PT (TR1) is 0.05 while that of CT (TR2) is 0.006. The settings of both transformers are shown in the following figures.

CT and PT settings

Simulation Results:

To test the working of Arduino based energy monitor, it is simulated in ISIS Proteus with different input voltages and currents. To verify our results, voltmeter, ammeter and two wattmeter are connected with the inputs. The values displayed by Arduino based energy monitor on LCD screen can be cross checked with the values displayed by the meters connected.

Initially in phase current and voltages are applied and the result is shown in the figure. In phase current and voltage means implies to the resistive load in real situations.

arduino based energy monitor results 1

It can be seen that all the values shown by energy monitor are almost equal to the values shown by the meters. The slight difference in current is due to the burden on CT.

The power factor shown by energy monitor is 1. From the ratios of power, the power factor can be calculated as

p.f = cos(Φ) = KW/KVA  = 0.31/0.31 = 1

So the value of monitor is verified by the values of the wattmeters.

Now to simulate for the inductive load, a time delay must be given to the current. For 30ᵒ phase delay, a time of 0.0016 is entered in current source settings as shown.

inductive load settings

The simulation result is shown

arduino based energy monitor results 2

To verify the power factor, the same method mentioned as above can be used.

p.f = cos(Φ) = KW/KVA  = 0.27/0.31 = 0.87

The value shown by monitor is 0.86 so it verifies our results.

Code 

Arduino based energy monitor uses “emonLib library” which is freely available at OpenEnergyMonitor.org. Library can be downloaded from the following link

https://github.com/openenergymonitor/EmonLib

#include “EmonLib.h” // Include Emon Library
EnergyMonitor emon1; // Create an instance
// include LCD the library:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
  Serial.begin(9600);   // set up the LCD’s number of columns and rows:
  lcd.begin(20, 4);
  emon1.voltage(2, 234.26, 1.7); // Voltage: input pin, calibration, phase_shift
  emon1.current(1, 111.1); // Current: input pin, calibration.
}
void loop()
{
  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)
    unsigned int long timemillis=millis(); //keeping the track of the time since the device is switched ON
  unsigned int long time=timemillis/1000;
   float realPower       = emon1.realPower; //extract Real Power into variable
  float apparentPower   = emon1.apparentPower; //extract Apparent Power into variable
  float powe//extract Apparent Power into variable rFactor     = emon1.powerFactor; //extract Power Factor into Variable
  float supplyVoltage   = emon1.Vrms; //extract Irms into Variable
  float Irms            = emon1.Irms;
//displaying the values
lcd.setCursor(4,0);
lcd.print(“Energy Monitor”);
lcd.setCursor(0,1);
lcd.print(“V=”);
lcd.print(supplyVoltage);
lcd.setCursor(9,1);
lcd.print(“I=”);
lcd.print(Irms);
lcd.setCursor(0,2);
lcd.print(“Power factor=”);
lcd.print(powerFactor);
lcd.setCursor(0,3);
lcd.print(“Units(kWh)=”);
lcd.print(abs(realPower*time)/abs(1000*3600));
}

If you have any questions please ask in comments. Share with your friends if you like it.

About Harris Fayyaz

Muhammed Harris Fayyaz, electrical engineer from NUST, EME, has 2.5 yrs industrial experience. He does research work in control systems, micro controllers and their applications.

Check Also

Arduino based power meter using Emon Library

This article assist the user to construct home made Arduino based power meter. The connection …

27 comments

  1. Hello there, that’s a cool project! But I have some problems, I can’t compile the above codes correctly in Arduino Software with Emonlib.h … could you send me the Arduino UNO correct codes for this project?
    or please send me the .ino file of this project?? I need that please send to my email: paddesky@live.com

    Regards

    • Oh! I still waiting for your keen response!
      Please send me a working .ino file of this project? Or full compiled codes! *** EMERGENCY ***

      • This is my Arduino Software Error code: (Please send me the working .ino code)
        Your Solution???

        Arduino: 1.6.7 (Windows 7), Board: “Arduino/Genuino Uno”

        C:\Program Files\Arduino\arduino-builder -dump-prefs -logger=machine -hardware “C:\Program Files\Arduino\hardware” -tools “C:\Program Files\Arduino\tools-builder” -tools “C:\Program Files\Arduino\hardware\tools\avr” -built-in-libraries “C:\Program Files\Arduino\libraries” -libraries “C:\Users\Novin Pendar\Documents\Arduino\libraries” -fqbn=arduino:avr:uno -ide-version=10607 -build-path “C:\Users\NOVINP~1\AppData\Local\Temp\buildb58985ad23b5c9ec59f937e1a697e066.tmp” -warnings=none -prefs=build.warn_data_percentage=75 -verbose “C:\Users\Novin Pendar\Documents\Arduino\vdd\vdd.ino”
        C:\Program Files\Arduino\arduino-builder -compile -logger=machine -hardware “C:\Program Files\Arduino\hardware” -tools “C:\Program Files\Arduino\tools-builder” -tools “C:\Program Files\Arduino\hardware\tools\avr” -built-in-libraries “C:\Program Files\Arduino\libraries” -libraries “C:\Users\Novin Pendar\Documents\Arduino\libraries” -fqbn=arduino:avr:uno -ide-version=10607 -build-path “C:\Users\NOVINP~1\AppData\Local\Temp\buildb58985ad23b5c9ec59f937e1a697e066.tmp” -warnings=none -prefs=build.warn_data_percentage=75 -verbose “C:\Users\Novin Pendar\Documents\Arduino\vdd\vdd.ino”
        “C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino” “-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard” “C:\Users\NOVINP~1\AppData\Local\Temp\buildb58985ad23b5c9ec59f937e1a697e066.tmp\sketch\vdd.ino.cpp” -o “nul”
        “C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino” “-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard” “-IC:\Program Files\Arduino\libraries\LiquidCrystal\src” “C:\Users\NOVINP~1\AppData\Local\Temp\buildb58985ad23b5c9ec59f937e1a697e066.tmp\sketch\vdd.ino.cpp” -o “nul”
        “C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino” “-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard” “-IC:\Program Files\Arduino\libraries\LiquidCrystal\src” “C:\Program Files\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.cpp” -o “nul”
        “C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino” “-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard” “-IC:\Program Files\Arduino\libraries\LiquidCrystal\src” “C:\Users\NOVINP~1\AppData\Local\Temp\buildb58985ad23b5c9ec59f937e1a697e066.tmp\sketch\vdd.ino.cpp” -o “nul”
        “C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino” “-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard” “-IC:\Program Files\Arduino\libraries\LiquidCrystal\src” “C:\Users\NOVINP~1\AppData\Local\Temp\buildb58985ad23b5c9ec59f937e1a697e066.tmp\sketch\vdd.ino.cpp” -o “C:\Users\NOVINP~1\AppData\Local\Temp\buildb58985ad23b5c9ec59f937e1a697e066.tmp\preproc\ctags_target_for_gcc_minus_e.cpp”
        vdd:1: error: #include expects “FILENAME” or

        #include “EmonLib.hâ€‌ // Include Emon Library

        ^

        Using library LiquidCrystal at version 1.0.4 in folder: C:\Program Files\Arduino\libraries\LiquidCrystal
        exit status 1
        #include expects “FILENAME” or

  2. Set your cursor position using lcd.setcursor() Count your number of characters on lcd like 4×20 means 20 characters can be displayed using 4 rows! Set the positions accordingly!

  3. Dear friend how to change pages in a 16*2 LCD?
    if I have just the 16*2 LCD what should I do to change display LCD with a push bottom??
    what codes?

    thanks

  4. i am getting invalid opcode error while simulating this code in proteus .. what should i do? please tell me fast.. thnks .

    • Muhammad Kamran

      The reason of invalid upcode error is , that you have selected incorrect board in Arduino IDE,,,,,, go to the tools menu in Arduino IDE and select Arduino UNO board from Board item….. if you are using UNO otherwise select that one which you are using.

  5. Buenas Tardes
    Como añadió la biblioteca emonlib.n a proteus? quiero compilar pero salta el error “emonlib.h no such file or directory”
    desde ya muchas gracias.
    saludos

  6. PROBLEM SOLVED

  7. How to place in Proteus the current source in front CT? Thanks

  8. its showing an error “stray “\” in program”. I did a ctrl+F to find it in the program but there is no backward slash in the program anywhere. How do I overcome this?

  9. I managed to compile the code but I’m getting different values for my simulation. V=180, I=85.61.. does anyone have a similar problem?

  10. Hi,
    Is this measuring AC or DC current, sorry I am new

    thanks,

  11. where do you find the KVA and W meters in proteus

Leave a Reply

Your email address will not be published. Required fields are marked *

*