Blynk 2.0 Digital pin to Virtual pin

Hello Blynkers… In my project i used to use this way so that to declare a digital pin to virtual pin.
But in new blynk app i try to use this code for on/of buttons (relay module) in gpio16 but the new app she does not responce. there was some code changes ? if yes please give me one example.
Thanks you a lot :slight_smile:

#define BLYNK_TEMPLATE_ID "*******************"
#define BLYNK_DEVICE_NAME "*************"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#include "BlynkEdgent.h"

const int relay_1 = 16;

void setup()


void loop() {;

  int pinData = param.asInt();
  digitalWrite(16, pinData);

You need a pinMode statement in your void setup for your realy_1 pin.

Also, the Edgent examples have a series of #defines which are commented-out, and which should be used to select the type of board you are using.
If you don’t un-comment one of them, or delete them as you seem to have done, then the custom board configuration, defined in the settings.h tab of the sketch, is used instead. You need to check that the pin you are using for your relay doesn’t conflict with pins already declared in that part of the sketch.

Also, if you’re using an ESP8266 (something you haven’t bothered to share) then GPIO16 probably isn’t the best choice of pin…


I use in my project gpio 16, 5, 4, 0, 14, 12, 13, 3 for relay module and gpio 2 for temp sensors. before i had already tried to uncoment nomcu board but in checking code i see error because in Settings.h was used pin d6 d7 d8 for RGB. Could you please tell me which is the reason to there are uncomment nodemcu? and what this can helps me :slight_smile:

That’s not good, as you’ll see if you’ve read the link I provided.
I’d suggest that you should switch to an ESP32 board.

You need to download the latest pre-release version of the library from here as a .zip file and install it…

Then take the updated Edgent ESP8266 file from that library and add-in your code changes.


Thanks you for suggestion. I am new in this world and i learn things yet. furthermore i did this changes in my code according to the new release and i would like to know if this way to add virtual pins in correct

const int relay_3 = (the digital pin) ;

  int pinData = param.asInt();
  digitalWrite( the digital pin, pinData)

You’re not exactly “adding” the virtual pin, you’re adding a function in your code that will be triggered when the value of the virtual pin changes. The datastreams for those virtual pins still need to be defined in the Blynk 2.0 web dashboard.

There’s more info on virtual pins here…