Blynk app for remote monitoring Nodemcu esp8266 and Arduino
Description:
Nodemcu eps8266 and Blynk app- Using the Nodemcu esp8266 wifi module and Arduino, you can learn how to use the blynk app application terminal widget to show the sensor data. If you’re using Arduino, you’ll know which serial monitor is being used for. Typically the serial monitor is used for debugging purposes.
The Terminal Widget program from Blynk app is just like the Serial Monitor from Arduino. The only difference is that the Arduino Serial monitor only operates when the Arduino is attached to the laptop or device, while the Blynk app Terminal Widget program is completely wireless and can be used to control remotely. You can monitor your sensors from anywhere in the world using the Blynk app device terminal widget. I will also show the value of the sensor on the serial monitor of Arduino.
I’m going to use a variable resistor as the sensor for the best understanding.
Today’s episode covers
- Circuit diagram
- Interfacing
- Programming and finally
- testing
Let’s continue without any further delay!!!
Amazon links:
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!
Circuit Diagram:
This circuit schematic is designed in cadsoft eagle 9.1.0 version.
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 Mobile App Setup:
First of all, open the blynk app
Click on the New Project and Set the project name as Arduino Nodemcu, if you want you can set any other name.
Click on the chosen device and select Nodemcu.
set the connection type to wifi.
Then click on the create button, an authentication token will be sent on your email id, which will be then used in programming. T
This is the authentication token, we will simply copy this and paste in our programming.
Now click anywhere on the screen and search for the Notification and click to add.
Now click on the terminal to open the settings.
Select virtual pin V12. Set the add newline to yes. That’s it.
Our basic application setup is completed.
Programming:
Arduino Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#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 on Arduino’s pin number 2 with the name Nodemcu and pin number 3.
SoftwareSerial nodemcu(2,3); The Rx pin number 2 and the Tx pin number 3
int vresistor = A0; // A variable resistor is attached to the Arduino’s analog pin A0.
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 which takes two arguments as the input.
}
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, then send it to the serial monitor, then empty the mystery variable for new data and then 1 second delay as 1000 milliseconds is equivalent to 1 second.
Now let’s talk about programming for Nodemcu.
Nodemcu ESP8266 wifi module Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
#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 the conditions.
if (Serial.available() == 0 )
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
if (Serial.available() > 0 )
{
rdata = Serial.read();
myString = myString+rdata;
}
If this means state, if no data has been obtained by the Nodemcu module, simply continue to run Blynk app.run and timer.run functions. While the other condition means that if the Nodemcu module has received data from the Arduino, only read the Nodemcu module and add the characters obtained 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.
Watch Video Tutorial
Thanks for Sharing
How can I send sensor data in decimal places