CURRENT MEASUREMENT BY ACS712

ACS712

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/CURRENT_ACS712.zip

#include <Filters.h>

float testFrequency = 60; // test signal frequency (Hz)
float windowLength = 20.0/testFrequency; // how long to average the signal, for statistist
int sensorValue = 0;
float intercept = -0.1129; // to be adjusted based on calibration testing
float slope = 0.0405; // to be adjusted based on calibration testing
float current_amps; // estimated actual current in amps

unsigned long printPeriod = 100; // in milliseconds
// Track time in milliseconds since last reading
unsigned long previousMillis = 0;

void setup() {
Serial.begin( 9600 ); // start the serial port
}

void loop() {
RunningStatistics inputStats; // create statistics to look at the raw test signal
inputStats.setWindowSecs( windowLength );

while( true ) {
sensorValue = analogRead(A0);
inputStats.input(sensorValue);
if((unsigned long)(millis() – previousMillis) >= printPeriod) {
previousMillis = millis(); // update time

Serial.print(“\n” );
Serial.print( “\tsigma: ” );
Serial.print( inputStats.sigma() );
current_amps = intercept + slope * inputStats.sigma();
Serial.print( “\tamps: ” );
Serial.println( current_amps );

}
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s