Introduction: How to Blink an LED Using the Blynk App

About: Bharat Pi is an IoT prototyping platform for students, innovators, startups and developers. A simplified board with an all in one compute network and storage on a single board to build rapid prototypes, colleg…

In this tutorial, we'll show you how to control an LED connected to your Bharat Pi board using the Blynk app. Blynk is a platform that allows you to build IoT projects easily and control hardware remotely from your smartphone.

Supplies

Bharat Pi board

Usb cable

Blynk app installed on your smartphone

Step 1: Bharat Pi

Bharat Pi boards come equipped with built-in LEDs, removing the need for any external LED connections.

Step 2: Blynk App

Step 3: Get Your Auth Token

Step 4: Add a Button Widget

Tap on the '+' button to add a widget.

Select the 'Button' widget.

Tap on the button to configure it.

Set the output pin to the pin corresponding to the onboard LED of the Bharat Pi board.

Step 5: Writing the Bharat Pi Cod

Install Blynk Library:

  • If not already installed, install the Blynk library.

Write the Code:

#define BLYNK_TEMPLATE_ID "TMPL3qtqAe6AN" // Add your actual Template ID here
#define BLYNK_TEMPLATE_NAME "led"
#define BLYNK_AUTH_TOKEN "ZGMM0nHLso1Xwq8FMrbuo35wE59z0CFB"
#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "smile123";
char pass[] = "123456789";

int LED = 2; // Define LED as an Integer and use pin 2 on the ESP32

void setup() {
 // Debug console
 Serial.begin(115200);
 pinMode(LED, OUTPUT); // Set the LED (pin 2) as an output
 Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}

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

// This function will be called every time button Widget
// in Blynk app writes values to the Virtual Pin V3
BLYNK_WRITE(V3) {
 int pinValue = param.asInt(); // Assigning incoming value from pin V3 to a variable
 if (pinValue == 1) {
  digitalWrite(LED, HIGH); // Turn LED on
 } else {
  digitalWrite(LED, LOW); // Turn LED off
 }
}


Replace "YourAuthToken" and #define BLYNK_TEMPLATE_ID "TMPL3qtqAe6AN"

with the Auth Token you received from Blynk.

Upload the Code and Connect

  1. Upload the Code:
  • Connect your Bharat Pi board to your computer using a USB cable.
  • Select the correct board and port from the Arduino IDE.
  • Upload the code to your Bharat Pi.
  1. Open the Serial Monitor:
  • After the code is uploaded, open the Serial Monitor from the Arduino IDE.
  • Set the baud rate to 9600.
  1. Connect the Blynk App:
  • Ensure your phone and Bharat Pi are connected.
  • Press the play button on the Blynk app to start the project.

Test Your Setup

  1. Control the Onboard LED:
  • Tap the button in the Blynk app to turn the onboard LED of the Bharat Pi on and off.
  • If everything is set up correctly, the onboard LED should blink when you press the button.