I'm using an ACS712 (20amp I think, doesn't matter at the moment) with a code I found. The code works as intended and I get it to run with a single sensor unit all fine and dandy. I am however trying to monitor a three-phase motor's current draw to make sure there isn't any problems with it in a long-term run.
I've tried to add other inputs by adding more running statistics and AO inputs and adding input statistics but I'm having no luck.
Also I'm rather new to the software side so any enlightenment would be highly appreciated.
So several questions pop into my head when I see this.
1.) Why is there a while(true) command in the void loop function. I thought while true was a void loop (or so I've seen in my limited understanding from Pi pico and arduino)
2.) Can this be used to actually measure multiple sensors and if so where would I mallet the code into it?
3.) Not a question but I have hooked up a cute nokia screen to the system for a display and that works.
Thanks in advance.
Code:
#include <Filters.h> //This library does a massive work check it's .cpp file
#define ACS_Pin A2 //Sensor data pin on A0 analog input
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.1; // to be adjusted based on calibration testing
float slope = 0.0752; // to be adjusted based on calibration testing
//Please check the ACS712 Tutorial video by SurtrTech to see how to get them because it depends on your sensor, or look below
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;
void setup() {
Serial.begin( 9600 ); // Start the serial port
pinMode(ACS_Pin,INPUT); //Define the pin mode
}
void loop() {
RunningStatistics inputStats; // create statistics to look at the raw test signal
inputStats.setWindowSecs( windowLength ); //Set the window length
while( true ) {
ACS_Value = analogRead(ACS_Pin); // 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();
Serial.print( "\t Amps: " );
Serial.print( Amps_TRMS );
Serial.print( "\t Sigma: " );
Serial.println( inputStats.sigma());
}
}
}
Also I'm rather new to the software side so any enlightenment would be highly appreciated.
So several questions pop into my head when I see this.
1.) Why is there a while(true) command in the void loop function. I thought while true was a void loop (or so I've seen in my limited understanding from Pi pico and arduino)
2.) Can this be used to actually measure multiple sensors and if so where would I mallet the code into it?
3.) Not a question but I have hooked up a cute nokia screen to the system for a display and that works.
Thanks in advance.