Skip to main content
added 8 characters in body
Source Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50

Thank you all for your time dedication. Finally increasing the sampling and optimize the same codes I could achieve my goals. I will post the functioning code for those who might need it.

float readRMS(int pin, int vref) {

int lecturas[200]; // declaring the matrix

float suma = 0; // sum of the squares

float rms = 0; // squares mean

float volt = 0; //

float Volt_Final = 0;

for (int cont = 0; cont < 200; cont++) {

float readRMS(int pin, int vref) {

  int lecturas[200]; // declaring the matrix

  float suma = 0; // sum of the squares

  float rms = 0;  // squares mean

  float volt = 0;  // 

  float Volt_Final = 0;

  for (int cont = 0; cont < 200; cont++) { 

    lecturas[cont] = analogRead(pin);  

    delayMicroseconds(200);           

} for (int j = 0; j < 200; j++) {

  }
  for (int j = 0; j < 200; j++) { 

    //Serial.println(lecturas[j]); 

    suma = suma + pow((lecturas[j] - vref), 2);
 
    //Serial.println(suma);
  }
  rms = sqrt((suma / 200));

  volt = (rms / 1024) * 5; 

  //Serial.println(volt);

  //suma=0;

  // Reset variables for the next RMS calculation

  rms = 0;

  lecturas[200] = 0;

  //Volt_Final = (volt * 4.31); //real voltage with circuit gain

  return volt;
}

} rms = sqrt((suma / 200));

volt = (rms / 1024) * 5;

//Serial.println(volt);

//suma=0;

// Reset variables for the next RMS calculation

rms = 0;

lecturas[200] = 0;

//Volt_Final = (volt * 4.31); //real voltage with circuit gain

return volt; }

Thank you all for your time dedication. Finally increasing the sampling and optimize the same codes I could achieve my goals. I will post the functioning code for those who might need it.

float readRMS(int pin, int vref) {

int lecturas[200]; // declaring the matrix

float suma = 0; // sum of the squares

float rms = 0; // squares mean

float volt = 0; //

float Volt_Final = 0;

for (int cont = 0; cont < 200; cont++) {

lecturas[cont] = analogRead(pin);  

delayMicroseconds(200);           

} for (int j = 0; j < 200; j++) {

//Serial.println(lecturas[j]); 

suma = suma + pow((lecturas[j] - vref), 2);

//Serial.println(suma);

} rms = sqrt((suma / 200));

volt = (rms / 1024) * 5;

//Serial.println(volt);

//suma=0;

// Reset variables for the next RMS calculation

rms = 0;

lecturas[200] = 0;

//Volt_Final = (volt * 4.31); //real voltage with circuit gain

return volt; }

Thank you all for your time dedication. Finally increasing the sampling and optimize the same codes I could achieve my goals. I will post the functioning code for those who might need it.

float readRMS(int pin, int vref) {

  int lecturas[200]; // declaring the matrix

  float suma = 0; // sum of the squares

  float rms = 0;  // squares mean

  float volt = 0;  // 

  float Volt_Final = 0;

  for (int cont = 0; cont < 200; cont++) { 

    lecturas[cont] = analogRead(pin);  

    delayMicroseconds(200);           
  }
  for (int j = 0; j < 200; j++) { 

    //Serial.println(lecturas[j]); 

    suma = suma + pow((lecturas[j] - vref), 2);
 
    //Serial.println(suma);
  }
  rms = sqrt((suma / 200));

  volt = (rms / 1024) * 5; 

  //Serial.println(volt);

  //suma=0;

  // Reset variables for the next RMS calculation

  rms = 0;

  lecturas[200] = 0;

  //Volt_Final = (volt * 4.31); //real voltage with circuit gain

  return volt;
}
Source Link

Thank you all for your time dedication. Finally increasing the sampling and optimize the same codes I could achieve my goals. I will post the functioning code for those who might need it.

float readRMS(int pin, int vref) {

int lecturas[200]; // declaring the matrix

float suma = 0; // sum of the squares

float rms = 0; // squares mean

float volt = 0; //

float Volt_Final = 0;

for (int cont = 0; cont < 200; cont++) {

lecturas[cont] = analogRead(pin);  

delayMicroseconds(200);           

} for (int j = 0; j < 200; j++) {

//Serial.println(lecturas[j]); 

suma = suma + pow((lecturas[j] - vref), 2);

//Serial.println(suma);

} rms = sqrt((suma / 200));

volt = (rms / 1024) * 5;

//Serial.println(volt);

//suma=0;

// Reset variables for the next RMS calculation

rms = 0;

lecturas[200] = 0;

//Volt_Final = (volt * 4.31); //real voltage with circuit gain

return volt; }