CO352 - Lab Manual - IoT With Cloud Computing Lab
CO352 - Lab Manual - IoT With Cloud Computing Lab
Draw ESP8266-NodeMCU Components and Pinout. Explain step by step process for connecting
ESP8266-NodeMCU with Arduino IDE and test the installation with a sample program.
NODEMCU ESP8266 - CAMPONENTS
(GPIO 0)
CP 2102
This is because, Some Arduino boards require an additional core to be installed, for
working with ESP8266, therefore we have implemented the Boards Manager as the
preferred tool to add cores (through the above URL) to your Arduino Software (IDE).
Now navigate to "Tools" in the menu bar and click on "Board" and click on "Boards
Manager"; this opens a window where you can see a search bar and list of boards with
installation button. Now, filter your search by entering 'esp8266'. Look for ESP8266 by
ESP8266 Community. Click on that entry, and then choose Install.
After installing the ESP8266 Arduino Core (as in the above step), restart your Arduino
IDE and navigate to "Tools" and click on "Board" and make sure you have ESP8266
boards available.
Now select your board in the "Tools" > "Board" menu (in our case, it’s the NodeMCU 1.0
(ESP-12E Module)). If you are unsure which board you have, select the Generic ESP8266
Module.
Finally, connect the ESP8266 NodeMCU to your computer and select the Port.
Testing the Installation
Once you’ve finished the preceding steps, you are ready to test your first program with your
ESP8266! Launch the Arduino IDE. If you disconnected your board, plug it back in. The ESP8266
Arduino core includes several examples that demonstrate everything from scanning for nearby
networks to building a web server. To access the example sketches, navigate to File > Examples >
ESP8266. You will see a selection of example sketches. You can choose any of them to load the
sketch into your IDE and begin experimenting.
Installing the USB-to-Serial Bridge Driver
There are numerous ESP8266-based development boards available. Depending on the design,
you may need to install additional drivers for your USB-to-serial converter before you are able to
upload code to your ESP8266; for example, the ESP8266 NodeMCU uses either CP2102 or
CH340 to convert USB signals to UART signals. The drivers can be checked and installed through
the "Device Manager" of the connected system.
Note that, If you’ve never installed drivers for these USB-to-serial converters on your computer
before, you have to do it; otherwise the NodeMCU won’t be shown/connected in Arduino IDE.
The CP210x USB to UART Bridge Virtual COM Port (VCP) drivers are required for device
operation as a Virtual COM Port to facilitate host communication with CP210x products. This
driver can be downloaded at -
https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads
Installing the USB-to-Serial Bridge Driver
https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads
Click on the above link and download the below marked software version. After downloading, open
the zip file and install the driver. After the installation, you can open the device manager and see
that, under COM PORTS, your node MCU is listed. Enter that COM PORT in IDE, then your board is
ready.
ARDUINO SKETCH
void setup() {
Serial.begin(9600);
Serial.print("Hello World!");}
void loop()
{}
OUTPUT
In Serial Monitor
TASK 2
Write an Arduino Sketch to control on-board LED and externally connected LED to ESP8266-
NodeMCU.
ARDUINO SKETCH
//On-board LED
#define LEDA D4
//External LED
#define LEDB D0
void setup()
{
pinMode(LEDA, OUTPUT);
pinMode(LEDB, OUTPUT);
}
void loop()
{
digitalWrite(LEDA, HIGH);
digitalWrite(LEDB, HIGH);
delay(1000);
digitalWrite(LEDA, LOW);
digitalWrite(LEDB, LOW);
delay(1000);
}
CIRCUIT DIAGRAM
OUTPUT
Physical Observation
Both the On-board LED and Externally connected LED are turning ON and OFF as per the given
delay.
TASK 3
Write an Arduino Sketch to control on-board LED and externally connected LED to with on-board
FLASH button of ESP8266-NodeMCU.
ARDUINO SKETCH
int ledpin = 16; //GPIO 16 is on board LED, for external LED as in circuit diagram, use GPIO 5
int button = 0;
int buttonState=0;
void setup() {
pinMode(ledpin, OUTPUT);
pinMode(button, INPUT_PULLUP);
}
void loop() {
buttonState=digitalRead(button); // put your main code here, to run repeatedly:
if (buttonState == 1){
digitalWrite(ledpin, HIGH);
delay(200);
}
if (buttonState==0)
{
digitalWrite(ledpin, LOW);
delay(200);
}}
CIRCUIT DIAGRAM
TASK 4
Connect ESP8266-NodeMCU to Blynk Cloud Platform and write an Arduino Sketch in Arduino IDE to
control on-board LED/externally connected LED of ESP8266-NodeMCU, through Blynk Web and
Mobile Interfaces.
CONNECTING TO BLYNK PLATFORM
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.
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 lab task, we are controlling a LED connected to Esp8266 using
Blynk platform (Web and Mobile App - The latest available Blynk app can be used on
smartphones and computers. That is, it has a web application and a mobile application.)
Setting up the Blynk web Application
First, go to the Blynk website using your browser. Then, click the “Start Free” button and sign up
using your Gmail address.
Next, check your registered email address and click the new Blynk email. After that, create your
strong password as you like. Also, include the profile name and click the “done” button.
OK, now you can see the Blynk web app interface. Next, click the template button and create
your first template. For that, first include your template name, device name, and connection
type. Finally, click the “done” button.
Next, go to the data streams tab and select the Virtual PIN. Then, enter the name of
your choice. Also, select the PIN as V0 and select the data type as integer. Finally click
the “create” button.
Next, go to the Web dashboard tab. Now we can set up our web dashboard. For that,
drag and drop the widgets to the dash board; we used dragged one button. After, click
the setting icon on the button and selected the data stream we created earlier. Finally
click the save button.
Now, click the search icon and create a new device. For that, click the “New device”
button and select your template we created earlier; now the Blynk web app is ready for
us.
Setting up the Blynk Mobile Application
First, download and install the Blynk app from the Play Store or Apps Store on your phone.
Then, run your application and click the “Log In” button.
Next, enter your email and password that we created in the blynk web application. Now you can
see the template, we created in the web app. After that, click on this template and set up your
mobile dashboard.
Now, click the button in the upper right corner and add one button widget to the dashboard.
Then customize this button to your liking.
Next, click on this button and named it as you like. After, select data stream. For that,
select the data stream we created in the web app. Finally, change the button mode as a
switch; now mobile versions are ready for us.
Setting up the Arduino IDE
First, include the ESP8266 additional boards to the Arduino IDE. For that, click the 'File' and click
on 'Preferences' and include the board manager URL.
Additional Boards URL
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Next, go to the 'Tools' and click on the 'Board' and then on 'Board Manager' install the ESP8266
boards, by typing ESP 8266 in the searchbar.
Now, add Blynk and WIFI libraries to the Arduino IDE. To do this, click on ‘Sketch’ and click on
‘Libraries’ and click on “Add ZIP library” button and select the ZIP library file. Libraries download
links are given below;
Blynk library Link
https://drive.google.com/file/d/1dbCZECyzjI7zxE_Q136jA9--dHELAGNt/view?usp=sharing
ESP8266WIFI library Link
https://drive.google.com/file/d/1b-tHjcqBHVCgQKabdR19iGmo4E-pa2mW/view?usp=sharing
Setting up Arduino Sketch
In arduino sketch, include the Blynk auth token. It’s included in the web application. For
that, go to the “Device info” and copy and paste the Blynk auth token to the program.
Now, include the WIFI name and password and select board and port from tools menu
and make sure, the NodeMcu board is connected properly. After, upload this code to
the Nodemcu board.
Finally, open the Blynk web and mobile dashboards. Then, click the buttons and enjoy
this project.
CIRCUIT DIAGRAM
ARDUINO SKETCH
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "pe3o2t_MREjgPQe_W-kSLzFUqg1qm3dh";
char ssid[] = "Karthik";
char pass[] = "eswar@12345";
void setup()
{
Serial.begin(115200)
Blynk.begin(auth, ssid, pass);
pinMode(D2, OUTPUT);
}
void loop(){
Blynk.run();
}
BLYNK_WRITE(V0) {
int ledState = param.asInt();
digitalWrite(D2, ledState);
}
UNDERSTANDING param.asInt();
In Blynk, the server sends the current value of a virtual pin to the hardware as a parameter. This
parameter can be obtained within the BLYNK_WRITE(vPin) function using code like int
virtual_pin_value = param.asInt();. The param.asInt() function interprets the incoming data as an
integer. Other functions that can be used to interpret incoming data include;
param.asFloat();
param.asDouble();
param.asStr();
The raw data from the param buffer can also be obtained using param.getBuffer();
UNDERSTANDING blynk.run();
Blynk.run() is a main Blynk routine responsible for keeping connection alive, sending data,
receiving data, etc. When you use a delay() , you most likely are breaking a connection to Blynk
Cloud or blocking some functions of Blynk library sometimes, that also leads to a situation, where
basically, your sensor Value will never get to the Cloud.
OUTPUT
Physical Observation
Connected LED switched ON and switched OFF as per the button action in Blynk Web Server and
Blynk Mobile Application.
TASK 5
Connect DHT 11 sensor connected ESP8266-NodeMCU to Blynk Cloud Platform and write
an Arduino Sketch to monitor temperature and humidity through Blynk Web and Mobile Interfaces.
UNDERSTANDING DHT11 SENSOR
The DHT11 is a commonly used Temperature and humidity sensor. The sensor is also factory
calibrated and hence easy to interface with other microcontrollers.
The sensor can measure temperature from 0°C to 50°C and humidity from 20% to 90% with an
accuracy of ±1°C and ±1%. So if you are looking to measure in this range then this sensor might
be the right choice for you.
Physical Observation
When value 1 is given in serial monitor, it was observed that, AC Bulb is lightning up and when the
value 2 is given the AC Bulb is switching off.
TASK 9
TASK 10