I am having Arduino Uno, SIM800 GSM module and PZEM 004T, 100 A module.
I want to build a project to view PZEM parametrs such as Voltage, Current, Power etc. through IoT application. For this I am using Blynk application through GSM/ GPRS Module.
The problem with me is that while connecting Arduino uno with both GSM module and PZEM module, it doesn’t work together.
Instead, if any one of them is used, it works fine.
Probably I am not able to use two serial ports or can’t communicate with two hardwares.
The code is as below:
#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
#include <PZEM004Tv30.h>
PZEM004Tv30 pzem(11, 12); //RX of PZEM to 12, TX of PZEM to 11
float voltage, current, power, energy, frequency, pf;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "my Auth Token";
char apn[] = "internet";
char user[] = "";
char pass[] = "";
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(6, 9); // SIM900 RX, TX with #9, #6
BlynkTimer timer;
TinyGsm modem(SerialAT);
void sendSensor(){
voltage = pzem.voltage();
current = pzem.current();
power = pzem.power();
energy = pzem.energy();
frequency = pzem.frequency();
pf = pzem.pf();
Blynk.virtualWrite(V0,voltage);
Blynk.virtualWrite(V1,current);
Blynk.virtualWrite(V2,power);
Blynk.virtualWrite(V3,energy);
Blynk.virtualWrite(V4,frequency);
Blynk.virtualWrite(V5,pf);
}
void setup()
{
// Debug console
Serial.begin(9600);
delay(10);
// Set GSM module baud rate
SerialAT.begin(9600);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
modem.restart();
// Unlock your SIM card with a PIN
//modem.simUnlock("1234");
Blynk.begin(auth, modem, apn, user, pass);
timer.setInterval(10000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
The output on serial monitor shows connected to Blynk cloud server, but after few seconds probably due to PZEM module run, the blynk stops and again tries to connect to cloud server. And again stops.
Can anybody please help me.
In there any way out?
I want to do the project with these available materials only.