Giter VIP home page Giter VIP logo

emonlib's Introduction

                             _      _ _
                            | |    (_) |
   ___ _ __ ___   ___  _ __ | |     _| |__
  / _ \ '_ ` _ \ / _ \| '_ \| |    | | '_ \
 |  __/ | | | | | (_) | | | | |____| | |_) |
  \___|_| |_| |_|\___/|_| |_|______|_|_.__/

Arduino Energy Monitoring Library - compatible with Arduino 1.0
*****************************************************************

Designed for use with emonTx: http://openenergymonitor.org/emon/Modules

Download to Arduino IDE 'libraries' folder. Restart of IDE required.

Git Clone and Git Pull can be easily used to keep the library up-to-date and manage changes.
JeeLabs has done a good post on the topic: http://jeelabs.org/2011/12/29/out-with-the-old-in-with-the-new/



Update: 5th January 2014: Support Added for Arduino Due (ARM Cortex-M3, 12-bit ADC) by icboredman.

To enable this feature on Arduino Due, add the following statement to setup() function in main sketch:
analogReadResolution(ADC_BITS); This will set ADC_BITS to 12 (Arduino Due), EmonLib will otherwise default to 10 analogReadResolution(ADC_BITS);.
See blog post on using Arduino Due as energy monitor: http://boredomprojects.net/index.php/projects/home-energy-monitor

emonlib's People

Contributors

arnyminerz avatar dcarter avatar elwell avatar glynhudson avatar icboredman avatar ivankravets avatar proboscide99 avatar ricardojlrufino avatar ticklethepanda avatar trystanlea avatar xkr47 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emonlib's Issues

Stm8 with emon

Hi we like to measure the current using emon library and stm8 is it possible to do that if possible can u give any suggestions and links

Can I to use the "NodeMCU v2 - Lua Based ESP8266 WIFI" instead of a Arduino Due?

Sorry for my dumb questions, but I am a NOOB in this and in need of reporting watts in two directions.

Can I use a:
NodeMCU v2 - Lua Based ESP8266
http://www.communica.co.za/Catalog/Details/P0013062986

Do I just have to upload the sketch from this code: "EmonLib.cpp" using Arduino IDE software and have this board setup. - https://learn.openenergymonitor.org/electricity-monitoring/ct-sensors/how-to-build-an-arduino-energy-monitor-measuring-current-only

I am planning to send the readings to Mosquitto MQTT Broker.

Will it sense current in both directions (TO and FROM Grid) + and - Watts?

current switch

Hi.

I just by and try a SCT-013 and it work well but a wanted to use it more like a work proof than an analog probe. Some other people have wrote some issue about the weigh of thelibrary. So I wrote this little library: https://github.com/NitrofMtl/CurrentSwitch.git

So If you mind take a look and if other people want to try it test it and give me some feedback.

thanks.

Set ADC to 1.1V internal reference?

I understood that precision is issue as CT produces very small voltages. Most of arduinos have ability to set ADC to use 1.1V internal reference instead of 5V internal reference. This should make ADC more sensitive (almost 5 times). Can you please add this feature? I'd like to measure current as precisely as possible with such simple circuit. I'd like to have precision down to +-3W (1W would be awesome, 5W max)...

attiny85 and serialprint()

attiny85 has no hardware uart. EnergyMonitor::serialprint() fails to build due to dependency on Serial library.

Not a issue but a question

Hello I'm a little lost. on coding. I'm not a coder at all much. I really need help. I don't have a 33 ohms resistor for the Burden resistor i do how ever have a 30 ohms resistor. Can someone please help me to calculate it into the Current only example?

Joseph

How many veriable can use to voltage measurement?

emon1.voltage(A0, vCalibration,1,7);
emon2.voltage(A1, vCalibration,1,7);
emon3.voltage(A2, vCalibration,1,7);

How many veriable limits for use different voltage?

When I use three veriable that's work fine but when I use forth veriable then it's not work...
Example...

emon1.voltage(A0, vCalibration,1,7);
emon2.voltage(A1, vCalibration,1,7);
emon3.voltage(A2, vCalibration,1,7);
emon4.voltage(A3, vCalibration,1,7);

power factor meter

Dear
How I can change power factor meter readings from value of cos φ to arccos φ to get reading results in degree ?

#include <LiquidCrystal.h>
#include "EmonLib.h"
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
EnergyMonitor emon1, emon2;

float volt, avolt[50], sumv, volt2, avolt2[50], sumv2, powerFactor, apowerFactor[50], sumPF, catchPF, cur, acur[50], sumc;
char symbPF = 223;

void setup() {

int i;

pinMode(PA6, INPUT_ANALOG); // U1
pinMode(PA7, INPUT_ANALOG); // I2
lcd.begin(16, 2); // set up the LCD’s number of columns and rows:

emon1.voltage(PA6, 3000, 1.7); // Voltage: input pin, calibration, phase_shift U1
emon2.voltage(PA7, 3000, 1.7);
emon1.current(PA7, 111.1); // Current

Serial.begin(9600); // initialize serial communication with bit rate of 9600

}
void loop()
{
emon1.calcVI(20, 2000); // Calculate all. No.of half wavelengths (crossings), time-out
emon1.serialprint(); // Print out variable power factor)
float powerFactor = emon1.powerFactor; //extract Power Factor into Variable

sumv = 0;
sumv2 = 0;

for (int i = 0; i < 50; i++)

{
emon1.calcVI(20, 200);
emon2.calcVI(20, 200);
avolt[i] = emon1.Vrms; // holds volt value
avolt2[i] = emon2.Vrms; // holds volt value
apowerFactor[i] = emon1.powerFactor;

}

for (int i = 0; i < 50; i++)
{
sumv += avolt[i]; // LED1 AND LED2 , PB6, U1
sumv2 += avolt2[i]; // LED C13, PB7 , U3 OR DC input on PB0

}

volt = sumv / 50;
volt2 = sumv2 / 50;

lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ");

lcd.setCursor(0, 0);
lcd.print("PF=");
lcd.print(powerFactor);
lcd.print(symbPF);
lcd.setCursor(5, 0);

lcd.setCursor(0, 1);
lcd.print("U=");
lcd.print(volt);

lcd.setCursor(8, 1);
lcd.print("I=");
lcd.print(volt2);

}

Real power

I am using Arduino mega, acs current sensor, step down transformer with bias (Only positive voltage cycle.)
RMS value of current and voltage is accurate, apparent power also correct.
Real power and thus power factor are inaccurate. There may be a circuit error but deviation is too large.
Please help. Does the code have to be changed for acs current sensor ?

Arduino Wifi rev 2 compatibility

It doesnt seem like this library works with the arduino uno wifi rev 2 due to the change of the analog pin names. I get the following error:


/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp: In member function 'long int EnergyMonitor::readVcc()':
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:251:3: error: 'ADCSRA' was not declared in this scope
   ADCSRA |= _BV(ADSC);                             // Convert
   ^~~~~~
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:251:3: note: suggested alternative: 'ADC_t'
   ADCSRA |= _BV(ADSC);                             // Convert
   ^~~~~~
   ADC_t
In file included from /Users/omarsaid/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/io.h:99:0,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/pgmspace.h:90,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/String.h:30,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/Print.h:24,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/Stream.h:25,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/Client.h:22,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/ArduinoAPI.h:29,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:23,
                 from /Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.h:15,
                 from /Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:13:
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:251:17: error: 'ADSC' was not declared in this scope
   ADCSRA |= _BV(ADSC);                             // Convert
                 ^
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:251:17: note: suggested alternative: 'ADC0'
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:253:12: error: 'ADCL' was not declared in this scope
   result = ADCL;
            ^~~~
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:253:12: note: suggested alternative: 'ADC0'
   result = ADCL;
            ^~~~
            ADC0
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:254:13: error: 'ADCH' was not declared in this scope
   result |= ADCH<<8;
             ^~~~
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:254:13: note: suggested alternative: 'ADC0'
   result |= ADCH<<8;
             ^~~~
             ADC0
exit status 1
Error compiling for board Arduino Uno WiFi Rev2.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.```


Any way I can change the code to make it compatible with the arduino uno wifi rev 2? I know I need to make some changes to the "ADC" and looking online, I see that they changed the names to AIN but I am not sure exactly what to do.

3-Phase Timing and Calculation Problem

Hi All,

We try to develop a device, and according to it's working algorithm, we need to calculate L1, L2 and L3 instant voltage and current value (3-Phase energy monitoring.)

For just one line (L1), we can measure everything good. But while we try to use L2 and L3 emon object everything is blocked.

Our summarized code is : (Testing is done with Arduino Mega 2560 and Arduino Giga R1)

`#include "EmonLib.h"

//Device Energy Line 1
EnergyMonitor device_energy_line_1;
//Device Energy Line 2
EnergyMonitor device_energy_line_2;
//Device Energy Line 3
EnergyMonitor device_energy_line_3;

//
/** ENERGY MONITOR CALCULATION PARAMETERS **/
/
/
//Number of half wavelengths (crossings)
#define WAVE_LENGTHS_AMOUNT 20
#define CALCULATION_TIMEOUT 50

//
/** VOLTAGE LINE PARAMETERS **/
/
/
//Define Analog pins
#define VOLTAGE_LINE_1 A0
#define VOLTAGE_LINE_2 A1
#define VOLTAGE_LINE_3 A2

//Voltage calibration value
#define VOLTAGE_CALIBRATION_1 234.26
#define VOLTAGE_CALIBRATION_2 234.26
#define VOLTAGE_CALIBRATION_3 234.26
//Voltage phase shift value
#define VOLTAGE_PHASE_SHIFT 1.7
/*************************************************************/

/*************************************************************/
/** CURRENT PARAMETERS **/
//Define Analog pins
#define CURRENT_LINE_1 A3
#define CURRENT_LINE_2 A4
#define CURRENT_LINE_3 A5

//Phase calibration value : The phase calibration value has 2 different values. We use them because of ACS724's different reading values
#define CURRENT_CALIBRATION_1 26
#define CURRENT_CALIBRATION_2 26
#define CURRENT_CALIBRATION_3 26

void setup() {

//Device energy line 1-2-3 : Voltage
device_energy_line_1.voltage(VOLTAGE_LINE_1, VOLTAGE_CALIBRATION_1, VOLTAGE_PHASE_SHIFT);
device_energy_line_2.voltage(VOLTAGE_LINE_2, VOLTAGE_CALIBRATION_2, VOLTAGE_PHASE_SHIFT);
device_energy_line_3.voltage(VOLTAGE_LINE_3, VOLTAGE_CALIBRATION_3, VOLTAGE_PHASE_SHIFT);

//Device energy line 1-2-3 : Current
device_energy_line_1.current(CURRENT_LINE_1, CURRENT_CALIBRATION_1);
device_energy_line_2.current(CURRENT_LINE_2, CURRENT_CALIBRATION_2);
device_energy_line_3.current(CURRENT_LINE_3, CURRENT_CALIBRATION_3);
}

void loop() {

device_energy_line_1.calcVI(WAVE_LENGTHS_AMOUNT, CALCULATION_TIMEOUT);
//Test Mode : device_energy_line_1.serialprint(); //This is for printing for all data : realpower, apparent power, Vrms, Irms, power factor
device_energy_line_2.calcVI(WAVE_LENGTHS_AMOUNT, CALCULATION_TIMEOUT);
//Test Mode : device_energy_line_2.serialprint(); //This is for printing for all data : realpower, apparent power, Vrms, Irms, power factor
device_energy_line_3.calcVI(WAVE_LENGTHS_AMOUNT, CALCULATION_TIMEOUT);

/*
Rest of our codes, include millis() timing elements like momentary button value read as in 1000ms, LED animations like 100 ms, 75 ms etc. These are blocking because of emon instance's calculations.
*/

}

`

As I wrote in code block, We have some functions have own millis() measurings, button reading state, LED animations. All of them, have own millis() calculations. Without emon instances for 3-phases, all of them work good.

For testing or finding blocking thing, we deleted device_energy_line_2 and 3 instances. Just for device_energy_line_1 for example, it doesnt block anything in code.

Could you have any advices or what we do wrong for 3-phases EnergyMonitor instances ?

Thanks a lot for your help...

At power-on, filteredV and I are uninitialised

(Awesome project, by the way - thanks so much for sharing!)

The correct functioning of the high-pass filter in EnergyMonitor::calcVI() relies on the previous values for filteredI and filteredV being sane. But these variables are uninitialised when the code starts running; hence they will be set to a random value at power-on!

Here's a patch with a simple fix: JackKelly@e10bfdf

how to calibrate current value?

we can't get exact current value according to original current value......

i used below cod

include "EmonLib.h"

include <LiquidCrystal.h>

EnergyMonitor emon1;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
emon1.current(0 ,30);
lcd.setCursor(0,0);
lcd.print("Current(A)=");
}

void loop()
{
double Irms = emon1.calcIrms(1480);

Serial.print(Irms*230.0);
Serial.print(" ");
Serial.println(Irms);
lcd.setCursor(12,0);
lcd.print(Irms);
}

please help me to resolve this problem....

High reading at the beginning

I have a problem measuring the Amps and kWhs for a few devices. The lib is so precise; nevertheless, after a while. In the beginning, I received a very high reading, and it kept reduced for a few cycles of the code until it settled to the precise value. Please advise.

Thank you.

CalcVI async calculation

Is it possible to make calcVI function do asynchronous calculation?
Because I cannot control other switch while emonlib doing calculate

Emonlib+Esp32+ADS1115 outputting inconsistant data

I did get it to work, by rewriting the emonlib library, but it was crontoversly to say at least. But it works perfectly, it still is measuring the current.
The reason I used the ADS1115 was indeed the ESP. I used the Nodemcu board and could use the extra current sensors.

Originally posted by @SybrenV in #23 (comment)

How were you able to get it working properly??

I have the hardware implemented, and under standard testing (only using an ADS1115 based sketch) the values work fine. However, when using the Emonlib w/ ADS support that Paul provided, I get invalid data.

I have changed the files to EmonLib_I2C considering that's what it's for. This way I don't get conflicts with ArduinoIDE.

#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include "EmonLib_I2C.h"                   // Include Emon Library
EnergyMonitor emon1;                   // Create an instance

Adafruit_ADS1115 ads;                  // Create an instance of the ADS1115 object

// Make a callback method for reading the pin value from the ADS instance
int ads1115PinReader(int _pin){
  return ads.readADC_SingleEnded(_pin);
}

void setup()
{  
  Serial.begin(115200);
  
  emon1.inputPinReader = ads1115PinReader; // Replace the default pin reader with the customized ads pin reader
  emon1.current(3, 111.1);             // Current: input pin, calibration.
}

void loop()
{
  double Irms1 = emon1.calcIrms(250);  // Calculate Irms only

  Serial.print("E1: ");
  emon1.serialprint();
}

Unfortunately, this is the output I get:

E1: 0.00 0.00 0.00 20696.53 0.00 
E1: 0.00 0.00 0.00 16211.26 0.00 
E1: 0.00 0.00 0.00 12698.02 0.00 
E1: 0.00 0.00 0.00 9946.16 0.00 
E1: 0.00 0.00 0.00 7790.67 0.00 
E1: 0.00 0.00 0.00 6102.30 0.00 
E1: 0.00 0.00 0.00 4779.84 0.00 
E1: 0.00 0.00 0.00 3743.97 0.00 
E1: 0.00 0.00 0.00 2932.59 0.00 
E1: 0.00 0.00 0.00 2297.05 0.00 
E1: 0.00 0.00 0.00 1799.24 0.00 
E1: 0.00 0.00 0.00 1409.32 0.00 
.........
E1: 0.00 0.00 0.00 1.18 0.00 
E1: 0.00 0.00 0.00 0.93 0.00 
E1: 0.00 0.00 0.00 0.73 0.00 
E1: 0.00 0.00 0.00 0.57 0.00 
E1: 0.00 0.00 0.00 0.44 0.00 
E1: 0.00 0.00 0.00 0.35 0.00 
E1: 0.00 0.00 0.00 0.27 0.00 
E1: 0.00 0.00 0.00 0.21 0.00 
E1: 0.00 0.00 0.00 0.17 0.00 
E1: 0.00 0.00 0.00 0.13 0.00 
E1: 0.00 0.00 0.00 0.10 0.00 
E1: 0.00 0.00 0.00 0.08 0.00 
E1: 0.00 0.00 0.00 0.06 0.00 
E1: 0.00 0.00 0.00 0.05 0.00 
E1: 0.00 0.00 0.00 0.04 0.00 
E1: 0.00 0.00 0.00 0.03 0.00 
E1: 0.00 0.00 0.00 0.02 0.00 
E1: 0.00 0.00 0.00 0.02 0.00 
E1: 0.00 0.00 0.00 0.01 0.00 
E1: 0.00 0.00 0.00 0.01 0.00 
E1: 0.00 0.00 0.00 0.01 0.00 
E1: 0.00 0.00 0.00 0.01 0.00 
E1: 0.00 0.00 0.00 0.01 0.00 
E1: 0.00 0.00 0.00 0.00 0.00 

It just slowly goes cycles down to "0" and then stays there. It doesn't matter if I have a current load or not.
And no, I don't have an external voltage reading of the mains line. It shouldn't matter for reading "current_only", correct? It would only be used during realpower calculations I would think.

But if I run the ADC only code, I get these values:

ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)
AIN0 	AIN1 	AIN2 	AIN3
770	0	771	0
773	0	771	0
770	0	767	0
773	0	1110	0   ---- Turned on load here
774	0	546	0
774	0	1147	0
775	0	450	0
770	0	818	0
773	0	947	0   ---- Turned off load here
769	0	771	0
773	0	772	0
773	0	772	0

Code:

#include <Wire.h>
#include <Adafruit_ADS1015.h>

// Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */
Adafruit_ADS1015 ads;     /* Use thi for the 12-bit version */

void setup(void) 
{
  Serial.begin(115200);
  Serial.println("Hello!");
  
  Serial.println("Getting single-ended readings from AIN0..3");
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
  ads.begin();
}

void loop(void) 
{
  int16_t adc0, adc1, adc2, adc3;

  adc0 = ads.readADC_SingleEnded(0);
  adc1 = ads.readADC_SingleEnded(1);
  adc2 = ads.readADC_SingleEnded(2);
  adc3 = ads.readADC_SingleEnded(3);
  Serial.print(adc0);
  Serial.print("\t");
.......
}

Thanks, Kori

Wrong (lower) current values with SCT-013-030?

I have an SCT-013-030 (30A, 1V peak signal, internal burden resistor 62 Ohm) connected to a UNO as "regular" schema (voltage divider with 2x10k from +5V to GND, and a 100nF condenser to GND).

My target is to monitor my Photovoltaic production, the same way I did before for years with an Efergy e2 power monitor (you can see it on the enclosed picture) that uses its own similar clip current sensor but without sensor specs I opted for that SCT-013. I'm aware that the measure can't be exact, as can vary depending on the load characteristics, but I can say Efergy always gave me not more than +/-5% difference from the inverter readings, so I expected the same range with SCT, Emonlib and Arduino UNO.

So, I made this simple sketch to perform some tests and calibration:
`#include "EmonLib.h"
EnergyMonitor emon1;
//Pin del sensore SCT su A1
#define SENS_CORRENTE A1
void setup()
{
Serial.begin(115200); //Apro la comunicazione seriale
Serial.print("Calibrating...");
// Just a bit of void readings to stabilize...
for (int i=1; i<=4; ++i)
analogRead(SENS_CORRENTE);
delay(500);
// Then calibrate (const= Ratio/Res. Burden 1800/62 = 29).
emon1.current(SENS_CORRENTE, 29);
Serial.println();
}

void loop()
{
// Read current
double Irms = emon1.calcIrms(1480);
// Just to ignore small fluctuations
if ( Irms <= 0.13 ) Irms = 0;
// Power ad current x 230V line voltage
int watt = (Irms*230);
watt = watt * 10;
// Show values
Serial.print(Irms,2);
Serial.print(" ");
Serial.println(watt);
delay(1000);
}`
The problem is I always get a power reading LOWER than real. For example, if I clip the sensor over the active wire of a power cable and connect a plug-in energy monitor and then a hairdryer, the energy monitor gives me the correct 1.7kW value, but that Arduino sketch gives me around 950W!
I then connected the sensor to the PV line out (the same wire I used with Efergy...) and here again I must multiply the resulting power by 1.7 to have a "similar" reading than the PV inverter says, but this 1.7 factor seems to be somehow "variable", depending on the PV output power, sometimes lower and sometimes higher for a bunch of hundred of watts, with an estimated factor ranging from 1.6 to 2.1 to get almost "exact" values!

I can accept a +/-5% precision like Efergy did, even a bit more, but an almost constant +70% is unacceptable. It seems something is wrong either with my circuit (but it's pretty simple..), and/or my implementation (but the measure sketch is like the example one) and/or the sensor (could be defective?), and/or the library (but I don't thik so), and/or what?
Thanks!
image

Problems with the phase_shift calibration

I tried to calibrate the phase shift but look to need a value outside the predefined range of 0-2
at 0 I get powerfactor of 0.96
at 1 I get powerfactor of 0.92
at 1.9 I get powerfactor of 0.89

So I tried 52 (shifting around 360° to get around the limit of 0) and I got a powerfactor of -1.12
with 49 I got a powerfactor of -0.96
But with these high values some other powerfactor for devices with a powerfactor of around 0.04 nog to 5.6

What am I'm doing wrong with this calibration ?
I used a 2000W electric heater so should be full resistive .

How to Measure Active & Reactive Power

I wanted to make a circuit that measures Active & Reactive Power drawn by AC loads. In order to do so, I had to design a circuit to measure the Phase Difference between AC voltage & current.

The idea is to use a Current Transformer(1:1000 turns ratio, 40ohm burden resistor) & a Step Down Voltage Transfromer(230V to 5V) to measure the current & voltage. The current & voltage signals would be fed to a Zero Cross Detector(ZCD) made using Comparator(LM339) & ExOR Gate(7486). The phase difference can be calculated based on the time period of the ZCD output signal.

I also used a Non Inverting Amplifier(using LM324) to amplify the input current signal to the ZCD. I have ensured that the VCC signal to all IC's is more than the Voltage of the input signals.

I am facing a few problems & not getting the intended results. I am getting proper current & voltage signals at the secondary sides of both transformers using a CRO. I am not getting the intended results at the ZCD part(both output of comparators & ExOR). i.e. The Comparator outputs are not in phase with the input voltage & current waveforms & do not show proper patterns either. The IC's tend to heat up when the voltage transformer signal is provided.

I have been working very hard to debug the circuit but to no avail. Can someone please help me out by pointing out my mistakes that I may be overlooking.

Heres a link to some of the circuit design that I have mentioned: Circuit Design Schematics, Graphs & Formulas

Calibration Error

I have different Loads and when I calibrate my voltage and current code for one setting, it does not work the same for another setting.
Ex - I have calibrated for 4Amps, when I increase my load the value on my meter comes 8Amps but my code shows 9Amps.

ESP8266 integration/compatibility

Hi
I try to use your library on ESP8266 and I get stuck when the library try to calculate the sqrt() function. The sqrt function lead ESP to crash and reboot, because of some problem in its math library when you program via the ArduinoIDE.
to overcame the issue, I implemented an approximated method to calculate the squareroot and it works fine.

Do you want that I do a pull request to integrate that part?
thanks
regards
Giacomo

License unspecified ?

Please add a LICENSE file in dir, mentioning GPL is not enough

Emon.cpp - Library for openenergymonitor
GNU GPL

Arduino Nano Every NOT Supported

Hi guys, we have bought the newest arduino nano every for our IOT projects and to monitoring houses consumptions.

However, we have seen that your library does not yet support these models...
The arduino compiler gives us this ADC register error :

/*
C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp: In member function 'long int EnergyMonitor::readVcc()':
C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:253:3: error: 'ADCSRA' was not declared in this scope
ADCSRA |= _BV(ADSC); // Convert
^~~~~~
C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:253:3: note: suggested alternative: 'ADC_t'
ADCSRA |= _BV(ADSC); // Convert
^~~~~~
ADC_t

ADCSRA |= _BV(ADSC); // Convert
^
C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:253:17: note: suggested alternative: 'DDRC'
C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:255:12: error: 'ADCL' was not declared in this scope
result = ADCL;
^~~~
C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:255:12: note: suggested alternative: 'ADC0'
result = ADCL;
^~~~
ADC0
C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:256:13: error: 'ADCH' was not declared in this scope
result |= ADCH<<8;
^~~~
C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:256:13: note: suggested alternative: 'ADC0'
result |= ADCH<<8;
^~~~
ADC0
*/

Would you able to integrate this model in your library?
Thanks!

total power real power consumption

I am wondering how can i calculate the total real power consumption lets say for one whole month? any suggestion for the modification i need to do. thanks

ESP32 resolution

More of a question than an issue (at this point).

The code applies a "low pass filter" (not sure what this is), that calculation has:
offsetV = offsetV + ((sampleV-offsetV)/1024);
offsetI = offsetI + ((sampleI-offsetI)/1024);

I'm a bit suspicious for the 1024 value: should this be 4096 for a 12 bit resolution ADC? Many places in the code use ADC_COUNTS which translates to ADC_BITS<<1 (power of 2), for 12-bit ADC this results to 4096.

Like I said, more of a question out of ignorance.

Bean support 8Mhz

Hi, trying to get this working on a Punchthrough Bean with additional 5V regulator, unfortunately the Bean only runs at 8Mhz, any tips on how to get it working?

RMS computation improvement suggestion

I used this very interesting library.

I have some suggestions for calcIrms():
1 - Before entering into the for loop, some variables have to be initialized:
sampleI = analogRead(inPinI); // very important for a signal with DC component
// the first sample create a high RMS
filteredI=0; // not so important but better
for (int n = 0; n < NUMBER_OF_SAMPLES; n++)

2 - The first order filter is sensitive to sampling period
if the speed of computation changes ( the frequency of the microcontroller changes from 2MHz -> 16 MHz) the cutt-off frequency changes also by a factor 8. This is because the sampling rate is not fixed and varies with the computation time. Perhaps it will be difficult to impove that, but it is important to know this effect.

3 - The gain of the filter is not equal to 1 at high frequency
but it should be in order to not affect the RMS.
The filter should be equal to:

define CUTT_OFF 0.996

filteredI =CUTT_OFF_(lastFilteredI+CUTT_OFF_(sampleI-lastSampleI));
With 0.996, the error is equal to 0.4 %, but if we want a higher cut-off frequency the error increases, because CUTT_OFF is lower.

I hope it will help.

calculations ECS1030-L72 sensor?

My Energy Meter parts List

image

Code

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

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

void loop()
{
   
    double Irms = emon1.calcIrms(1480);  
    Serial.print(Irms*220.0);         // Apparent power
    Serial.print(" ");
    Serial.println(Irms, DEC);          // Irms
    delay(1000);
}

8.5w lamp measurement

but output data :
137.87 0.6266713142
140.01 0.6364147663
138.00 0.6272707462
137.44 0.6247273445
135.22 0.6146469116
137.73 0.6260547637
139.02 0.6319146156
138.40 0.6290988445
137.97 0.6271401405
139.11 0.6323106288
138.62 0.6300705909
139.56 0.6343578338
141.37 0.6425902843
141.72 0.6441868782
140.05 0.6366049766
139.36 0.6334630012

What's the problem????????

Emonlib conflicts with other analogRead values.

I've a scenario where I'm using I2C interrupt and Emonlib together. I2C ISR contains several analogReads and emonlib measurement is running in loop(). I've observed that values from other analogReads are not quite correct when I'm using it with emonlib. Upon investigating, I've landed upon this Arduino thread, http://forum.arduino.cc/index.php?topic=54976.0, which suggests that if I'm in a middle of an analogRead and try to use the other analogRead (probably in an ISR caused by an interrupt) , due to multiplexer switch it might give me a wrong value. Is this a known issue ? If yes, can we enhance emonlib to put a certain lock or any other similar mechanism to prevent simultaneous access ?

Appreciate the help. Thanks.

Making Emonlib non-blocking

Hello,

I've had a brief look at the code and I'm wondering if it's possible to make the CalcVI function asynchronous? i.e. be able to constantly calculate the voltage and current, and also being able to perform other tasks at the same time? The best example of this usage would be a wall power meter with an LCD display, were you can seamlessly switch between displaying current, voltage, watts, change a settings, etc, while everything is still being calculated.

Potential deadlock in void EnergyMonitor::calcVI(..) - 50 days

Potential Deadlock

The calcVI function depends on the millis() function, to get a sequence, however the function millis() wraps, and thereby making a risk of an infinite loop.
The guilty code is this.

  unsigned long start = millis();    
//millis()-start makes sure it doesn't get stuck in the loop if there is an error.

  while(st==false)                                   //the while loop...
  {
     startV = analogRead(inPinV);                    //using the voltage waveform
     if ((startV < (ADC_COUNTS/2+50)) && (startV > (ADC_COUNTS/2-50))) st=true;  
//check its within range
     if ((millis()-start)>timeout) st = true;
  }

The code above fails, if millis() returns a number very close to 4,294,967,295. E.g 4,294,967,293.
This will cause millis()-start to become negative, and then it will never be bigger than the timeout value. Normally set to 2000 ms.

Minor issue - compiler warning

The code if ((millis()-start)>timeout) st = true; compares an unsigned long(positive numbers) with and int(natural numbers)
It is also semantically wrong to have a timeout, that is not unsigned.
These two issue have not been proven by unit test or similar.

Emonlib with ADS1115

Hello all!

I have a question for you,

I wanted to use the ADS1115 to read the analog value from my diy current clamp pcb(which worked perfectly with a Arduino nano).

Since i am a self taught programmer and i lack skill i cant figure out how I can implement the values I read with the ADS1115 into the emonlib library. Im using the Adafruit library (https://www.adafruit.com/product/1085).

Can maybe somebody point me in the right direction how to do this? I know the analogRead is located in Emonlin.ccp and i tried a lot of variation to load in the right number, but no luck...

Thanks in advance!

STM32 Bluepill support

Hello
Is this library supports Stm32 Bluepill? If so then Do I need any special config or not?

Arduino Nano IoT is not supportet?

I dont now where the mistake is, with Arduino UNO everything works fine,
if I use the Nano Iot the Values are complete wrong. I set the "analogReadResolution(ADC_BITS);"in the setup.
Have Someone an exaple vor the Iot?
Thanks in advance
Riggi

Solve most of your issues, ESP32

Some code that you may want to change to make it work (I have ESP32):
In EmonLib.h:

	#if defined(__arm__)
	#define ADC_BITS    12
	#else
	#define ADC_BITS    10
	#endif

Just add/replace with:
#define ADC_BITS 12

Because ESP32 is a 12-bit ADC.

In EmonLib.cpp
Replace all occurences of "/1024" by "/(ADC_COUNTS>>1".
The code was originally written for a 10-bit ADC, without ability to change it to 12 bits.

That's all. The precision and predictability of the reading is improved a lot.

Another note, for Calibration (111.1 value). If you have a voltage-output sensor (SCT-013-015, SCT-013-020, etc.), replace the "111.1" with "15" for -015, "20" for -020, etc. In other words, use the same calibration value as the Amp/V value (15A/V use "15", 30A/V use "30"). Most of the examples I saw online, using the 111.1 calibration value, are only good for SCT-013-000 with current output (which also require a burden/load resistor). Since the non-000 (-015, -020, -050, etc.) sensors have the burden/load resistors integrated, the calibration constant is different.

I hope it helps someone. Took me a few days to figure it out.

Alex

error in calculating offset for RMS calulations

First, I have no experience with Arduino's, nor do I have one - so pinch(grain) of salt - I just came across this while looking up ideas.

I do not know the speed of the iterations in the sampling loop, but assuming there are more that just a few samples each half cycle offsetIV(I) will move up and down by about (A * S)/1024 where A is the peak A/D count (≈500/2000 at full scale) and S is the number of samples per half wave.

Better would be to update the calculated offset each full wave or even just once each measurement (again depending on # samples each half wave)
mike

total KWH

hello, I firstly i would like to thank you guys for this amazing work. I am actually trying to modify the current voltage example to get the total accumulative KWH. my idea was to take the real power samples lets say 3600 sample per hour, and add them to get 24 hour for one day. any alogorithem recommended other than this. another issue is that i was trying to understand the source code to figure every how long it takes samples from the current and voltage sensor.

thanks

Voltage & Current Calibration

When I ran the current_only sketch, I set the value of the current calibration to 4.75. The load I used was a 40W incandescent bulb. The real power drawn as measured by the Arduino was also ~40W.

When I ran the voltage_and_current sketch, I kept the same current calibration value of 4.75
I changed the value of the voltage constant to the value read from the AC mains by my multimeter.
In my case, the multimeter read 239V. Hence emon1.voltage(2, 239, 1.7);

For the same 40W Incandescent bulb as my load, I got the following results:

-70.34 71.80 430.72 0.17 -0.98 
-70.61 71.94 432.79 0.17 -0.98 
-70.51 72.16 430.68 0.17 -0.98 
-70.55 71.95 433.02 0.17 -0.98 
-69.53 70.60 432.65 0.16 -0.98 
-71.25 72.74 432.78 0.17 -0.98 
-70.85 71.95 430.73 0.17 -0.98 
-70.83 72.30 432.91 0.17 -0.98 
-69.46 71.23 432.76 0.16 -0.98 
-69.84 71.43 432.77 0.17 -0.98 
-70.23 71.53 432.81 0.17 -0.98 
-71.20 72.46 432.89 0.17 -0.98 
-70.06 71.87 430.98 0.17 -0.97 
-69.68 70.69 432.69 0.16 -0.99 

An incandescent bulb is considered as a Resistive Load. Hence the values of Real & Apparent power should ideally be equal.
In my case, the absolute values of Real & Apparent Power are almost equal with an error margin of ~1.4%.
The value of Irms is correct i.e. 40/239 = 0.167

I am getting a few errors that I wish to debug:

  1. The value of Real Power is 70W instead of 40W. Real Power is negative whereas Apparent Power is positive.
  2. The value of Vrms is 431V instead of 239V. Is this value supposed to have an error so large?
  3. The value of power factor is negative. Shouldn't this value be negative only if the load generates power which flows back to the source?

@icboredman Could you help me with this?

Compile warnings for unused variable "result"

I believe it comes from line 232 of Emonlib.cpp not being inside the "if" that uses it.. I get this error for both my own program and the example program for Arduino. Anyone want to confirm?

ESP8266 with EmonLib.h

Good afternoon.
I plan to use ESP8266 to measure AC voltage 220V.
To do this, I try to use the ZMPT101B module, the EmonLib master library (EmonLib.h), and the Voltage.ino (https://forum.arduino.cc/index.php?action=dlattach;topic=357095.0;attach=164922 1) sketch.
When there is a voltage at the module input, the sketch outputs values ​​to the terminal.
But as soon as the voltage disappears at the module input, an error appears:

ets Jan 8 2013, rst cause: 2, boot mode: (3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ ld
⸮0.00 0.00 217.27 0.00 nan
0.00 0.00 172.59 0.00 nan

Soft WDT reset

ctx: cont
sp: 3ffef1f0 end: 3ffef4b0 offset: 01b0

stack >>>
3ffef3a0: 4021a51d 00000004 00000000 4112e264
3ffef3b0: 4021a7bf 00000004 00000000 3ffee2d8
3ffef3c0: 000007d0 00000004 00000000 00000000
3ffef3d0: 40213a20 00000000 00000000 3ffee2d8
3ffef3e0: 05fb05fb 05fb05f9 05fb05f9 05fb05fb
3ffef3f0: 00000000 000002fd 40204064 000012a1
3ffef400: 40201126 7ff80000 feefeffe 3ffee484
3ffef410: 40101afc 001622e3 000012a1 40201e79
3ffef420: 40101afc 00169d0d 3ffee3ac 00000000
3ffef430: 3ffe8910 00000014 00000000 4087e800
3ffef440: 3ffe835c 3ffee2c8 402028c4 3ffee490
3ffef450: 402010ae 00000064 00000064 3ffee484
3ffef460: 3fffdad0 00000000 3ffee2d8 40201cd8
3ffef470: feefeffe feefeffe feefeffe 3ffee484
3ffef480: 00000000 00000000 00000001 3ffee484
3ffef490: 3fffdad0 00000000 3ffee47c 40202910
3ffef4a0: feefeffe feefeffe 3ffee490 40100114
<<< stack <<<

I ask to help to solve the problem.
Thank you.

SCT-013

Hi , I like use your library with esp8266 on nodemcu 1.0, usually I use 30a sct sensor but I also try 100a and 60a sensors , do you can say to me calibration value ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.