I'd like to have an overview about how Blynk works

Hello everybody,

I just installed the BlynkApp on my smartphone and installed the Blynk-Libraries in the Arduino-IDE. I have quite some experience in Programming with Arduino and SPIN for microcontrollers and with Delphi for Windows Software.
So I don’t need to learn the basics.

Now I would like to read what are the concepts of how Blynk works.
What was presented to me by the website as “Getting started” was
browse examples.
Now I’m not the guy who has a lot of fun by tinkering around in examples

I would like to read a straight-forward article that explains the concepts.

And then goes on the level of lines of code.
But not only lines of code like in the examples.finding out how it works through try and error.

This article should show the communication-principles with pictures that show the connection between the Blynk-App and the lines of code in the Arduino-IDE

I’m very astonished that a well grown company ist still not offering something like that.
I haven’t looked through much of the Blynk-website yet. But why does the Blynk-Website not offer something like that at such a prominent place that it must catch my eyes??!

best regards Stefan

Hi @StefanL38
I guess that everyone has their own learning style, and comes to Blynk via a totally different journey through life. A large number of people seem to start with an Arduino board, that has no internet connectivity, then want to get started with that hardware without learning any programming skills.

More experienced programmers are usually happy to read the documentation and look at the Sketch Builder examples, but that’s clearly not working for you.

I’ll try to give you a quick overview. I’ll assume that your using something like a NodeMCU board, a WiFi connection and that you’ll be using C++ to write your code…

Blynk has 3 cloud servers dotted around the world. You can use these for free, but you’re only given 2000 units of free ‘energy’. Adding widgets to your project uses-up this energy, and if you want to use more widgets in your project then you’ll need to buy more energy. The energy is recyclable, so if you add a widget to your project then delete it you get the energy back again.
If you wish, you can create your own local server, and give yourself unlimited energy.
I’d recommend using the free cloud energy as a staring point.

The Blynk app talks to the (cloud or local) Blynk server, as does your NodeMCU device - via the Blynk libraries.


The NodeMCU and the Blynk server need to be in constant communication with each other. This is achieved by having the command in the void loop of your sketch. Each time this void loop executes (which should be tens of not hundreds of times per second) the NodeMCU and the server do a handshake and exchange any necessary data.

Widgets in the app can mostly be connected to digital or virtual pins.
A digital pin will (via the Blynk library) directly control the corresponding hardware pin on the NodeMCU.
My advice would be not to use digital pins. Virtual pins are much more powerful, and versatile, so use them instead.

When you use Virtual Pins you get access to a number of callback functions within your code. This is where the documentation is a bit lacking in my opinion. I’ll demonstrate how they work with an example, even though you don’t like examples :grinning:

In the app, attach a Button widget to pin V1 and set it to Switch (latching) mode. By default, when you press the button it will send a “1” when it’s on, and a “0” when it’s off. This data is sent from the app to the server.
When the NodeMCU does it’#s handshake with the server then it wil;l be tols about the new value for pin V1. However, to make use of this you need to add a callback function to your sketch, like this:

  // This code will execute when the value of V1 changes

So, every time the value of the widget attached to V1 changes, the BLYNK_WRITE(V1) callback function will ‘fire’ and the code inside that function will be executed. If you’re familiar with hardware interrupts then this is a similar principal, but executed in software.

Just knowing that the V1 widget has changed state isn’t normally much use, instead you want to know if it is now On or Off. You do this with the command. There are tree flavours of this:
which return integer, float or string versions of the data. As we are dealing with just 0’s and 1’s we’ll use the param.asInt() version…

    Serial.println("The button widget on V1 was turned ON");
    Serial.println("The button widget on V1 was turned OFF");    

Widgets can be updated from code using the Blynk.virtualWrite(vPin,value) command, so this:


would turn our button widget attached to V1 off.
It’s worth noting that this won’t trigger the BLYNK_WRITE(V1) callback, because if it did you could easily create an endless loop within your code.

There are other callbacks that can be added to your code, such as BLYNK_CONNECTED which will trigger every time the NodeMCU connects to the Blynk server and BLYNK_APP_CONNECTED and its sister BLYNK_APP_DISCONNECTED which trigger when the app connects or disconnects from the server, but all of these are covered quite well in the documentation.

Does this help to give an overview and get you started using widgets to control your device?


1 Like

Hello Pete,

thank you very much for taking the time to explain in this detail how Blynk works.
Yes indeed now I have understood the basic concepts of Blynk. I guess there are more things to discover what Blynk can do. With this overview, now I feel ready to start coding.

best regards Stefan

1 Like