Introduction: How to Use Virtual Pins in Blynk

Picture of How to Use Virtual Pins in Blynk

Hello Everyone. I was tinkering with the blynk app and wanted to find a way to use the virtual pins.. Here is what I came up with so far...
Essentially this project uses and LDR attached to adc pin to switch on a virtual LED in the blynk app as a notification. I am hoping that when further widgets and more features such as MQTT, Thingspeak, IFTTT are added, this can come in handy to make easy projects such as alarms, irrigation timers, home automation etc.

Step 1: Tools

Picture of Tools


ESP8266 development board. I am using ESP-12 with and LDR attached to ADC pin.


Arduino IDE with required libraries(blynk, esp8266com etc)

Here is a step- by step guide how to set up

Blynk app

Step 2: Virtual Pins

Virtual pins are used to interface with libraries (Servo, LCD and others), and implement custom functionality.The device may send data to the widget on a virtual pin like this:

* Blynk.virtualWrite(pin, "abc");
* Blynk.virtualWrite(pin, 123);
* Blynk.virtualWrite(pin, 12.34);

Also, virtual pins can react to value updates and requests. For example, this function will be called every time App Widget requests data for Virtual Pin 5:
* BLYNK_READ(5) { // Usually, you will need to respond with a virtual pin value. Blynk.virtualWrite(5, some_value); }

This function will be called every time App Widget writes value to Virtual Pin 1:
* BLYNK_WRITE(1) { BLYNK_LOG("Got a value: %s", param.asStr()); // You can also use: param.asInt() and param.asDouble() }

BLYNK_READ/BLYNK_WRITE functions are effectively "getters/setters" of the Virtual Pins if you're familiar with this concept in other programming languages. Please also take into account that these functions should take minimal time to execute, so avoid using sleep/delay inside of them.
N.B: taken from readme doc

Essentially i wanted to make an example to illustrate the BASIC use of the Blynk.virtualWrite() command
I made a sketch in Arduino:
the value of adc pin is read and when value <100, a HIGH is written to virtual pin 5.
the magic then happens in the blynk app where I can also visualise the adc analog value and light an LED when ldr analog value <100

Step 3: Results

Picture of Results

As you can see in the pictures:
when LDR value is >100 the Burglar LED pin is switched off
When I shine a light on LDR, ldrvalue<100 LED is swtiched on

This is just a proof of concept.. With more tinkering I guess this can come in handy..


homerruma made it! (author)2015-12-07


I'm a flash LDR_alarm_V5.ino the ESP8266

After that I used the widget Value displaj and set input ADC0 and I have read with LDR.

After that I added the widget and select pin LED Virtual V5.

Tap spotlight on and off the value of <100 or LED does not react, does not light up.

Where did I go wrong?

Sorry for bad english This is google translator.

John Trzon (author)2015-10-07

Can you post full working code?

saurabh47 (author)2015-10-05

It doesn't works i have usb connectivity only.please give any solution .i just want led indication. i have connected led to digital pin 6.and pin 6 also connected to analog pin a0.i have using same code just editing that
if(anlog= HIGH)
VirtualWrite(5, HIGH);
virtualwrite(5, LOW);
when program is running then led is on /off by Blynk it doesn't show indication of led on blynk.

John Trzon (author)saurabh472015-10-05

You are right it doesn't work ! Fix it please

saurabh47 (author)John Trzon2015-10-06

char auth[] = "auth token";
int prev = -1;
int B1V;
int BUTTON1_P = 6;
void setup()

// Default baud rate is 9600. You could specify it like this:
//Blynk.begin(auth, 57600);

void loop()
B1V = digitalRead(BUTTON1_P);
if (B1V != prev) {
if (B1V) {
Blynk.virtualWrite(V2, 255);
} else {
Blynk.virtualWrite(V2, 0);


this is pragram realy works .
here digital pin is 6.and virtual pin is v2.

Rahul27 (author)saurabh472015-10-06

I can't understand, did you manage to solve the problem?

saurabh47 (author)Rahul272015-10-07

yes i am able to solve

Rahul27 (author)2015-10-05

how about your setup in blynk app? did you link 5 to led indicator in app?virtual pin

saurabh47 (author)Rahul272015-10-06

yes, i link led to virtual pin 5

Optimus_Grime made it! (author)2015-08-15

Hey, Great instructable!! I was able to use your app and add it to my current project. It uses a TFT shield to be the local HMI... and the BLYNK app to act as my wireless connection. Feel free to check it out :)

Rahul27 (author)Optimus_Grime2015-08-15

Glad you made it. Please check out the blynk community @ for more project ideas! And yeah. Please spread the word. Blynk is awesome,right?

Optimus_Grime (author)Rahul272015-08-18

Yeah it's great!!

Rahul27 (author)2015-07-06

Thanks, hope it was helpful

DIY Hacks and How Tos (author)2015-07-04

Nice. Thanks for sharing.

About This Instructable




More by Rahul27:Blynk-ESP8266 教程ESP8266 Firmata-J5 NodeBotESP8266+Websocket server RGB LED controller
Add instructable to: