Diy smart meter for home using nodemcu esp8266

hi good day guys im still newbie i hope you can help me give some ideas
i want to build smart meter for my thesis
im using...
nodemcu esp8266 ,
ads1115 for analog extender ,
acs712 current sensor
ZMPT101B current voltage

wiring
nodemcu esp8266 connect d1 d2 to scl and sda 3.3v to ads1115 gnd to gnd
addrs to grnd..
then the voltage sensor a0 to output of voltage sensor and the a1 is gnd..
and to current sensor is a2 to output of current the and the a3 is to gnd...

my problems i i cant get the accurate voltage and current :frowning:

the code i use.

  //Library to use
#include <Wire.h>
#include <Adafruit_ADS1X15.h>
#include <Filters.h>                           

Adafruit_ADS1115 ads; 


/////////voltage var		
float testFrequencys = 50;                     // test signal frequency (Hz)	
float windowLengths = 100/testFrequencys;       // how long to average the signal, for statistist, changing this can have drastic effect	
int RawValue = 0;
float Volts_TRMS;     // estimated actual voltage in Volts
float intercepts = 0;  // to be adjusted based on calibration testin
float slopes = 1;
unsigned long printPeriods = 1000; // in milliseconds
unsigned long previousMilliss = 0;
////////end voltage var


/////current var
float ACS_Value;                              //Here we keep the raw data valuess	
float testFrequency = 50;                    // test signal frequency (Hz)	
float windowLength = 40.0/testFrequency;     // how long to average the signal, for statistist	
float intercept = 0; // to be adjusted based on calibration testing			
float slope = 0.0462; // to be adjusted based on calibration testing			
float Amps_TRMS; // estimated actual current in amps
unsigned long printPeriod = 1000; // in milliseconds
// Track time in milliseconds since last reading
unsigned long previousMillis = 0;
//////end current var


void setup(void){
Serial.begin();
ads.setGain(GAIN_ONE);
ads.begin();
}

void loop(void)
{

////////voltage statistic
RunningStatistics inputStatss;                 // create statistics to look at the raw test signal	
inputStatss.setWindowSecs( windowLengths );     //Set the window length	
/////////end voltge statistic

//////////voltage calcultation//////
RawValue = ads.readADC_SingleEnded(0);  // read the analog in value:
inputStatss.input(RawValue);       // log to Stats function
if((unsigned long)(millis() - previousMilliss) >= printPeriods) { //We calculate and display every 1s
previousMilliss = millis();   // update time
Volts_TRMS = inputStatss.sigma()* slopes + intercepts;
//      Volts_TRMS = Volts_TRMS*0.979;              //Further calibration if needed
}
//////////// end voltage cal/////////////



//////////current statistic///////////
RunningStatistics inputStats;                 // create statistics to look at the raw test signal	
inputStats.setWindowSecs( windowLength );     //Set the window length	
// endcurrentstatistic//////

///////////current calculation/////
ACS_Value = ads.readADC_SingleEnded(2);  // read the analog in value:
inputStats.input(ACS_Value);  // log to Stats function
if((unsigned long)(millis() - previousMillis) >= printPeriod) { //every second we do the calculation
previousMillis = millis();   // update time
Amps_TRMS = intercept + slope * inputStats.sigma();
}
///////////end current calculation/////////////



Serial.println("....................................Voltage output.....................................");
Serial.print("Non Calibrated: ");
Serial.print("\t");
Serial.print(inputStats.sigma());
Serial.print("\t");
Serial.print("Calibrated: ");
Serial.print("\t");
Serial.println(Volts_TRMS);
delay(1000);
Serial.println(".........................current output...........................");
Serial.print( "\t Amps: " );
Serial.print( Amps_TRMS );

}

Both of your sensors output an AC voltage. AC means the voltage and current go positive then negative then positive.......

I don't know the frequency of you AC input. Its likely 50 or 60 Hz. If 50 Hz then the period is 0.02 seconds (aka 20 ms). You would have to take readings at least 10 times faster than 20 ms. Calculate either the average of the absolute value or the RMS value.

1 Like

@JohnRob thank you i really appriciate it i changed my code so that it can help me i think

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.