Can someone help me with my problem? I can't fix my code. I try to measuring voltage using esp32 and 2 ZMPT101B sensors but it can't work (when i only use 1 sensor zmpt101b it the code work, but when i duplicate the code like this, the code doesn't work for both sesnosrs
while( true ) {
Sensor_1 = analogRead(34); // read the analog in value:
inputStats.input(Sensor_1); // log to Stats function
Sensor_2 = analogRead(35); // read the analog in value:
inputStats.input(Sensor_2); // log to Stats function
if((unsigned long)(millis() - previousMillis) >= printPeriod) {
previousMillis = millis(); // update time every second
Tegangan1= (intercept + slope * inputStats.sigma())*(49.3231); //Calibartions for offset and amplitude
Tegangan2= (intercept + slope * inputStats.sigma())*(49.3231); //Calibartions for offset and amplitude
Serial.print( "Tegangan 1: " );
Serial.println( Tegangan1 );
Serial.print( "Tegangan 2: " );
Serial.println( Tegangan2 );
}
here is my code
#include <Filters.h>
float testFrequency = 50; // signal frequency (Hz)
float windowLength = 100.0/testFrequency; // how long to average the signal, for statistist
int Sensor_1 = 0;
int Sensor_2 = 0;
float intercept = 0; // adjust untuk kalibrasi
float slope = 0.01245; // adjust untuk kalibrasi
float Tegangan1;
float Tegangan2;
unsigned long printPeriod = 1000; //Refresh rate
unsigned long previousMillis = 0;
void setup() {
Serial.begin( 9600 );
Serial.println("AC Voltmeter");
//delay(5000);
}
void loop() {
RunningStatistics inputStats;
inputStats.setWindowSecs( windowLength );
while( true ) {
Sensor_1 = analogRead(34); // read the analog in value:
inputStats.input(Sensor_1); // log to Stats function
Sensor_2 = analogRead(35); // read the analog in value:
inputStats.input(Sensor_2); // log to Stats function
if((unsigned long)(millis() - previousMillis) >= printPeriod) {
previousMillis = millis(); // update time every second
Tegangan1= (intercept + slope * inputStats.sigma())*(49.3231); //Calibartions for offset and amplitude
Tegangan2= (intercept + slope * inputStats.sigma())*(49.3231); //Calibartions for offset and amplitude
Serial.print( "Tegangan 1: " );
Serial.println( Tegangan1 );
Serial.print( "Tegangan 2: " );
Serial.println( Tegangan2 );
}
}
}