Experts! Shout for help again!
I'm trying to build an AC power/energy meter for some project of mine. I'm using the ACS712 Hall Effect current sensor for this project due to its compact size and very high output linearity. I'm using the 30A version of this sensor. I use the ADS1115 16bit ADC to read the output from ACS712 and process it in the code.
I'm building this on an ESP8266 microprocessor board using Arduino IDE. Below is my code for calculating the power. As a starting point, I've taken the code for now from:
https://www.instructables.com/id/Arduino-Energy-Meter-V20/
For testing, I'm using a 200W filament bulb as load.
Issue that I'm facing is:
- When I check the current on my DMM, it shows approx 0.8A of current drawn
- Output of the ESP8266, using the above code, shows me a current drawn of approx 1A
AC voltage seen on my DMM is approx 245V (I know its on the higher side. It should be around 230V, but what to do ... its India).
Can someone help me understand/identify where am I going wrong or where the code is going wrong? Would be of immense help!
Regards,
Deepak
I'm trying to build an AC power/energy meter for some project of mine. I'm using the ACS712 Hall Effect current sensor for this project due to its compact size and very high output linearity. I'm using the 30A version of this sensor. I use the ADS1115 16bit ADC to read the output from ACS712 and process it in the code.
I'm building this on an ESP8266 microprocessor board using Arduino IDE. Below is my code for calculating the power. As a starting point, I've taken the code for now from:
https://www.instructables.com/id/Arduino-Energy-Meter-V20/
C:
// Arduino Energy Meter V2.0
// This code is for This code is for Wemos(ESP8266) based Energy monitoring Device
// This code is a modified version of sample code from https://github.com/pieman64/ESPecoMon
// Last updated on 30.05.2018
#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
Adafruit_ADS1115 ads(0x48); /* Use this for the 16-bit version */
#define SERIAL_BAUD 115200
int ledPower = 12;
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV (default)
// ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV
unsigned int Sensitivity = 66; // 185mV/A for 5A, 100 mV/A for 20A and 66mV/A for 30A Module
float Vpp = 0; // peak-peak voltage
float Vrms = 0; // rms voltage
float Irms = 0; // rms current
float Supply_Voltage = 247.0; // reading from DMM
float Vcc = 5.0; // ADC reference voltage // voltage at 5V pin
float power = 0; // power in watt
float Wh =0 ; // Energy in kWh
unsigned long last_time =0;
unsigned long current_time =0;
unsigned long interval = 100;
unsigned int calibration = 12; // V2 slider calibrates this
unsigned int pF = 85; // Power Factor default 95
void getACS712() { // for AC
Vpp = getVPP();
Vrms = (Vpp/2.0) *0.707;
Vrms = Vrms - (calibration / 10000.0); // calibtrate to zero with slider
Irms = (Vrms * 1000)/Sensitivity ;
if((Irms > -0.015) && (Irms < 0.008)){ // remove low end chatter
Irms = 0.0;
}
power= (Supply_Voltage * Irms) * (pF / 100.0);
last_time = current_time;
current_time = millis();
Wh = Wh+ power *(( current_time -last_time) /3600000.0) ; // calculating energy in Watt-Hour
Serial.print("Irms: ");
Serial.print(String(Irms, 3));
Serial.println(" A");
Serial.print("Power: ");
Serial.print(String(power, 3));
Serial.print(" W");
Serial.print("\t Energy Unit(s) (KWh): ");
Serial.println(String((Wh/1000), 4));
}
float getVPP()
{
int16_t adc1;
float result;
int readValue;
int maxValue = 0;
int minValue = 32768;
uint32_t start_time = millis();
while((millis()-start_time) < 950) //read every 0.95 Sec
{
readValue = ads.readADC_SingleEnded(1);
if (readValue > maxValue)
{
maxValue = readValue;
}
if (readValue < minValue)
{
minValue = readValue;
}
}
result = ((maxValue - minValue) * Vcc) / 32768.0;
Serial.print("\nVp-p: ");
Serial.println(String(result, 3));
return result;
}
void setup() {
Serial.begin(115200);
Serial.println("\n Rebooted");
Serial.begin(SERIAL_BAUD);
while(!Serial) {} // Wait
Wire.begin(D3,D4); //Changed defaults to match ESP8266 pin connections: 23 - SDA, 24 - SCL
ads.begin();
WiFi.begin("Tulsani", "homenetwork");
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());
pinMode(ledPower,OUTPUT);
}
void loop()
{
getACS712();
delay (2000);
}
Issue that I'm facing is:
- When I check the current on my DMM, it shows approx 0.8A of current drawn
- Output of the ESP8266, using the above code, shows me a current drawn of approx 1A
AC voltage seen on my DMM is approx 245V (I know its on the higher side. It should be around 230V, but what to do ... its India).
Can someone help me understand/identify where am I going wrong or where the code is going wrong? Would be of immense help!
Regards,
Deepak