• Hardware model = arduino with sim 800l + 2 capteur : asc712 and zmpt101b
• Android version:2.27.34
• local server
i can’t stay connected and I can’t control the actuators What makes interference in the programming between the sensors code and Blynk code
#define BLYNK_TEMPLATE_ID "TMPLxxxxxx"
#define BLYNK_DEVICE_NAME "Device"
#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800
#define BLYNK_HEARTBEAT 60
#include <BlynkSimpleSIM800.h>
#include <TinyGsmClient.h>
#include "ACS712.h"
#include "EmonLib.h"
#include <Filters.h>
#define vCalibration 106.8
#define currCalibration 0.52
EnergyMonitor emon;
char auth[] = "N46Z45yasSLc-tw3EgfgTlKiY18b*****";
char apn[] = "YourAPN";
char user[] = "";
char pass[] = "";
char server[] = "197.***.**.**";
int port = 8080;
const int sensorIn = A2;
int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;
float testFrequency = 50;
float windowLength = 100 / testFrequency;
int RawValue = 0;
float Volts_TRMS;
float intercept = 0;
float slope = 1;
unsigned long printPeriod = 1000; //Measuring frequency, every 1s, can be changed
unsigned long previousMillis = 0;
RunningStatistics inputStats;
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(5, 4); // RX, TX
TinyGsm modem(SerialAT);
BlynkTimer timer;
float kWh = 0;
unsigned long lastmillis = millis();
WidgetTerminal terminal(V4);
void myTimerEvent()
{
emon.calcVI(20, 2000);
/*Serial.print("Vrms: ");
Serial.print(emon.Vrms, A6);
Serial.print("V");*/
Blynk.virtualWrite(V0, emon.Vrms);
/*Serial.print("\tIrms: ");
Serial.print(emon.Irms, A2);
Serial.print("A");*/
Blynk.virtualWrite(V1, emon.Irms);
/*Serial.print("\tPower: ");
Serial.print(emon.apparentPower, 4);
Serial.print("W");*/
Blynk.virtualWrite(V2, emon.apparentPower);
//Serial.print("\tkWh: ");
kWh = kWh + emon.apparentPower * (millis() - lastmillis) / 3600000000.0;
/*Serial.print(kWh, 4);
Serial.println("kWh");*/
Blynk.virtualWrite(V3, kWh);
lastmillis = millis();
Blynk.virtualWrite(V12, digitalRead(2));
Blynk.virtualWrite(V13, digitalRead(3));
Blynk.virtualWrite(V14, analogRead(A2));
Blynk.virtualWrite(V15, analogRead(A6));
//ignoring the value below 0.09
Voltage = getVPP();
VRMS = (Voltage / 2.0) * 0.707;
AmpsRMS = (VRMS * 1000) / mVperAmp;
Blynk.virtualWrite(V14, 0.9 * AmpsRMS * 110); // To Gauge Widget @ .9pf and 110vac
terminal.print(AmpsRMS); // To Terminal Widget
terminal.print(" Amps - ");
terminal.flush();
}
float getVPP() {
float result;
int readValue; //value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1023; // store min value here
uint32_t start_time = millis();
while ((millis() - start_time) < 1500) { // sample for 1 Sec
readValue = analogRead(sensorIn); // see if you have a new maxValue
if (readValue > maxValue) {
maxValue = readValue; // record the maximum sensor value
}
if (readValue < minValue) {
minValue = readValue; // record the minimum sensor value
}
}
// Subtract min from max
result = ((maxValue - minValue) * 5.0) / 1023.0;
return result;
}
void ac_read() {
int rVal = 0;
int sampleDuration = 100; // 100ms
int sampleCount = 0;
unsigned long rSquaredSum = 0;
int rZero = 511; // For illustrative purposes only - should be measured to calibrate sensor.
uint32_t startTime = millis(); // take samples for 100ms
while ((millis() - startTime) < sampleDuration) {
rVal = analogRead(A2) - rZero;
rSquaredSum += rVal * rVal;
sampleCount++;
}
double voltRMS = 5.0 * sqrt(rSquaredSum / sampleCount) / 1024.0;
// x 1000 to convert volts to millivolts
// divide by the number of millivolts per amp to determine amps measured
// the 20A module 100 mv/A (so in this case ampsRMS = 10 * voltRMS
double ampsRMS = voltRMS * 6.6;
}
void setup()
{
// Debug console
Serial.begin(115200);
delay(10);
// Set GSM module baud rate
SerialAT.begin(9600);//115200
delay(3000);
Serial.println("Initializing modem...");
modem.restart();
inputStats.setWindowSecs( windowLength );
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(A0, OUTPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(A2, INPUT);
pinMode(A6, INPUT);
emon.voltage(35, vCalibration, 1.7); // Voltage: input pin, calibration, phase_shift
emon.current(34, currCalibration); // Current: input pin, calibration.
Blynk.begin(auth, modem, apn, user, pass, server, port);
timer.setInterval(9000L, myTimerEvent);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(12, LOW);
digitalWrite(A0, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(13, LOW);
}
void loop()
{
Blynk.run();
timer.run();
}