ESP8266IOT Projects

Blynk Terminal Widget for remote monitoring Nodemcu and Arduino

Blynk Terminal Widget, Description:

 

Blynk Terminal Widget– In this Tutorial, you will learn how to use the Blynk application terminal widget to display the sensor data using Nodemcu esp8266 wifi module and Arduino. If you are using Arduino then you should be quite familiar with Serial monitor which is used for reading the strings and sensors data. The serial monitor is usually used for debugging purposes.


The Blynk application Terminal Widget is just like the Arduino’s Serial Monitor. The only difference is that the Arduino’s Serial monitor works only when the Arduino is connected with the Laptop or computer, while the Blynk application Terminal Widget is completely Wireless and can be used for remote monitoring. Using the blynk application terminal widget you can monitor your sensors from anywhere around the world. I will also display the sensor value on the Arduino’s serial monitor.

For the step by step explanation watch video tutorial given at the end of this article.

Blynk Terminal Widget

For the best understanding, I am going to use a variable resistor as the sensor. You can replace the variable resistor with any other sensor.

Today’s episode covers

  1. Circuit diagram
  2. Interfacing
  3. Programming and finally
  4. testing

Without any further delay let’s get started!!!

Note: this old version of the Blynk app is no more functional. For the blynk mobile App setup and Blynk.cloud dashboard setup ready my article on the New Blynk V2.0. In this article I have explained how to migrate your projects from Blynk 1.0 to the new Blynk V2.0. You can also watch the video.



Amazon Links:

12v Adaptor:

Nodemcu ESP8266 WiFi Module:

LM7805 Voltage Regulator:

470uf capacitor:

330-ohm resistor:

DC Female Power Jack:

Female Headers:

Male Headers:

LEDs:

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

DISCLAIMER:

Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!


This project is based on my previous two tutorials.

 

 

In this tutorial, you will learn how to install the Nodemcu esp8266 wifi board and how to download and use the Blynk library and how to fix the USB UART driver error.

 

 

While in this tutorial you will learn how to make a power supply for Nodemcu esp8266 wifi module so that it can be easily powered up using a 12v adaptor or battery. In this tutorial, a Vero Board is used. While if you want to use a PCB. then you can watch the following video tutorial.

Circuit Diagram:

Blynk Terminal Widget

This schematic is designed in cadsoft eagle 9.1.0 version. If you want to learn how to make a schematic and PCB then watch my tutorial given above.

Let’s start with the 5v regulated power supply based on the lm7805 voltage regulator. J1 is the Female Power Jack and this is where we connect a 12v adaptor or a Solar Panel or a 12v battery. The female power jack J1 is connected with the Input and GND legs of the voltage regulator. Two 470uf capacitors are connected at the input and output sides of the LM7805 voltage regulator. The capacitor connected at the output is compulsory. As you can see a 330-ohm resistor is connected in series with a 2.5v LED. This is a current limiting resistor.


To power up the Nodemcu ESP8266 wifi module, a wire from the output of the voltage regulator is connected with the Vin pin of the Nodemcu ESP8266 wifi module, and make sure all the grounds are connected together.

As the Nodemcu will communicate with Arduino through serial communication, so for this we need a serial port, as I always say never use the Arduino’s default serial port for communication with other devices, Use Arduino’s default serial port only for the debugging purposes. So now the question is if we are using the Arduino’s default serial port for debugging purposes then how we will communicate with Nodemcu Module?

Well my friends no worries at all, we can define multiple serial ports using the Software serial library, which I will explain in the programming. So as you can see the Nodemcu Rx pin is connected with Arduino’s pin3 and the Nodemcu Tx pin is connected with Arduino’s pin2 and the ground is connected with the ground.

A variable resistor is connected with the Analog pin A0 of the Arduino, while the remaining two legs of the variable resistor are connected with 3.3v and ground. As I said earlier this variable resistor will be used as the sensor.

Blynk Terminal Widget


Blynk Mobile Application Setup:

First of all, open the blynk application

Blynk Terminal Widget

Click on the New Project and Set the project name as Arduino Nodemcu, if you want you can set any other name.

Blynk Terminal Widget

Click on the choose device and select Nodemcu.

Make sure you set the connection type to wifi.

Blynk Terminal Widget

Then click on the create button, an authentication token will be sent on your email id, which will be then used in programming. T

Blynk Terminal Widget

This is the authentication token, we will simply copy this and paste in our programming.

Blynk Terminal Widget

Now click anywhere on the screen and search for the Notification and click to add.

Blynk Terminal Widget

Now click on the terminal to open the settings.

Blynk Terminal Widget

Select virtual pin V12. Set the add newline to yes. That’s it.

Our basic application setup is completed.

Programming:

Arduino Programming:

#include<SoftwareSerial.h>

SoftwareSerial nodemcu(2,3); 

int vresistor = A0; // variable resistor is connected with analog pin A0 of the Arduno
int vdata = 0; 
String mystring; 
void setup()
{
 Serial.begin(9600); 
nodemcu.begin(9600); 
pinMode(vresistor, INPUT); 
}

void loop()
{
 vdata = analogRead(vresistor);  
  if (nodemcu.available() > 0 )
  {
  char data; 
  data = nodemcu.read(); 
  Serial.println(data); 
  }
  mystring = mystring + "Variable resistor: " + vdata; 
 nodemcu.println(mystring);
 Serial.println(mystring);  
 mystring = ""; 
delay(1000); 
}



Arduino Program explanation:

We start with

#include <SoftwareSerial.h>

#include means that this is a preprocessor directive and .h means that this is a header file. So with the help of this, you can make multiple serial ports. So let’s define a serial port with name Nodemcu on pin number 2 and pin number 3 of the Arduino.

SoftwareSerial nodemcu(2,3); pin number 2 is the Rx and pin number 3 is the Tx

int vresistor = A0; // a variable resistor is connected with analog pin A0 of the Arduino

int vdata = 0; // this is a variable of the type integer and will be used to store the value of variable resistor.

String mystring; // my string is a variable of the type string.

As you you know my friends, every Arduino, and the mega program has at least two functions which are the void setup() and void loop() functions. Void means that this function is not returning any value while the empty parenthesis means that this function is not taking any arguments as the input.

Serial.begin(9600);  // activates the serial communication at baud rate of 9600. This will be used for debugging purposes.

nodemcu.begin(9600); // activates the serial communication with Nodemcu connected with pin2 and pin3 of arduino and 9600 is the baud rate.


pinMode is a function and it takes two arguments as the input the pin number or pin name which is vresistor  and the status which can be input or output.

}

Then starts the void loop function.

vdata = analogRead(vresistor);  // reads the variable resistor and stores the value in vdata

  mystring = mystring + “Variable resistor: ” + vdata;  // we make a complete message, and send it to the Nodemcu module and also send it to the serial monitor and then empty the mystring variable for new data and then a delay of 1 second as 1000 milliseconds are equal to 1 second.

Now let’s discuss the Nodemcu programming.

Nodemcu ESP8266 wifi module Programming:

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>


String sdata; 
char auth[] = " aa7fced027354cbe9b57307d404d98e2";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "ZONG MBB-E8231-6E63";
char pass[] = "08659650";

SimpleTimer timer;

String myString; // complete message from arduino, which consistors of snesors data
char rdata; // received charactors


// This function sends Arduino's up time every second to Virtual Pin (1).
// 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 myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() / 1000);
  
}



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

  Blynk.begin(auth, ssid, pass);

    timer.setInterval(1000L,sensorvalue1); 

}

void loop()
{
   if (Serial.available() == 0 ) 
   {
  Blynk.run();
  timer.run(); // Initiates BlynkTimer

   }
   
  if (Serial.available() > 0 ) 
  {
    rdata = Serial.read(); 
    myString = myString+rdata; 
  
  }

}

void sensorvalue1()
{
sdata = myString ;
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V12, sdata);
   myString = "";
}


Nodemcu Program Explanation:

Before you start the programming, first of all, make sure that you download all the necessary libraries and you install the Nodemcu board and you also install a driver for the USB UART.

char auth[] = ” aa7fced027354cbe9b57307d404d98e2″;

this is the authentication number which was sent via email, I simply copied and past it over here.

// Your WiFi credentials.

// Set password to “” for open networks.

char ssid[] = “ZONG MBB-E8231-6E63”;

char pass[] = “08659650”;

This is the name of your wifi password.

Then, starts the void setup function. I have already explained these instructions in my previous tutorials on Nodemcu.

The void loop function consists of two if conditions.

   if (Serial.available() == 0 )

   {

  Blynk.run();

  timer.run(); // Initiates BlynkTimer

   }

  if (Serial.available() > 0 )

  {

    rdata = Serial.read();

    myString = myString+rdata;

  }

This if condition means, if Nodemcu module hasn’t received any data then simply keep executing Blynk.run and timer.run functions. While the other condition means if the Nodemcu module has received data from the Arduino then simply read the Nodemcu module and add the received characters with the mystring variable to make a complete message.


Sensorvalue1() function is a user-defined function and it is used to send the variable resistor value to the virtual pin 12 and finally, we empty the variable for new data, this is really important.

Note: for the Best understanding watch video tutorial given below.

Watch Video Tutorial:

 

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

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

Back to top button