Tuesday, March 19, 2024
ExplainerHow ToInternet of ThingsIoT PlatformsIoT Software&ToolsTutorials/DIY

Blynk Tutorials | Blynk IoT Platform | How To use Blynk

Blynk was designed for the Internet of Things. It is most popular IoT Platform. It can control hardware remotely, it can display sensor data, it can store data, vizualize it and do many other cool things. With Blynk Library you can connect over 400 hardware models (including ESP8266, ESP32, NodeMCU, all Arduinos, Raspberry Pi, Particle, Texas Instruments, etc.)to the Blynk Cloud. Full list of supported hardware can be found here.

There are three major components in the platform:

  • Blynk App – allows to you create amazing interfaces for your projects using various widgets we provide.
  • Blynk Server – responsible for all the communications between the smartphone and hardware. You can use our BlynkCloud or run your private Blynk server locally. It’s open-source, could easily handle thousands of devices and can even be launched on a Raspberry Pi.
  • Blynk Libraries – for all the popular hardware platforms – enable communication with the server and process all the incoming and outcoming commands.

Now imagine: every time you press a Button in the Blynk app, the message travels to space the BlynkCloud, where it magically finds its way to your hardware. It works the same in the opposite direction and everything happens in a blynk of an eye.

blynk iot platform

What do I need ?

1. Hardware.

An Arduino, Raspberry Pi, or a similar development kit.

Blynk works over the Internet. This means that the hardware you choose should be able to connect to the internet. Some of the boards, like Arduino Uno will need an Ethernet or Wi-Fi Shield to communicate, others are already Internet-enabled: like the ESP8266, Raspberry Pi with WiFi dongle, Particle Photon or SparkFun Blynk Board. But even if you don’t have a shield, you can connect it over USB to your laptop or desktop (it’s a bit more complicated for newbies, but we got you covered). What’s cool, is that the list of hardware that works with Blynk is huge and will keep on growing.

2. A Smartphone.

The Blynk App is a well designed interface builder. It works on both iOS and Android, so no holywars here, ok?

Download for iOS

Download for Android

Blynk Library

Download The Library

You can find example sketches covering basic Features. They are included in the library. All the sketches are designed to be easily combined with each other. You can use https://examples.blynk.cc/


Blynk Tutorials


LED using Blynk and ESP8266 (Node MCU)

Components Required

  1. BYNK APP (Download from Play Store)
  2. ESP8266 NODEMCU

Blynk App Dashboard Setup for Controlling LED

To control LED with Blynk app, download and install the Blynk app from Google or Apple app store.

After sign up click on ‘New Project’ to start your project. Now provide your project a name and as blynk app works with diffferent hardware models.

Thus opt for your device from choices. Here, we are using ESP8266 nodeMCU.

While selecting your board opt for your association sort whether or not it’s Wi-Fi or LAN or USB association.

After these steps click on ‘Create’ button to form your project.

As, the blank project opens, add Widgets to it by clicking on Add button (Plus sign button)

Now after this click on ‘Button’ to add a button in your project.

Now in button settings provide a name to your button. After assign the pin number to the ‘OUTPUT’. Also, give names to your On/Off labels.

NODE MCU Setup for Blynk App

Open this link your browser https://examples.blynk.cc/ .  Select your board “ESP8266” and example code “LED Blink”.

blynk led blink

Now open Arduino IDE and setup environment for ESP8266 NodeMCU Board. If you are not familiar with Arduino IDE.

Visit This : Arduino Support for ESP8266 with simple test code

Now copy the example code from the browser as mentioned above and paste in Arduino IDE.

Arduino Sketch code Explanation

The complete code for Controlling LED using Blynk App and ESP8266 is given at the end. Includeall the required libraries for ESP8266 and Blynk App in the code, as shown below:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

Enter the Auth Token in the code, which you can get from the Blynk App or from the mail you have received from Blynk.

char auth[ ] = "YourAuthToken";

To connect with WIFI enter your SSID name and password

char ssid[ ] = "YourNetworkName";
char pass[ ] = "YourPassword";

Here, void blinkLedWidget() function is used for switching ON and OFF the LED.

void blinkLedWidget() 
{
  if (led1.getValue()) {
    led1.off();
    Serial.println("LED on V1: off");
  } else {
    led1.on();
    Serial.println("LED on V1: on");
  }
}

In void setup( ) function, we will initialize the baud rate, LED output and will connect the module with the Wi-Fi using Blynk.begin(auth,ssid,password); function. This function begins the Wi-Fi connection.

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, blinkLedWidget);
}

Testing LED Control using Blynk App and ESP

Now, copy and paste the complete code into Arduino IDE. Then upload the code into the ESP8266. Then, open the Blynk App for controlling the LED from the button widget.

Complete Code

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).

char auth[ ] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.

char ssid[ ] = "YourNetworkName";
char pass[ ] = "YourPassword";

WidgetLED led1(V1);
BlynkTimer timer;

// V1 LED Widget is blinking
void blinkLedWidget()  // function for switching off and on LED
{
  if (led1.getValue()) {
    led1.off();
    Serial.println("LED on V1: off");
  } else {
    led1.on();
    Serial.println("LED on V1: on");
  }
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, blinkLedWidget);
}

//In the loop function include Blynk.run() command.
void loop()
{
  Blynk.run();
  timer.run();
}

NodeMcu to DHT Interface in Blynk app

Things used in this project

DHT11 sensor measures and provides humidity and temperature values serially over a single wire. First read this article and prepare arduino for ESP8266 Arduino Support for ESP8266 with simple test code

PIN Connection:

pin connection

Create a Project use Blynk apps Following Instruction First LogIn your Blynk App Then Flow the Step By Step

NOTE – You got your AUTH TOKEN it send to your email address.

Now Flash this code in ESP8266. Here Replace SSID, SSID PASSWORD and Auth TOKEN. You need to Some library.

So Download by this link https://github.com/blynkkk/blynk-library/archive/master.zip

Adafruit DHT sensor libraries:
https://github.com/adafruit/Adafruit_Sensor
https://github.com/adafruit/DHT-sensor-library

Download these library and extract it. Now open Arduino and go to File>Properties. Here you find path of Arduino.

Now go to Arduino path and paste all extracted libraries folder in Libraries Folder. Select Board “Nodemcu 1.0” in Tool tab of Arduino IDE and Select right Port for Nodemcu. Now Flash this code given below.

Code

/*************************************************************

WARNING :
For this example you’ll need Adafruit DHT sensor libraries:
https://github.com/adafruit/Adafruit_Sensor
https://github.com/adafruit/DHT-sensor-library

App project setup:
Value Display widget attached to V5
Value Display widget attached to V6
*************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “AUTH TOKEN”;      // replace with your auth token, You got your AUTH TOKEN it send to your email.

// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = “YOUR SSID”;                                                                     // replace with your SSID
char pass[] = “SSID PASSWORD”;                                                          // SSID Password

#define DHTPIN 2 // What digital pin we’re connected to

// Uncomment whatever type you’re using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino’s up time every second to Virtual Pin (5).
// In the app, Widget’s reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

if (isnan(h) || isnan(t)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
// You can send any value at any time.
// Please don’t send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}

void setup()
{
// Debug console
Serial.begin(9600);

Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, “blynk-cloud.com”, 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

dht.begin();

// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}

void loop()
{
Blynk.run();
timer.run();
}

Useful links


I hope you like this post. Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

2 thoughts on “Blynk Tutorials | Blynk IoT Platform | How To use Blynk

Leave a Reply

Your email address will not be published. Required fields are marked *