LED Using Blynk and ESP8266
LED Using Blynk and ESP8266
Objective:
3. To setup the configuration and program to control the four LED’s ON/OFF action using Blynk.
4. To setup the configuration and program to control RGB LED using Blynk
https://www.youtube.com/watch?v=BEZrQcjsWT0
Procedure:
Blynk is an IoT platform with customizable mobile apps, private cloud, rules engine, and device management
analytics dashboard, designed for easy and customizable Internet of Things applications. Designing dashboard
on Blynk App for IoT projects is really easy, you just have to organize buttons, sliders, graphs,
and alternative widgets onto the screen. We can also edit the widgets as per our requirements.
With the help of Blynk, the software side gets easier than the hardware. Blynk is perfect for interfacing with
simple projects like monitoring the temperature of your room or turning lights on and off remotely Here, in this
project we are controlling a LED using Blynk App and Esp8266. Earlier we have controlled the LED using
ESP32. So, not only with ESP8266, it’s easy to interface Blynk app with Raspberry Pi, Arduino and other
microcontrollers.
Components Required
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
In your browser search Blynk code generator then open Blynk example browser,
Select your board and example code, as shown below:
Open Arduino IDE and select Tools option as shown below:
Note: You should have ESP8266 library installed in Arduino IDE.
Then copy the example code from the browser as mentioned above and paste in Arduino IDE.
Programmig Code Explanation
The complete code for Controlling LED using Blynk App and ESP8266 is given at the end. Include all the
required libraries for ESP8266 and Blynk App in the code, as shown below:
Enter the Auth Token in the code, which you can get from the Blynk App or from the mail you have received
from Blynk.
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 ESP32
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.
So we have successfully designed the Blynk App dashboard and controlled the LED through Blynk app
using ESP8266.
Code
Now in programming, first we need to include the libraries
#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();
}
Code:-
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
void setup()
Serial.begin(9600);
void loop()
Blynk.run();