I'm doing a project in which I'm monitoring the 3 voltages of 127V using 3 ZMPT101B sensors, using the library itself for the calculations.
After that, I'm passing a moving average filter to reduce network noise, and showing the values in an HTML page.
The problem is that when you turn off one of the voltages, all of them drop, instead of just turning off.
I wanted to know if there is a way to make the readings of the 3 sensors more "individual"?
Follow my code below:
#include <SPI.h
#include <Ethernet.h
#include "EmonLib.h"
#define LED1 44
#define LED2 45
#define LED3 46
//#define VOLT_CAL1 945.40
#define VOLT_CAL2 844.17
#define VOLT_CAL3 1220.85
#define num 22
EnergyMonitor emon1;
EnergyMonitor emon2;
EnergyMonitor emon3;
int statusger;
int gerador = A6;
String gert;
String FALTA1;
String FALTA2;
String FALTA3;
float tensaoR = 0;
float tensaoS = 0;
float tensaoT = 0;
long moving_average(int sig);
int values[num];
float adc_noise1,
adc_noise2,
adc_noise3;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(172, 22, 131, 12);
EthernetServer server(80);
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(300);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(A5,INPUT);
pinMode(A11,INPUT);
pinMode(A15,INPUT);
pinMode(gerador,INPUT);
emon1.voltage(5, VOLT_CAL2, 1.7);
emon2.voltage(11, VOLT_CAL2, 1.7);
emon3.voltage(15, VOLT_CAL3, 1.7);
}
//========================= MEDIÇÃO DAS TENSÕES COM FILTRO DE RUÍDO GAUSSIANO ===========================================//
void loop()
{
emon1.calcVI(20,2000);
tensaoR = emon1.Vrms; // FASE R
adc_noise1 = moving_average(tensaoR);
delay(100);
if(tensaoR >110){
digitalWrite(LED1, LOW);
FALTA1 = "OK";
}
else if (tensaoR <110){
digitalWrite(LED1, HIGH);
FALTA1 = "FORA";
}
emon2.calcVI(20,2000);
tensaoS = emon2.Vrms; // FASE S
adc_noise2 = moving_average(tensaoS);
delay(100);
if(tensaoS >110){
digitalWrite(LED2, LOW);
FALTA2 = "OK";
}
else if (tensaoS <110){
digitalWrite(LED2, HIGH);
FALTA2 = "FORA";
}
emon3.calcVI(20,1000);
tensaoT = emon3.Vrms; // FASE T
adc_noise3 = moving_average(tensaoT);
delay(100);
if(tensaoT <110){
digitalWrite(LED3, LOW);
FALTA3 = "OK";
}
else if (tensaoT >110){
digitalWrite(LED3, HIGH);
FALTA3 = "FORA";
}
//=========================GERADOR===========================================//
statusger = digitalRead (gerador);
if ( statusger == HIGH){
gert = "LIGADO";
}
else if
(statusger == LOW)
{
gert = "DESLIGADO";
}
//====================================================================//
//============================ PÁGINA HTML ========================================//
EthernetClient client = server.available();
if (client)
{
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
if (c == '\n' && currentLineIsBlank)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");
client.println("<link rel='shortcut icon' href='https://www.google.com/s2/favicons?domain=http://tvcultura.com.br/' type='image/x-icon'>");
client.println("<center>");
client.println("<font color=\"#000000\" size=\"9\" face=\"Black\"><strong> TORRE SUMARE</strong></font></td><td> </td></tr></table><br>");
client.println("<HR SIZE=15 font color=##008000>");
client.println("<title>TORRE SUMARE</title>");
client.println("<body>");
client.println("<h1>Medicao de energia eletrica </h1>");
client.println("<h>QDX TRIFASICO 380Vac - 13,8 KV </h>");
client.println("</body>");
client.println("<h1>FASE R </h1>");
client.println(adc_noise1,0);
client.print(F("Volts"));
client.println("<h1>FASE R </h1>");
client.println(FALTA1);
client.println("<h1>FASE S </h1>");
client.println(adc_noise2,0);
client.print(F("Volts"));
client.println("<h1>FASE S </h1>");
client.println(FALTA2);
client.println("<h1>FASE T </h1>");
client.println(adc_noise3,0);
client.print(F("Volts"));
client.println("<h1>FASE T </h1>");
client.println(FALTA3);
client.println("<h1> GRUPO GERADOR </h1>");
client.println(gert);
client.println("</body>");
client.println("</html>");
client.print("<meta http-equiv=\"refresh\" content=\"15 \">");
break;
}
if (c == '\n')
{
currentLineIsBlank = true;
}
else if (c != '\r')
{
currentLineIsBlank = false;
}
}
}
delay(10);
client.stop();
}
}
long moving_average(int sig){
int i;
long acc = 0;
for(i = num; i > 0; i--) values[i] = values[i-1];
values[0] = sig;
for(i = 0; i < num; i++) acc += values[i];
return acc / num;
}
//================================================================================================================================================================//