How to control anything with Blynk app
Turn your things On / Off or send any data from Blynk app to hardware
Blynk can control any electronics, GPIOs, relays, anything. You just need to know the basics, which are super simple.
☝️ You need Blynk library installed. Here is the guide how to install Blynk Library.
There are two ways of turning things ON and OFF with Blynk:
  1. 1.
    Simple. Directly controlling Digital I/O pins with no coding;
  2. 2.
    Advanced, using Virtual Pins and simple code;
In this article we will describe both cases.
Let's try turning on/off LED connected to Digital Pin D3 of your hardware.

Control GPIOs with no extra coding

In Blynk app:
  1. 1.
    Create a New Project (new Auth Token will be sent to your email);
  2. 2.
    Add Button Widget;
  3. 3.
    Go to Widget Settings;
  4. 4.
    Set PIN to D3 - this where you tell the app that Button will turn ON and OFF something;
  5. 5.
    Set Mode to Switch;
Preparing the basic code:
Use our Blynk Examples Sketch Builder to create the code for your hardware.
  1. 1.
    Choose your board;
  2. 2.
    Choose your Connection (WiFi, Ethernet, Bluetooth, USB, ...);
  3. 3.
    Browse through examples and choose the one you need;
  4. 4.
    Sketch Builder will create a code for you;
  5. 5.
    Copy the whole code and paste it to Arduino IDE;

Input your Auth Token

In the example sketch find the line:
1
char auth[] = "YourAuthToken";
Copied!
Change it with your own Auth Token (it should be in your email inbox after you created the Project in the Blynk app).
Now this line should look similar to this:
1
char auth[] = "53e4da8793764b6197fc44a673ce4e21";
Copied!
🔥 Flash the example code to your hardware.

Advanced. Using Virtual Pins to turn things ON and OFF

Sometimes, triggering single Digital Pin is not enough. Sometimes you need more flexibility. For example, how to control brightness of 3 LEDs using one Slider Widget, or trigger a a whole set of actions with 1 button?
We've got you covered.
  1. 1.
    In Blynk app add a Slider Widget and set it to use Virtual Pin V1;
  2. 2.
    Change this basic sketch to match your hardware and connection type;
  3. 3.
    🔥 Flash the example code to your hardware;
Let's try to understand the code. Look at this block:
1
BLYNK_WRITE(V1)
2
{
3
int pinValue = param.asInt();
4
Serial.print("V1 Slider value is: ");
5
Serial.println(pinValue);
6
}
Copied!
This is where we tell the hardware what to do when there is a WRITING command from Blynk app to Virtual Pin V1.
Our Slider widget sends data to V1:
1
BLYNK_WRITE(V1) //something in Blynk app WRITEs to pin V1
Copied!
☝️ BLYNK_WRITE should be placed OUTSIDE of void loop(); The next line is to get the actual incoming value:
1
int pinValue = param.asInt();
Copied!
Where, is how you define the incoming data type:
1
param.asInt();
Copied!
If you need other variable type, you can also use:
1
param.asInt(); // get value as an Integer
2
param.asFloat(); // get value as a Float
3
param.asDouble(); // get value as a Double
4
param.asStr(); // get value as a String
Copied!
...and then we just print the slider value to Serial Monitor
1
Serial.print("V1 Slider value is: ");
2
Serial.println(pinValue);
Copied!
This approach gives you endless opportunities on how to use incoming data from the app in a very flexible way. For example, you can create a set of actions in the function that will be triggered by one click of the Button:
1
void myMorning(){
2
3
// make me coffee
4
// prepare breakfast
5
// clean my shoes
6
7
}
8
9
10
BLYNK_WRITE(V5) // Button Widget writes to Virtual Pin V5
11
{
12
if(param.asInt() == 1) { // if Button sends 1
13
myMorning(); // start the function
14
}
15
}
Copied!
---
If you have questions or something is not working, visit our 👥 community page.
Also, full 📗 documentation is here.
Last modified 4mo ago