Virtual pin reading

I have conected button in app to V1pin.
In ARDUINO code is super easy to use the command " Blynk.virtualWrite(pin,value) ".

How can I read virtual pin? It would be more simple to use something like :" Blynk.virtualRead(pin) "

I need read value from app V1pin. In ARDUINO I need save this value (button pushed “HIGH”) to the “int pin= HIGH/LOW”.

Thank you for your support

This is how you can read data from virtual pin. For button you need to :


And you’ll get 1 or 0 (HIGH/LOW).

Im so sory, Im new here.
I was read some topic about that, but i dont understant it.
I can show you my test code as an example…


#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2,3); // RX, TX
 #define BLYNK_DEBUG
 #define BLYNK_PRINT SwSerial
 #include <BlynkSimpleSerial.h>
char auth[] = "171b6854e43146fxxxxxxxxxxxxxxx";
void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);

void loop() {

/*   WHAT I HAVE TO WRITE HERE if I want to read pin number V1 ?????
 I need:  
        if "virtual pin V1" =HIGH {
          if "virtual pin V1" =LOW {

void pin_activated(){
    Blynk.virtualWrite(1, HIGH);  //LED 10 "HIGH"
    Blynk.virtualWrite(2, LOW);   //LED 11 "LOW"
    digitalWrite(13, LOW);        //relay is on  

void pin_deactivated(){
    Blynk.virtualWrite(2, HIGH);   //LED "HIGH"
    Blynk.virtualWrite(1, LOW);    //LED "LOW"
    digitalWrite(13, HIGH);        //relay is off
1 Like


    if (param.asInt()) {
    } else {

void loop() {

Go to sketch examples and there you’ll find GetData and PushData - check them to see how to work with Virtual Pins

I read some examples, but I dont uderstand it.
I simplify my code and tried it again with part of your code. If i tried to compile my code IDE write me:

BLYNK_USB_button.ino: In function ‘void BlynkWidgetWrite1(BlynkReq&, const BlynkParam&)’:
BLYNK_USB_button.ino:20:20: error: cannot convert ‘BlynkParam::asInt’ from type ‘int (BlynkParam::)()const’ to type ‘bool’
compilation error.

Please check it:

 *#include <SoftwareSerial.h>*
 *SoftwareSerial SwSerial(2,3); // RX, TX*

 *#define BLYNK_DEBUG*
 *#define BLYNK_PRINT SwSerial*
 *#include <BlynkSimpleSerial.h>*

*char auth[] = "171b6854e43146f68a35cxxxxxxxxxxx";*

*void setup(){*
  *pinMode (13,OUTPUT);*

*{   if (param.asInt) {*        
        *pin_activated();    //HIGH*
    *} else {*
       *pin_deactivated(); //LOW*
*void pin_activated(){digitalWrite(13, LOW);}*

*void pin_deactivated(){digitalWrite(13, HIGH);}*

*void loop()*
  1. :exclamation:Read the posting rules and use code formatting so that it’s readable. I did it for you this time, but next time we will ignore such posts.
  2. You should be more attentive when coding and always double check your code :wink:

GetData Example clearly shows how to get data from Virtual Pin:

  BLYNK_LOG("Got a value: %s", param.asStr());
  // You can also use: asInt() and asDouble()

while yours is:

Spot the difference? :wink:

BTW, there is no need in complicating code so much:

    if (param.asInt()){       
        digitalWrite(pin, HIGH);
    } else {
        digitalWrite(pin, LOW);

Also, avoid using delay() function, especially in void loop(). It can affect connection to Blynk Cloud and cause other errors. Read carefully instructions in SendData Example to see how to work with timers and avoid delays.



should be


Thank you very much for your advice. It was helpful !!!

Wundered why the LED widget differs from other presentation widgest ,like value / graph.
e.g. with request or push.

1 Like

@knooien Does your question relate to this thread?

Think so,

Maybe just like a value widget:
e.g. V0 assigned to a LED.

request code:
int status = get_some_status();
Blynk.virtualWrite(0, status);

push code:
int status = get_some_status();
Blynk.virtualWrite(0, status);

A post was split to a new topic: Read from multiple virtual pins?