hi guys, i have problem with my Blynk. after uploading the code to Wemos D1 and opens blynk, my project continually connect and disconnect.
someone please help me 
this my code :
#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
#include<BlynkSimpleEsp8266.h>
BlynkTimer timer;
char auth [] = "xxxx";
char ssid [] = "xxxx";
char pass [] = "xxxx";
int distance, gas, motion;
SoftwareSerial wemos(D5, D6);
void ultrasonic() {
Blynk.virtualWrite(V1, distance);
if (distance <= 5) {
Blynk.notify("bak penuh") ;
}
}
void mq2() {
Blynk.virtualWrite(V2, gas);
if (gas >= 700) {
Blynk.notify("gas terdeteksi");
}
}
void pir() {
Blynk.virtualWrite(V3, motion);
if (gerakan == HIGH) {
Blynk.notify("gerakan terdeteksi");
}
}
void setup() {
Serial.begin(9600);
wemos.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode (D5, INPUT);
pinMode (D6 , OUTPUT);
timer.setInterval(500L, ultrasonic);
timer.setInterval(500L, mq2);
timer.setInterval(500L, pir);
}
String arrData[3] = ""; //3 sensor
void loop() {
Blynk.run();
timer.run();
String data = "";
//baca data yang diterima
while (Serial.available() > 0)
{
data += char (Serial.read());
}
//membuang spasi data
data.trim();
Serial.println(data);
//parsing data
int index = 0;
for (int i = 0; i < data.length(); i++)
{
char delimiter = '#'; //pemisah
if (data[i] != delimiter)
arrData[index] += data[i];
else
index++;
}
//tampilkan di serial monitor
Serial.println("Sensor Ultrasonic : " + arrData[0]);
Serial.println("Sensor PIR : " + arrData[1]);
Serial.println("Sensor MQ2 : " + arrData[2]);
Serial.println();
distance = arrData[0].toInt();
motion = arrData[1].toInt();
gas = arrData[3].toInt();
arrData[0] = "";
arrData[1] = "";
arrData[2] = "";
}
the connection is good, pin looks fine
but idk why my wemos canât connect to my blynk
sorry, my english is bad 
@Indra_Sitanggang please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Pete.
Your title mentions a Mega, but you are running the code on the Wemos D1. Whatâs this all about?
If you are actually managing to connect to Blynk using this code on your Wemos then the disconnections will be caused by your void loop.
Read this:
Pete.
look, i am doing a smart home project with serial communication between arduino and wemos, the program on arduino is running fine but after the wemos program i have a problem in the connection which keeps dropping on blynk. maybe youâre right in the void loop. can you help me find the right program for my wemos.
thanks
I think thatâs your first mistake when planning g the architecture of this system. Itâs far from the ideal way to approach a smart home project and a difficult communication timing challenge when working within Blynk.
A better solution would be to have one MCU doing everything (an ESP32 if you need multiple analog ports), or multiple MCUs that connect directly to Blynk and use Bridge code if needed.
But, whatever hardware architecture approach you adopt, you canât have a void loop that looks like that with Blynk. Youâll understand why if you read the âkeep your void loop cleanâ document I linked to.
Pete.
Iâve seen some video tutorials on Arduino and Esp serial communication using Blynk, and everything looks fine. I wonder whatâs wrong, is it better to use nodeMCU instead of wemos? I guess
No, they both use the same ESP8266 processor chip.
Itâs better, in my opinion, not to use the Arduino. Stick with devices that have native internet connectivity, and whatever you do donât go for one of those awful Arduino Mega and ESP8266 combined boards.
What does the Mega give you that canât be achieved with either an ESP8266 or ESP32 based board?
In that situation, Iâd suggest that you reach out to the authors of the videos, as its impossible to comment on some of the weird and wonderful things that some people choose to post videos about - especially when you donât cite your sources.
Pete.
2 Likes