current measure

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
andy-ich
Normal user
Posts: 10
Joined: 17 Mar 2016, 07:59

current measure

#1 Post by andy-ich » 17 Mar 2016, 08:18

Hi,

I'm excited about this project. I control so that all blinds.
Also have many of my light switch refitted and made inteligent :D

A big wish of mine, it is to measure the current of devices. Washingmachine, Refrigerator, ...
Which component does this with EspEasy?

thx

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: current measure

#2 Post by BertB » 17 Mar 2016, 20:07

Have a look here http://www.esp8266.nu/forum/viewtopic.p ... dishwasher
But be careful. Some Chinese boards with this chip on it, like http://nl.aliexpress.com/item/NEW-20A-H ... 4589af03fb

are not realy save or capable of dealing with 20 Amps.

andy-ich
Normal user
Posts: 10
Joined: 17 Mar 2016, 07:59

Re: current measure

#3 Post by andy-ich » 24 Mar 2016, 14:00

Thanks for your answer.
Is it ok like this?:
ESP_ACS712.png
ESP_ACS712.png (43.29 KiB) Viewed 24636 times

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: current measure

#4 Post by BertB » 27 Mar 2016, 15:31

I think it is a good starting point, but some of the Chinese products do not keep the minimum safety clearance between 230 volt and 5 volt tracks.
If that is the case, it is likely there are no electrical safety issues as long as you do not attach any other sensor to the esp that has conductive elements that can be touched from the outside.

Furthermore, you probably need some capacitors on the HLK-PM01. In mine I have also mounted an electronic fuse and a VDR.

User avatar
ManS-H
Normal user
Posts: 279
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: current measure

#5 Post by ManS-H » 28 Mar 2016, 14:29

BertB wrote:I think it is a good starting point, but some of the Chinese products do not keep the minimum safety clearance between 230 volt and 5 volt tracks.
If that is the case, it is likely there are no electrical safety issues as long as you do not attach any other sensor to the esp that has conductive elements that can be touched from the outside.

Furthermore, you probably need some capacitors on the HLK-PM01. In mine I have also mounted an electronic fuse and a VDR.
BertB, is it possible to extend the scheme with your options? Or what capacitors and VDR you used and where did you placed them. Its a learning aspect for me.

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: current measure

#6 Post by costo » 28 Mar 2016, 15:32

I do not think it is possible to measure 50/60Hz line current with ESPEasy and a ACS712 module.
It is true that the output of the ACS module produces a voltage that is proportional to the current ......... but this proportional voltage is an alternating voltage of the same frequency and waveform as the AC-line current waveform has.

ESPEasy will sample the momentary value of the voltage and this momentary value will IN NO WAY be proportional to the original effective/average AC line current.
There must be some extra hardware to convert the alternating voltage to a effective/average DC voltage that can be measured with ESPEasy.
The simpel method would be a diode with a smoothing capacitor but this will give very inaccurate results at lower currents.

This article http://www.instructables.com/id/How-to- ... ct-Sensor/ will give a way to use the ACS712 together with ESPEasy.

User avatar
ManS-H
Normal user
Posts: 279
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: current measure

#7 Post by ManS-H » 28 Mar 2016, 17:05

My wife is asking of it's possible to get a notification on her mobile when the washing machine is ready, that why i was looking at this solution.

andy-ich
Normal user
Posts: 10
Joined: 17 Mar 2016, 07:59

Re: current measure

#8 Post by andy-ich » 28 Mar 2016, 21:00

thank you for your information

@BertB: If you tell me in detail where I need which components, I will update the scheme here.

@costo: I am aware that I can not use them to measure the exact power consumption.
By several measurements in quick succession, i hope can see a trend.
E.g. the mode in which just the washing machine is.
Does not exist a finished product(board)? ...what you've linked.

I'm curious about the result. :D

User avatar
hilo90mhz
Normal user
Posts: 11
Joined: 29 Mar 2016, 21:21
Location: Hilo, Hawaii
Contact:

Re: current measure

#9 Post by hilo90mhz » 01 Apr 2016, 00:32

I am compiling information on my project using current measurements here http://hilo90mhz.com/remote-power-monit ... surements/

I am using espEasy to send data to thingspeak that is triggering a txt message through twillo on condition met with AC current sent along in text message - it is working.

I will write up full documentation in the coming days...

Suffice to say you want to use these current sensors for your application: https://openenergymonitor.org/emon/buil ... -interface

I have integrated their emonLib library into the MiniProExtender Arduino code on an arduino pro mini - emulating the analog read output and ESPEasy doesn't know its not just straight analog read but actually formatted current data ;) you get 6 channels current/voltage with the ADCs in MiniPro and its cheaper than going with dedicated external I2C ADC.

https://thingspeak.com/channels/101562

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: current measure

#10 Post by BertB » 02 Apr 2016, 21:59

@andy-ich and @ManS-H

Apologies for the late response.
The manufacturer of the HLK-PM1claims a ripple of <= 50 mVpp when a 10 uF (electrolytic) and a 0.1 uF (ceramic) are connected across the output.
At the mains side of the HLK-PM1, across the AC pins, I have a VDR 10K391. That short circuits higher tension values. In series between one of the mains inputs and the HLK-PM1, I have a electronic fuse of 1 Amp.

What program did you use to make the schematic?

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: current measure

#11 Post by BertB » 03 Apr 2016, 14:24

This works for me:

Image

User avatar
hilo90mhz
Normal user
Posts: 11
Joined: 29 Mar 2016, 21:21
Location: Hilo, Hawaii
Contact:

Re: current measure

#12 Post by hilo90mhz » 03 Apr 2016, 19:44

BertB wrote:This works for me:
That's exactly the power supply setup I plan to use.. 5 of the hlk modules are in the mail. Looks good!
Last edited by hilo90mhz on 04 Apr 2016, 22:21, edited 1 time in total.

User avatar
ManS-H
Normal user
Posts: 279
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: current measure

#13 Post by ManS-H » 04 Apr 2016, 10:19

BertB wrote:This works for me:
Thanks for the Power Supply scheme.

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: current measure

#14 Post by costo » 04 Apr 2016, 12:46

hilo90mhz wrote:I am compiling information on my project using current measurements here http://hilo90mhz.com/remote-power-monit ... surements/

I am using espEasy to send data to thingspeak that is triggering a txt message through twillo on condition met with AC current sent along in text message - it is working.

I will write up full documentation in the coming days...

Suffice to say you want to use these current sensors for your application: https://openenergymonitor.org/emon/buil ... -interface

I have integrated their emonLib library into the MiniProExtender Arduino code on an arduino pro mini - emulating the analog read output and ESPEasy doesn't know its not just straight analog read but actually formatted current data ;) you get 6 channels current/voltage with the ADCs in MiniPro and its cheaper than going with dedicated external I2C ADC.

https://thingspeak.com/channels/101562
Pleased to see that there are people looking for real solutions to do some AC current/power measurements in combination with ESPEasy.
I found a simple solution here : https://forum.arduino.cc/index.php?topic=179541.0 (by dc42) that I plan to use on a proMiniExtender.
I am waiting for a ACS712 currentsensor to arrive from china, when I have it I will certainly try the library from your link too, thanx for the good info you provided.

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: current measure

#15 Post by BertB » 04 Apr 2016, 22:19

I am very curious where this will go in the reality of the day, since many loads are not truly sinusoidal.

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: current measure

#16 Post by JR01 » 27 Apr 2016, 18:54

Hi, the same author on Instructables you quoted and linked to his project to get AC current smoothed to measure it, published a new / improved project now for AC hall effect measurement with Arduino. See it here http://www.instructables.com/id/Simplif ... -Using-AC/. He does not need the smoothing circuit anymore, but uses the Arduino "Filters" library. See the filters Arduino sketch here http://playground.arduino.cc/Code/Filters. Any chance we can ask dev's to include this in order to read AC current with hall effect sensors like the ACS709, or ACS712 or similar?
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: current measure

#17 Post by JR01 » 27 Apr 2016, 20:06

costo wrote:
hilo90mhz wrote: I am waiting for a ACS712 current sensor to arrive from china, when I have it I will certainly try the library from your link too, thanx for the good info you provided.
Hello @costo, I see you are playing with the AC712 as well, and you already posed No '15 you have ordered parts and want to try current AC measurement,have you got it woking yet? Would love to learn from you.
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: current measure

#18 Post by BertB » 27 Apr 2016, 21:46

I think it is not a good idea to use an ESPEasy for this purpose, since accurate measurements require many samples per second.

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: current measure

#19 Post by costo » 30 Apr 2016, 15:41

JR01 wrote:Hi, the same author on Instructables you quoted and linked to his project to get AC current smoothed to measure it, published a new / improved project now for AC hall effect measurement with Arduino. See it here http://www.instructables.com/id/Simplif ... -Using-AC/. He does not need the smoothing circuit anymore, but uses the Arduino "Filters" library. See the filters Arduino sketch here http://playground.arduino.cc/Code/Filters. Any chance we can ask dev's to include this in order to read AC current with hall effect sensors like the ACS709, or ACS712 or similar?
Hi JR01,
Looked at the instructable article. I have experimented with exact the same sensor but do not really like that sensor . The electrical isolation between the Line current and the low voltage part (arduino) is very small.
There is a safer ACS712 module that is only a little more expensive but it has better isolation properties. (Greater distance of the conducting parts.)
http://www.aliexpress.com/item/Original ... 83198.html
I have been experimenting with ACS712 and a PME pro Mini Extender and have very usable results.
Though the combination of ACS and PME have some difficulties.

1) The noise in the ACS is about 0.12 Ampere on the 5Amp module, so there is never a zero reading.
2) Accuracy and foremost resolution is limited by the PME AD converter which is 10 bit (1024 steps)
As the 5Amp has an output of 0.185V/Ampere and the ADC has a resolution of 5V/1024 there are only about 26.4 mA resolution.

The good thing is that you can do a lot of measurements in a short period.
In 0.1 second (100.000 micros) the PME does 250 measurements, so you sample exactly 5 periods of a 50Hz or 6 cycles of 60Hz. The PME calculates the square root of the sum of the squared values, which is very close to the true RMS value.

It needs some more to calculate the power. It is acceptable to assume that the line voltage is always 230 volt (+- 5%) But the Cos φ value needs to be calculated. For that you need a circuit to measure the zero crossing of the voltage and calculate the difference with the zero crossing of the current. Preferrable that circuit needs to have line isolation with a opto-coupler.
Power used/generated is then: measured current * 230 * Cos φ.
I am working on that.

For now I will publish a sketch for the PME in this topic
http://www.esp8266.nu/forum/viewtopic.p ... nder#p6385
This measures the RMS current without Cos φ calculation

grz3
Normal user
Posts: 36
Joined: 21 Feb 2016, 21:47

Re: current measure

#20 Post by grz3 » 24 May 2016, 11:23


User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: current measure

#21 Post by costo » 24 May 2016, 13:05

I found these articles about hacking a cheap Chinese PowerPlugMonitor to send the measuring data wireless very interesting:

Hacking the powermeter: http://gizmosnack.blogspot.nl/2014_10_01_archive.html
Making it wireless: http://gizmosnack.blogspot.nl/2014/11/p ... eless.html

The code is written for Arduino and NRF24L01 but it could be adapted to work on the ESP and even ESPEasy with the PME
This approach looks far more promising than working with a ACS712 which will never be accurate enough to measure power.
Also the cost of building a reasonable accurate powermeter yourself will be higher than using this hacked Power Plug Meter.

shubell
New user
Posts: 5
Joined: 07 Sep 2016, 13:25

Re: current measure

#22 Post by shubell » 07 Sep 2016, 13:27

So are there any plans to include an Analog Input device that uses filters and measures the fluctuation and/or min max values?

daxkamala
Normal user
Posts: 15
Joined: 17 Aug 2016, 09:12

Re: current measure

#23 Post by daxkamala » 07 Sep 2016, 16:51

Sonoff were promising a switch that returns the power consumption of the load.
Seems to have vanished from their website.

I'm waiting for some ACS758 devices. http://www.ebay.co.uk/itm/150653947908

There are code snippets to get this going.

I will report back....

shubell
New user
Posts: 5
Joined: 07 Sep 2016, 13:25

Re: current measure

#24 Post by shubell » 08 Sep 2016, 12:14

ok i did some googling and came up with this code
the majority of the code is from here
http://henrysbench.capnfatz.com/henrys- ... -tutorial/
did some changes and add some comments and it kinda works.

Code: Select all

#define DEBUG 1

/*
Measuring AC Current Using ACS712
http://physicsnet.co.uk/a-level-physics-as-a2/current-electricity/alternating-current-ac/
*/
//parameters
const int sensorIn = A0; 
int mVperAmp = 89; // use 100 for 20A Module and 66 for 30A Module, 5A is 185 for 5v input voltage // use this formula Vout = Vin/2 + ((Vin/2)/Imax)*I  , first set I = 0 then 1 and substract them and you get the correcct values , Imax is not the Module type for example 20A but the Imax value wich is not the same
double ADCmaxVolt = 3.3 ; // arduino has 5, nodemcu esp has 3.3, esp has 1.06
int ADCRessolution = 1024;
int Offset = 7; // because values at zero Amp have different min max
int STime = 500 ; // twice that time
//end of parameters

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;


void setup(){ 
 Serial.begin(115200);
}

void loop(){
  Voltage = getVPP(); //  peak to peak current in amperes shown in volts
 VRMS = (Voltage/2.0) *0.707; //0.0707 is kinda the same as 1/sqroot(2) = 0.7071067..   // we divide peak to peak so we get Io= peak current in amperes shown in volts and Irms = Io / sqroot(2)  all shown in volts
 AmpsRMS = (VRMS * 1000)/mVperAmp; //now we convert voltage to amps  // RMS is equal to the value of the direct current that would produce the same power dissipation in a resistive load
 Serial.print(AmpsRMS);
 Serial.println(" Amps RMS");
}

float getVPP()
{
  float result;
  
  int readValue;             //value read from the sensor
  int maxValue = 0;          // store max value here
  int minValue = ADCRessolution;          // store min value here
  int samplecount = 0 ;
   uint32_t start_time = millis();
     int substracted;
   while((millis()-start_time) < STime) //sample for 1 Sec
   {
      samplecount = samplecount + 1 ;
       readValue = analogRead(sensorIn);
       // see if you have a new maxValue
       if (readValue > maxValue) 
       {
           /*record the maximum sensor value*/
           maxValue = readValue;
       }
       if (readValue < minValue) 
       {
           /*record the maximum sensor value*/
           minValue = readValue;
       }
   }

   // i do everything twice so i get a better average in the end if something peaks, could've done better but...
  float result1;
  int readValue1;             //value read from the sensor
  int maxValue1 = 0;          // store max value here
  int minValue1 = ADCRessolution;          // store min value here
  int samplecount1 = 0 ;
  uint32_t start_time1 = millis();
  int substracted1;
  while((millis()-start_time1) < STime) //sample for 1 Sec
   {
      samplecount = samplecount + 1 ;
       readValue1 = analogRead(sensorIn);
       // see if you have a new maxValue
       if (readValue1 > maxValue1) 
       {
           /*record the maximum sensor value*/
           maxValue1 = readValue1;
       }
       if (readValue1 < minValue1) 
       {
           /*record the maximum sensor value*/
           minValue1 = readValue1;
       }
   }

   
   // Subtract min from max
   substracted = maxValue - minValue -  Offset;
   substracted1 = maxValue1 - minValue1 - Offset ;
   if (substracted < 0) 
       {
         substracted = 0;
         #ifdef DEBUG
          Serial.println(" Offset too big");
          #endif
       }
    if (substracted1 < 0) 
       {
         substracted1 = 0;
         #ifdef DEBUG
          Serial.println(" Offset too big");
          #endif
       }
   
   result = ( (double)(substracted) * ADCmaxVolt)/  ADCRessolution; //gets the milivolt difference betweene the values
   result1 = ( (double)(substracted1) * ADCmaxVolt)/  ADCRessolution; //gets the milivolt difference betweene the values
 #ifdef DEBUG
Serial.print(" Try 1 min is ");
Serial.print(minValue);
Serial.print(" max is ");
Serial.print(maxValue);
 Serial.print(" Try 2 min is ");
Serial.print(minValue1);
Serial.print(" max is ");
Serial.print(maxValue1);
Serial.print(" Togethe sampled  ");
Serial.print(samplecount);
Serial.print(" times in 1 sec, first result is  ");
Serial.print(result);
Serial.print("  second is ");
Serial.print(result1);
Serial.print("  Together ");
 Serial.print((double)(result +result1) / 2);
 Serial.println("");
#endif
      
   return ((double)(result +result1) / 2) ;
 }

shubell
New user
Posts: 5
Joined: 07 Sep 2016, 13:25

Re: current measure

#25 Post by shubell » 08 Sep 2016, 12:51

daxkamala wrote: I'm waiting for some ACS758 devices. http://www.ebay.co.uk/itm/150653947908
Well there is quite a lot of code on the internetz for DC but AC is a pain in the ass

edit:
this sensor looks promising PmodISNS20

danielsan
New user
Posts: 3
Joined: 16 Sep 2016, 13:48

Re: current measure

#26 Post by danielsan » 16 Sep 2016, 15:57

Hi All, I read about the current monitor thread.
Since i still cannot find what i'm looking for i'm going to ask you my question!

I'm using an arduino nano clone to read data from a CT sensor (as seen on openenergymonitor.org). it works good! i'm also using a 220->9V AC transformer to have the correct measure of the voltage of my powerline.
I would like to know if there's some way to "import" the data from nano to espeasy and then to the world by mqtt or json string or emoncms website , so i could use them to trig events (like send a message when the washing machine have finished) :P

shubell
New user
Posts: 5
Joined: 07 Sep 2016, 13:25

Re: current measure

#27 Post by shubell » 27 Sep 2016, 14:26

ok here is some more test code :) here you won't need to calibrate the zero value, just change the mVperAmp value I think the logic behind the code is ok... it kinda measures Irms and average I and also power usage

Code: Select all

#define DEBUG 1

/*
Measuring AC Current Using ACS712
http://physicsnet.co.uk/a-level-physics-as-a2/current-electricity/alternating-current-ac/
*/
//parameters
const int sensorIn = A0; 
int mVperAmp = 30; // use 100 for 20A Module and 66 for 30A Module, 5A is 185 for 5v input voltage // use this formula Vout = Vin/2 + ((Vin/2)/Imax)*I  , first set I = 0 then 1 and substract them and you get the correcct values , Imax is not the Module type for example 20A but the Imax value wich is not the same
float ADCmaxVolt = 3.3 ; // arduino has 5, nodemcu esp has 3.3, esp has 1.06
int ADCRessolution = 1024;
int Offset = 1; // because values at zero Amp have different min max
int STime = 1000 ; 
float Zero = 417.1; //will get zero value based on average
float PrevZero = Zero ;
int VRMS = 230 ;//europe 
//end of parameters

//double Voltage = 0;
//double VRMS = 0;
double Amps = 0;
double ARMS = 0;
double Calc =  double(ADCmaxVolt) /  double(ADCRessolution) *  double(1000) / double(mVperAmp);

void setup(){ 
 Serial.begin(115200);
 
Serial.println(" Measuring Zero value!!!");

//get average

  int readValue;       
  int sample = 0;
  float sum = 0;
 uint32_t start_time = millis();
  while((millis()-start_time) < 200) //sample for 1 Sec
   {
  readValue = analogRead(sensorIn);
 sample = sample +1;
 sum = sum + readValue ;


   }
   Zero = double(sum/sample);
Serial.print(" Zero: ");
Serial.println(Zero);


// 
}

void loop(){
  GetValues();
  //Voltage = getVPP(); //  peak to peak current in amperes shown in volts
 //VRMS = (Voltage/2.0) *0.707; //0.0707 is kinda the same as 1/sqroot(2) = 0.7071067..   // we divide peak to peak so we get Io= peak current in amperes shown in volts and Irms = Io / sqroot(2)  all shown in volts
// It is worth noting that it is true only for a sinusoidal waveform... here it is not so we have to multply every value and then sqr the average
 //Amps = (Voltage * 1000)/mVperAmp; //now we convert voltage to amps  // RMS is equal to the value of the direct current that would produce the same power dissipation in a resistive load

}

float GetValues()
{
 // float result;
  int readValue;             //value read from the sensor
  int samplecountplus = 0 ;
  int samplecountminus = 0 ;
  int samplecountzero = 0 ;
  long sumplus = 0 ;
  long summinus  = 0 ;
  long sumzero = 0 ;
  float SumSq = 0 ;
 #ifdef DEBUG
 int maxvalue = 0 ;
 int minvalue = 1024 ;
 #endif
 
  boolean ping = true;
   uint32_t start_time = millis();
     while((millis()-start_time) < STime) //sample for 1 Sec
   {
     readValue = analogRead(sensorIn);

 #ifdef DEBUG     
// get min max only if you want to
if (readValue > maxvalue)
{
  maxvalue = readValue ;
}
      if (readValue < minvalue)
{
  minvalue = readValue ;
}
#endif

   
      
   //   SumSq = double(SumSq) +  double(sq((((double(readValue) - Zero) * double(ADCmaxVolt)) /  double(ADCRessolution))))*  double(1000)/ double(mVperAmp);
   //   Serial.print((((double(readValue) - Zero) * double(ADCmaxVolt)) /  double(ADCRessolution)));
       
       if (double(readValue - Offset) > Zero ) 
       {
           samplecountplus = samplecountplus +1 ;
           sumplus = sumplus + readValue ;
           SumSq = SumSq + sq((double(readValue) - double(Zero) - Offset ) * Calc)  ;
        }
      
      else if (double(readValue + Offset) < Zero ) 
       {
          samplecountminus = samplecountminus +1 ;
          summinus = summinus + readValue ;
        SumSq = SumSq + sq((double(readValue) - double(Zero) + Offset) * Calc)  ;
       }
       else
       {
        //   SumSq = SumSq + sq((double(readValue) - double(Zero)) * Calc)  ;
        //no point doing this if it is like 0
        
         if (ping)
         {
            samplecountplus = samplecountplus +1 ;
              sumplus = sumplus + readValue ;
              ping = false;
         }
          else
          {
             samplecountminus = samplecountminus +1 ;
            summinus = summinus + readValue ;
              ping = true;
         }
      
         samplecountzero = samplecountzero +1 ;
       
        
       }
   }

 if (samplecountzero == 0)
         {
          samplecountzero = 1;
         }

   
 if (samplecountminus == 0)
         {
          samplecountminus = 1;
         }

   
 if (samplecountplus == 0)
         {
          samplecountplus = 1;
         }
float plusavg = double(double(sumplus)/ double(samplecountplus)) ;
float minusavg = double(double(summinus)/ double(samplecountminus)) ;
float pmm =  double((plusavg - minusavg)/2) ; 
Amps = double(pmm * Calc);
  // result = ( (((double)(sumplus)/ samplecountplus)- ((double)(summinus)/ samplecountminus)) * ADCmaxVolt)/  ADCRessolution; //gets the milivolt difference betweene the values... old style

float meansq = SumSq / (double(samplecountplus + samplecountminus)) ;
float RMSCurrent = sqrt(meansq);


 #ifdef DEBUG
Serial.print(" min: ");
Serial.print(minvalue);
Serial.print(" max: ");
Serial.print(maxvalue);
Serial.print(" samples: ");
Serial.print(samplecountplus +samplecountminus);
Serial.print(" count plus: ");
Serial.print(samplecountplus);
Serial.print(" plus sum: ");
Serial.print(sumplus);
Serial.print(" count minus: ");
Serial.print(samplecountminus);
Serial.print(" minus sum: ");
Serial.print(summinus);
Serial.print(" count zero: ");
Serial.print(samplecountzero);
Serial.print(" zero this run: ");
Serial.print(Zero);
#endif
Zero = double(double(double(sumplus +summinus)/ double(samplecountplus+samplecountminus)) + Zero)/ 2; // prevent fast changes
#ifdef DEBUG
Serial.print(" avg and zero next: ");
Serial.print(Zero);
Serial.print(" plus avg: ");
Serial.print(plusavg);
Serial.print(" minus avg: ");
Serial.print(minusavg);
Serial.print(" Current: ");
Serial.print(Amps,4);
Serial.print(" RMS Current: ");
Serial.print(RMSCurrent,4);
Serial.print(" Power consumption: ");
Serial.print(RMSCurrent * VRMS ,4);
Serial.println("");
#endif
 
     
  // return (double(result)) ;
 
 }

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: current measure

#28 Post by pw444 » 02 Jan 2021, 18:00

Did it worked with ACS712?

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests