Sensor Data not displayed and Device Keeps Disconnecting

Everytime I try to connect my device to the Blynk app, it connects for a minute or two, then automatically says EVENT_CLOSE, received EOF, and disconnects. The auth token is the same, the com and baud rate are both the ones on the code, I’m keeping the window open the whole time.
Additionally, none of my sensor data is being displayed though I have used the virtual pins correctly. Can someone please help?

//fall detection
#include <Wire.h>
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
float ax=0, ay=0, az=0, gx=0, gy=0, gz=0;

//int data[STORE_SIZE][5]; //array for saving past data
//byte currentIndex=0; //stores current data array index (0-255)
boolean fall = false; //stores if a fall has occurred
boolean trigger1=false; //stores if first trigger (lower threshold) has occurred
boolean trigger2=false; //stores if second trigger (upper threshold) has occurred
boolean trigger3=false; //stores if third trigger (orientation change) has occurred

byte trigger1count=0; //stores the counts past since trigger 1 was set true
byte trigger2count=0; //stores the counts past since trigger 2 was set true
byte trigger3count=0; //stores the counts past since trigger 3 was set true
int angleChange=0;
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define BLYNK_PRINT DebugSerial
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial (2,3); // RX, TX
#include <BlynkSimpleStream.h> 
char auth[] = "XGTJ9FJkD8tr0f9KFG7WoxFC6oksNOTR";

BlynkTimer timer;

void setup()


 Wire.write(0x6B);  // PWR_MGMT_1 register
 Wire.write(0);     // set to zero (wakes up the MPU-6050)


 pinMode(11, OUTPUT);
void sendSensor()
  //for fall detection

 //2050, 77, 1947 are values for calibration of accelerometer
 // values may be different for you
 ax = (AcX-2050)/16384.00;
 ay = (AcY-77)/16384.00;
 az = (AcZ-1947)/16384.00;

 //270, 351, 136 for gyroscope
 gx = (GyX+270)/131.07;
 gy = (GyY-351)/131.07;
 gz = (GyZ+136)/131.07;

 // calculating Amplitute vactor for 3 axis
 float Raw_AM = pow(pow(ax,2)+pow(ay,2)+pow(az,2),0.5);
 int AM = Raw_AM * 10;  // as values are within 0 to 1, I multiplied 
                        // it by for using if else conditions 

 if (trigger3==true){
    if (trigger3count>=10){ 
       angleChange = pow(pow(gx,2)+pow(gy,2)+pow(gz,2),0.5);
       if ((angleChange>=0) && (angleChange<=10)){ //if orientation changes remains between 0-10 degrees
           fall=true; trigger3=false; trigger3count=0;
       else{ //user regained normal orientation
          trigger3=false; trigger3count=0;
 if (fall==true){ //in event of a fall detection
Blynk.notify("the patient has fallen down!");
  // exit(1);
 if (trigger2count>=6){ //allow 0.5s for orientation change
   trigger2=false; trigger2count=0;
 if (trigger1count>=6){ //allow 0.5s for AM to break upper threshold
   trigger1=false; trigger1count=0;
 if (trigger2==true){
   angleChange = pow(pow(gx,2)+pow(gy,2)+pow(gz,2),0.5); 
   if (angleChange>=30 && angleChange<=400){ //if orientation changes by between 80-100 degrees
     trigger3=true; trigger2=false; trigger2count=0;
 if (trigger1==true){
   if (AM>=12){ //if AM breaks upper threshold (3g)
     trigger1=false; trigger1count=0;
 if (AM<=2 && trigger2==false){ //if AM breaks lower threshold (0.4g)
//It appears that delay is needed in order not to clog the port

 Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
 Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers<<8|;  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)<<8|;  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)<<8|;  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)<<8|;  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)<<8|;  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)<<8|;  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)<<8|;  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
//for sound sensor
void soundSensor()
    int sensorVal=analogRead(A0);

if (sensorVal>=500){
  Blynk.notify("a shout or loud noise detected near/from the patient");
else {
  void tempSensor () {
 // Blynk.virtualWrite(V5,millis()/1000);
  float temperature = sensors.getTempCByIndex(0) * 9.0 / 5.0 + 32.0;
if (temperature>=100){
  Blynk.notify("the patient's temperature is over 100");
if (temperature<=95){
  Blynk.notify("the patient's temperature is below 95");

void loop ()


What MCU are you using?
Is your sensor data being displayed in the Serial Monitor?

You are using One_Wire_Bus on GPIO4

If you are connecting the MPU-6050 via I2C, then GPIO4 is also I2C SDA pin.


I am using the Arduino Nano, and yes, it’s being displayed in the serial monitor on the app.
The ONE Wire Bus part is for the ds18b20 temperature sensor.

I’m sorry, I’m a beginner, but do you mean to say that the analog pin I connected the MPU 6050 through via the SDA pin should also be connected to the temperature sensor’s data pin?

What exactly does this mean, and what data are you seeing?

Do you have an FTDI adapter attached to pins 2&3?


Sorry for being vague. I mean to say that when I view data on the serial monitor, it’s working just fine. For instance, the temperature sensor will display the temperature on the serial monitor but not on the app when I try to connect it with Blynk. Additonally, on the serial monitor I can view the sound values from the sound sensor between 0-1023 and the code before Blynk had the arduino display “FALL DETECTED” on the serial monitor when a fall was detected.

Now, I have taken of most of the Serial.print and replaced them with what I want them to do in the blynk app (display data or a notification on the phone). No, I do not have this adapter. Is there a way for me to connect my Arduino Nano through a USB to Blynk without using the adapter?

No, not really.
Without an adapter you have no real debugging tools available to you, so it’s difficult to say what is causing your issue.
I guess one possible cause may be lack of memory, what does the compiler say about this?

Ultimately, your finished project isn’t going to use the USB connection method is it?
Maybe now is the time to swap to a NodeMCU or similar and that removes the need for an FTDI adapter when connecting via WiFi.


The code compiles without any issue. No, but for the moment, I am going to be working with a USB connection, so while I’m waiting on a Wi-fi module, is there really nothing I can do to resolve the issue? Is there any problem with my code like I’m not connecting to Blynk correctly?

That wasn’t what I was asking. I wanted to know how much memory is used/free. It tells you this when you compile the code.


Oh, sorry. It uses 55% of the program storage space.

Program Storage Space is half of the story.
What about Dynamic Memory?


That would be 54%

Okay, those numbers look fine.
Without seeing debug information its impossible to say if it’s issues like slow ping time, or what the cause of the disconnection was (heartbeat timeout etc).

I really hope that you’re not going to use an ESP-01 as the WiFi adapter for your Nano.


Oh okay. So it’s not a problem with the code? I want to rule the code out before I try again.

I was thinking of the ESP - 8266 Wifi module.

That could mean anything.
My point is that adding a ESP8266 of some type as a WiFi adapter to your Nano is just compounding your problems.
You should use an ESP8266 based dev board (not an ESP-01) such as the NodeMCU or Wemos D1 Mini as your board, rather the Nano plus an ESP8266.

Read this…


I’ll check it out!