Read the data in serial monitor from BLYNK_WRITE

I copied the code from github/GetData and I cant figure out how to see that ‘‘Serial print’’ while my cmd is running, cause the serial port is busy.
For my project, I will need 16 switches that I can go get the status from and use that 1 or 0 in my code to control a motor. All my code is working but I wanted to make a GUI instead of just typing into the Serial monitor.
So I dont really understand how to see that serial print cause it says « COM4 ». (Port busy) when i try to open the serial monitor. And when i close the cmd, well the project goes offline (duh).
Thank you very much in advance.

the code is;

#define BLYNK_PRINT Serial

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "6233473edb0846cc90a935c4e23a446f";

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin 1
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("V1 Slider value is: ");

void setup()
  // Debug console


void loop()

What type of hardware are you using, and what connection method to the Blynk Server?

You also need to properly format your code in order for us to see it properly… the included libraries are missing without the formatting.

If, as it seems, you are using the USB-Link then you would also have to add another serial connection, typically SoftSerial and send any prints through that, via a TTL-USB adapter, to another terminal program (I use Termite).

A helpful tip is to change Serial.print commands into terminal.print and forward your serial messages to your Blynk app rather than the serial monitor. Here’s a snippet from one of my sketches I’m working, plus it will be wrapped in code formatting for this site as Gunner described above. You should edit your post and include the code formatting as the illustration above depicts.

    button = oldButtonState;
    startCount = millis();
    pumping = true; // launched
    digitalWrite(pump, HIGH);
    terminal.print("startCount is:");

Thanks for the answers. I am totaly new to forum and stuff, my bad! I’m still trying to figure out everything hehe.
@Gunner I use an arduino Uno and im connected via a USB port to my PC with windows.
I’ve tried the exemple with the bliking Led and it works good!
@myggle thank you I will try that :D!

Actually i dont NEED the print but I can use it to ensure I get the right values, all i need is that I get the value from the switch/button to modify my variables. I just dont understand how can I see the Serial.print at the same time my cmd is running.
Also, I don’t really get the BLYNK_WRITE() loop… I undersatand that the param.asInt() is like a ‘‘read’’ of my virtual pin right?

@simon_blais I had to edit your original post to properly format your posted code. Please take a look at it and compare with the diagram I posted earlier to see how it needs to be done in the future.

Since any serial port can only be used by one thing at a time, when you are using the USB-Link, then you should avoid all other references to the port lest they cause communication disconnects. e.g.

Comment out this line…

// #define BLYNK_PRINT Serial

…and change or remove any of these

Serial.print("V1 Slider value is: ");

As for the BLYNK_WRITE(vPin) loops, they are loops that are called whenever the associated virtual pin is activated (gets data or changes state HIGH/LOW. This is usually done by a Widget on the App, like a button or slider.

You can send data back to the App by using the command Blynk.virtualWrite(vPin, value).

So in your example, you can use a Display Widget like Terminal, or others to replicate your print statement in the app.

BLYNK_WRITE(V1)  // this function is called when a widget, like a button, is pressed
  int pinValue = param.asInt();  // assigning incoming value from pin V1 to a variable
  Blynk.virtualWrite(V2, pinValue)  // sends the data back to a widget linked with V2

There is a more indepth explanation on all this in the Documentation here

1 Like