Choose your Connection (WiFi, Ethernet, Bluetooth, USB, ...);
3.
Browse through examples and choose the one you need;
4.
Sketch Builder will create a code for you;
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.
In Blynk app add a Slider Widget and set it to use Virtual Pin V1;
2.
Change this basic sketch to match your hardware and connection type;
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.