BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

No data Shown on Blynk app (sensor reading Arduino Nano and SW420)

Hello Guys

I am creating a project just to test blynk, and i want to make a vibration monitoring for this. I’m using an arduino nano as the board and SW420 for the vibration sensor. the connection to my phone is made using Serial USB and im using blynk IOT.

I can confirm that it is connected because I have set a button from blynk D13 to trigger LED on my Nano and it works. but for some reason I am unable to get data from the SW420 to show on my phone. The sensor also works because the LED on the sensor and my Nano blinked rapidly when I shake it. I’m still quite new to this, below is the full code

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID           "TMPLxxxxxx"
#define BLYNK_DEVICE_NAME           "Device"
#define BLYNK_AUTH_TOKEN            "YourAuthToken"

#include <SimpleTimer.h>
#include <SoftwareSerial.h>
#include <BlynkSimpleStream.h>

// Comment this out to disable prints and save space



char auth[] = "TKVUcDT-LFXAZCt730fQlz73O6CXIFv8";
int vs = 2;
int sdata = 0;


SimpleTimer timer;

String vdata = "";

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() / 1000);
}

void setup()
{
  // Debug console
  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  pinMode(vs ,INPUT);
  Blynk.begin(Serial, auth);

  timer.setInterval(10L,sensorvalue); // 1000L
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer

}
void sensorvalue()
{
  long measurement =vibration();
 //delay(50);
  Serial.println(measurement);
  Blynk.virtualWrite(V3, measurement);
 
vdata = vdata + "Vibration: " + measurement;  
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V2, vdata);
vdata = ""; 
}

long vibration(){
  delay(10);
  long measurement=pulseIn (vs, HIGH);  //wait for the pin to get HIGH and returns measurement
  return measurement;
}


How did you configure your datastream ?

Are you saying that the Nano is physically connected to your phone using a serial cable, and that you are running the USB connection script on your phone?

Pete.

I Basically using the blynk virtual server in the blynk library on my computer

@echo off
setlocal EnableDelayedExpansion

REM === Edit these lines to match your need ===

set COMM_PORT=COM20
set COMM_BAUD=9600
set SERV_ADDR=blynk-cloud. com
set SERV_PORT=8442

REM === Edit lines below only if absolutely sure what you're doing ===

rem Get command line options
set SCRIPTS_PATH=%~dp0

:loop
IF NOT "%1"=="" (
    IF "%1"=="-c" set COMM_PORT=%2& SHIFT & SHIFT & GOTO :loop
    IF "%1"=="-b" set COMM_BAUD=%2& SHIFT & SHIFT & GOTO :loop
    IF "%1"=="-s" set SERV_ADDR=%2& SHIFT & SHIFT & GOTO :loop
    IF "%1"=="-p" set SERV_PORT=%2& SHIFT & SHIFT & GOTO :loop

    CALL :usage
    GOTO :eof
)

rem Find ports
set PORTS=
for /f "tokens=4 delims=: " %%A in ('mode^|findstr "COM[0-9]*:"') do IF not [%%A] == [] set PORTS=!PORTS! %%A
set PORTS=!PORTS:~1!

rem Check port
rem Skip check if no ports at all - Windows bug?
if not "x%PORTS%"=="x~1" (
    if "x!PORTS:%COMM_PORT%=!"=="x%PORTS%" (
        echo %COMM_PORT% not found, or may be busy.
        set /p COMM_PORT="Select serial port [ %PORTS% ]: "
    )
)

rem Create exe
if not exist "%SCRIPTS_PATH%\com2tcp.exe" (
    copy "%SCRIPTS_PATH%\com2tcp.bin" "%SCRIPTS_PATH%\com2tcp.exe" > NUL
)

rem Do the job
echo Connecting device at %COMM_PORT% to %SERV_ADDR%:%SERV_PORT%...

rem Try resetting board
rem mode %COMM_PORT%:%COMM_BAUD%,N,8,1 >nul

:restart
  "%SCRIPTS_PATH%\com2tcp.exe" --baud %COMM_BAUD% --ignore-dsr \\.\%COMM_PORT% %SERV_ADDR% %SERV_PORT%
  echo Reconnecting in 3s...
  timeout /T 3
goto restart


goto:eof

:usage
    echo.
    echo.   This script redirects serial communication to the server.
    echo.
    echo.   You can specify port, baud rate, and server endpoint like this:
    echo.     blynk-ser.bat -c ^<serial port^> -b ^<baud^> -s ^<server^> -p ^<port^>
    echo.
    echo.   The defaults are:
    echo.     -c    /dev/ttyUSB0       (on Linux)
    echo.           COM1               (on Windows)
    echo.           /dev/tty.usbserial (on OSX)
    echo.     -b    9600
    echo.     -s    blynk-cloud.com
    echo.     -p    80
    echo.
    echo.   If the specified serial port is not found, it will ask to enter another one.
    echo.   The script also tries to reestablish connection if it was lost.
goto:eof

here is the configuration from the blynk-ser.bat file in Documents > Arduino > Library > blynk > scripts , I only change at the beginning of the script the comm_port and serv_port (default serv port 80)

Screenshots

this are the setup screenshot on my phone

No, the config is i connect my nano and stuff to my PC > i set the virtual server on blynk-serv.bat on the pc > and my pc connected to the internet/wifi > then it connect to my phone via wifi/internet

You’re reading the sensor value 100 times per second, try 1000 instead of 10.

I tried this before no luck. I tried to change the server port thinking that might work but no dice either

You can’t be connecting to the the Blynk IoT cloud server using this setting in your batch file, as this will attempt to connect to the Legacy cloud servers.

Pete.

how can i connect to the iot cloud? is there a specific library or settings i should add or do? the server address was set from the library.

Read this…

Pete.

ok I’ve tried that solution. the connection is goind on and off and no connection to my phone, I’ve changed the port to 80 and 8080 but still the same I tried the 8440 port and it timed out

Screenshot 2021-11-23 171227

and also I forgot to say this but when i used blynk-cloud.com it says the same but it got connected, i read from the solved forum it says offline but not connected but in my case it’s connected

Screenshot 2021-11-23 171540

In that case, you aren’t using a Blynk IoT Auth token or a Blynk IoT sketch with a valid template ID.

It would help if you provided more information, such as app version, library version etc.

It would also help if you used the correct term8nology. You aren’t running a virtual server on your PC, you are running a script which allows internet communication via the USB port.
Also, your device isn’t connecting to your phone, it’s connecting to the Blynk cloud server, which your phone is also connecting to.

Pete.

for the library im using version 1.0.1 and the blynk app is 2.27.32(04.09.2021 20:45:54), I might get confused here because there are 2 (maybe) blynk platform here and I moght got it mixed up. I just started to learn about this and might get a little confused. and im following this Tutorial

You are using Blynk Legacy, not Blynk IoT

You need to downgrade your library to 0.6.1 and undo the changes you’ve made to the USB script.

You also need to remove this line…

as it will send debug data to the serial port which is being used for your USB communication with the Blynk server.

You should also remove these lines:

as they relate to Blynk IoT.

Pete.

ok i have downgrade it to 0.6.1 and remove some stuff from the code, but im still unable to get it to show. i check from the tutorial they used WidgetTerminal and i manage to get m to show on th terminal but the data is not showing. here is the modified code

#include <SimpleTimer.h>
#include <SoftwareSerial.h>
#include <BlynkSimpleStream.h>

SoftwareSerial SwSerial(10, 11); // RX, TX
// Comment this out to disable prints and save space

#define BLYNK_PRINT SwSerial

char auth[] = "TKVUcDT-LFXAZCt730fQlz73O6CXIFv8";
int vs = 2;
int sdata = 0;
WidgetTerminal terminal(V1);
SimpleTimer timer;

String vdata = "";

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() / 1000);
}

void setup()
{
  
  SwSerial.begin(115200);
  // Debug console
  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  
  pinMode(vs ,INPUT);
  Blynk.begin(Serial, auth);

  timer.setInterval(10L,sensorvalue); // 1000L
  
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.flush();
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer

}

void sensorvalue()
{
  long measurement =vibration();
 //delay(50);
  Serial.println(measurement);
  Blynk.virtualWrite(V3, measurement);
 
  vdata = vdata + "Vibration: " + measurement;  
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V2, vdata);
  vdata = ""; 
}

long vibration(){
  //delay(10);
  long measurement=pulseIn (vs, HIGH);  //wait for the pin to get HIGH and returns measurement
  return measurement;
}

This might help you
https://docs.blynk.io/en/legacy-platform/legacy-articles/how-to-display-any-sensor-data-in-blynk-app

ok i just realized that they put the command to push data in myTimerEvent, after i put the command there it works it shows in the terminal and gauge, I tried using newer library version and it still works, and it seems that it can only connect when i set the SERV_PORT to 8442 when I tried 80 (default) or 8080 it goes EVENT_CLOSE.

here is the complete script:

#include <SimpleTimer.h>
#include <SoftwareSerial.h>
#include <BlynkSimpleStream.h>

SoftwareSerial SwSerial(10, 11); // RX, TX
#define BLYNK_PRINT SwSerial

char auth[] = "TKVUcDT-LFXAZCt730fQlz73O6CXIFv8";
int vs = 2;
int sdata = 0;

WidgetTerminal terminal(V1);
SimpleTimer timer;

String vdata = "";

void myTimerEvent()
{
  long measurement = vibration();
  delay(30);
  Blynk.virtualWrite(V5, measurement);

  vdata = vdata + "Vibration: " + measurement;
  Blynk.virtualWrite(V2, vdata);
  vdata = ""; 

  if( measurement > 3000 )
  {
    Blynk.logEvent("Vibration detected!!");
  }
}

void setup()
{
  SwSerial.begin(115200);
  
  Serial.begin(9600);
  
  pinMode(vs, INPUT);
  Blynk.begin(Serial, auth);

  timer.setInterval(200L,myTimerEvent); // 1000L
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.clear();
  terminal.flush();
}

void loop()
{
  Blynk.run();
  timer.run(); // running timer every second
}

long vibration(){
  //delay(10);
  long measurement=pulseIn (vs, HIGH);  //wait for the pin to get HIGH and returns measurement
  return measurement;
}

Thank you for the help :smiley:

1 Like