Correct values on Serial Monitor, but wrong values to Blynk


Hi everyone,

I was hoping someone can help me out. My project checks the water level in my tank using jsn-sr04t to measure the distance on a nodeMCU…sending values to blynk via SIM800L. My project seems to work from a serial monitor perspective, but values are not sending correctly to blynk. Currently, my sketch runs and prints the output correctly to serial monitor as below. Goes to sleep, and then wakes again to do the same. What am i doing wrong? At the moment, its seems that only V1 is actually sending to blynk app. All the other values are blank on my app. Any help would be appreciated.


Initializing modem...
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.4 on NodeMCU

[9096] Modem init...
[9921] Connecting to network...
[15607] Network: 65502
[15607] Connecting to  ...
[20593] Connected to GPRS
[20606] Connecting to
[22575] Ready (ping: 853ms).

Tank - water distance: 73
Tank - water depth: 147
Tank - Litres: 3824
Tank - Percentage: 76
#include <NewPing.h>
#define BLYNK_PRINT Serial
#include <TinyGsmClient.h>
#include <SoftwareSerial.h>
#include <BlynkSimpleSIM800.h>
#define SIM800_TX_PIN 12
#define SIM800_RX_PIN 13
#define uS_TO_m_FACTOR 60000000   // Conversion factor for micro seconds to minutes

char auth[] = "xxxxxxxx";
char apn[]  = "";
char user[] = "";
char pass[] = "";
const int sleepTimeM = 5;
const int MAX_DISTANCE = 225;                       //max distance to measure
const int Diameter1 = 182;                                //internal Diameter of tank 1 in cm
const int Depth1 = 220;                                 //total depth of tank 1 in cm , from sensor to base inside
const unsigned int Period = 60000;    //period between pings, in milliseconds. i.e  1 munute = 60,000. max 65535. Want longer? use unsigned long
const int PingPin1 = 5;                          //     GPIO5,  D1
const int EchoPin1 = 4;                        //     GPIO4,  D2
const int Area1 = PI * ((Diameter1 / 2) * (Diameter1 / 2));          //area of base of tank 1
int Litres1, Distance1, WaterDepth1, Decimal, Persentage;

#include <SoftwareSerial.h>
SoftwareSerial SerialAT(SIM800_TX_PIN, SIM800_RX_PIN);
TinyGsm modem(SerialAT);
BlynkTimer timer;
NewPing sonar = NewPing(PingPin1, EchoPin1, MAX_DISTANCE);

void setup()
  // Debug console
  Serial.println("Initializing modem...");
  Blynk.begin(auth, modem, apn, user, pass);
  Distance1 = sonar.ping_cm();                                       //get distance to the top of the water tank 1
  if (Distance1 >= Depth1 || Distance1 == 0 )  Distance1 = Depth1;                   //check it does not go negative
  WaterDepth1 = Depth1 - Distance1;                     //calculate the depth of the water
  Litres1 = (Area1 * WaterDepth1) / 1000;                          //calculate the volume of the water in litres
  Persentage = (Litres1 / 5000.00) * 100;  //Get persentage
  Serial.println("Tank - water distance: " + String(Distance1));   //print depth
  Blynk.virtualWrite(V2, Litres1);
  Serial.println("Tank - water depth: " + String(WaterDepth1));  //print depth
  Blynk.virtualWrite(V1, WaterDepth1);
  Serial.println("Tank - Litres: " + String(Litres1));
  Blynk.virtualWrite(V3, Litres1 / 10);
  Serial.println("Tank - Percentage: " + String(Persentage));                //print litres
  Blynk.virtualWrite(V4, Persentage);
  ESP.deepSleep(sleepTimeM * uS_TO_m_FACTOR, WAKE_RF_DEFAULT); // Sleep for 5 Minutes

void loop()


I don’t see; anywhere in your void loop() or void setup()


Thanks, Gunner… without changing anything else in my code, ive added; into the void loop and uploaded it to the nodeMCU. At first, I got one more value in the app (wrong value, but something at least) Then after a few more runs I now have all the values sync to the app.?? !

See values printed in serial and values on app screenshot complete different??

Weird…maybe blynk server delay? I dunno?

[9395] Modem init...
[10075] Connecting to network...
[16022] Network: 65502
[16022] Connecting to  ...
[22724] Connected to GPRS
[22737] Connecting to
[24727] Ready (ping: 855ms).

Tank - water distance: 73
Tank - water depth: 147
Tank - Litres: 3824
Tank - Percentage: 76


Not sure about the rest… but assuming you have like grouped with like… your variables are different between the Serial print and the Blynk print on these two at least.

And since I haven’t worked with any MCU sleep modes yet, this is just a guess… but, perhaps due to timing or something, is the App showing the preceding values from the readings 5 mins ago?


Ooh, ok, i see what i did there…will fix once I get home. Thx Gunner !!
As for the rest, maybe I should add a few delays, maybe the sleep happens too fast, or something. Will update once Ive tried a few more things


Just what every Blynk sketch needs. The more the better :rofl: