0% found this document useful (0 votes)
61 views

CO352 - Lab Manual - IoT With Cloud Computing Lab

Uploaded by

Prudhvi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

CO352 - Lab Manual - IoT With Cloud Computing Lab

Uploaded by

Prudhvi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 97

TASK 1

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

ESP-12 LED (GPIO 2) NodeMCU LED (GPIO 16)


NODEMCU ESP8266 - PINOUT
UNDERSTANDING NODEMCU - WITH ARDUINO IDE
 The NodeMCU (Node MicroController Unit) is an open-source software and hardware
development environment built around an inexpensive System-on-a-Chip (SoC) called the
ESP8266. The ESP8266, designed and manufactured by Espressif Systems, contains the crucial
elements of a computer: CPU, RAM, networking (WiFi), and even a modern operating system
and SDK. That makes it an excellent choice for Internet of Things (IoT) projects of all kinds.
 The NodeMCU offers a variety of development environments, including compatibility with the
Arduino IDE (Integrated Development Environment).
 Before you can use the Arduino IDE to program the ESP8266, you must first install the ESP8266
board (also known as the ESP8266 Arduino Core) via the Arduino Board Manager. The following
steps will walk you through the process of downloading, installing, and testing the ESP8266
board in IDE with a sample program.
Setting up the Arduino IDE for ESP8266 NodeMCU
 The first step in interfacing the ESP8266 to Arduino IDE is to have the latest version of the
Arduino IDE installed on your computer, latest means version-1.8 or above but not below
version - 1.8.
 After installing the IDE, open it and click on the "File" in menu bar and click on the
"Preferences"; in the additional boards manager, enter below URL and click "OK".
Link - http://arduino.esp8266.com/stable/package_esp8266com_index.json

 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.

Vcc - Power supply 3.5V to 5.5V


Data - Outputs both Temperature and Humidity
through serial Data
NC - No Connection and hence not used
Ground - Connected to the ground of the circuit
CIRCUIT DIAGRAM
ARDUINO SKETCH
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
char auth[] = "pe3o2t_MREjgPQe_W-kSLzFUqg1qm3dh";
char ssid[] = "Karthik"; //Enter your WIFI Name
char pass[] = "eswar@12345"; //Enter your WIFI Password
#define DHTPIN 1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V0, h);
Blynk.virtualWrite(V1, t);
}
void setup(){
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dht.begin();
timer.setInterval(1000L, sendSensor);
}
void loop(){
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
OUTPUT
Physical Observation
Temperature and Humidity readings are seen in live in both web dashboard and mobile
application interface.
TASK 6
Draw the pin out of Pulse Sensor module and interface it to ESP8266-NodeMCU and write
an Arduino Sketch to print live Pulse of user.
CIRCUIT DIAGRAM
ARDUINO SKETCH
int PulseSensorPurplePin = 0;
int LED13 = 13;
int Signal;
int Threshold = 550;
void setup()
{
pinMode(LED13,OUTPUT);
Serial.begin(9600);
}
void loop() {
Signal = analogRead(PulseSensorPurplePin);
Serial.println(Signal);
if(Signal > Threshold){
digitalWrite(LED13,HIGH);
} else {
digitalWrite(LED13,LOW);}
delay(10);
}
OUTPUT
TASK 7
Connect ESP8266-NodeMCU to Arduino IoT Cloud platform and write an Arduino Sketch in Arduino
IDE to control on-board LED/externally connected LED of ESP8266-NodeMCU, through Arduino IoT
Cloud Platform.
CONNECTING TO ARDUINO IOT CLOUD PLATFORM
So to get started with the Arduino IoT Cloud you will need to first create an account; when the
page is opened, click on the "GET STARTED FOR FREE" button and then enter your credentials and
click on "SIGN IN". If you are a returning user and you have an account on the Arduino then you can
simply log into your account using user username or email and a password. If you are a new user
then you can click on the "Create One" as you can see in the screenshot.
Adding a Device
 Now, here after the login process, first of all, we need to add a device; So after adding your
device, it will be creating two credentials we can save, one is the device id and the next is the
secret key. Now we need to save both parameters, we can say inside our computer because we
will be requiring these parameters at the time of coding, so for that, you just need to click on
download the pdf and it will automatically download the credentials pdf on your computer. The
pdf containing all the data, after that, click on I saved my device id and secret key and click on
continue. Now with this, we have successfully added a device as well and click on the done.
Associate Device
 As a further step, navigate to "Associated device: and click on the "Select device" button, an
then select the device which you have added in the previous step. This step, make sures that,
your device is associated with the current work space.
Configure Network
 Now navigate to, "Network" menu, which is right under the "Associated device" space. Here
enter the, network details; username, password and secret key (whick we havesaved earlier,
while creating the device). This step is for providing the wi-fi credentials because this is an IoT
project and this ESP8266 board does require internet connectivity. So this network
configuration process is mandatory.
Adding Variable
 For creating a variable, so just click on "add variable". After that, you just need to name the
variable, so as we want to make a project for controlling an LED. So we will require only one
variable. So let’s just add it. We will name the first variable as 'led' and type is boolean. Now, in
the variable permission select the read and write and in variable update policy select the on
change and then click on the add variable.
Create Arduino Sketch
 Unlike other cloud platforms, in Arduino IoT cloud, we have a builtin web based IDE, from which
we can connect to the NodeMCU through our PC's USB. When clicked on the "Sketch" tab, you
can see the automatically generated sketch available to be edited. This sketch includes all
necessities to connect to the cloud, and has a callback function generated for each read/write
variable, we have created in the previous steps.
 For us, a sketch is generated for a single boolean variable called led (we created it in previous
steps). We modified it to as we mentioned in the sketch slide, for proper functionality.
Creating a Web Dashboard
 To control the state of the "led" variable, we have created earlier, we can setup a dashboard and
a switch widget. This will allow us to control the LED remotely.
 Go to Dashboards, and create a new dashboard.
 Click on the edit button at the top left, then on the "Add" button. Select the Thing you want to
associate it with, and then click on "Create Widgets".
 A switch widget will have generated, which is now linked to your board. Flicking it should control
the state of the LED (on/off).
Mobile Application (Arduino IoT Cloud Application)
 The Arduino IoT Remote phone application lets you control and monitor all of your dashboards
in the Arduino Cloud.
 To use the Arduino IoT Remote app, visit Google Play / App Store and search for "Arduino IoT
Remote".
 After installing the app, you will need to log in to your Arduino account. After you login, you will
discover all of your dashboards (if you have any), in the main menu.
CIRCUIT DIAGRAM
ARDUINO SKETCH
#include "thingProperties.h"
void setup()
{
Serial.begin(9600);
delay(1500);
pinMode(5, OUTPUT);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
}
void onLedChange()
{
if(led)
{
digitalWrite(5, HIGH);
}
else
{
digitalWrite(5, LOW);
}
}
OUTPUT
Physical Observation
External LED connected to D1 (GPIO5 for Arduino IDE) of NodeMCU is working according to the
action of button slider; in the Arduino IoT Cloud’s web Interface and Mobile Application Interface.
TASK 8
Draw and explain the Pinout and Working of Single Channel Relay and write an Arduino Sketch to
control AC Bulb using ESP8266 NodeMCU.
UNDERSTANDING RELAY
A single-channel relay is an electronic switch that can be controlled by a low-power electrical
signal, such as the output from an Arduino microcontroller/NodeMCU. By using such low-power
electrical signa, a single-channel relay module can control high-voltage or high-power devices,
such as lights, motors, and appliances, from your computer or mobile device.

VCC - this pin provides power to the module.


GND - this is the common ground.
IN - this pin is also called the control pin because it is used to control the output of the relay.
COM - is connected to the device you intend to connect.
NC - is connected to the COM terminal by default unless you activate the relay which breaks the connection.
NO - is normally open unless you activate the relay which then connects it to the COM terminal.
 Think of a relay like a switch that is controlled by electricity. Instead of you physically flipping
the switch, an electrical signal does it for you. Here's how it works:
 An electrical current flow through the coil of wire around the relay's electromagnet, creating a
magnetic field. This magnetic field attracts the metal armature inside the relay and causes it to
move, making contact with a switch. This switch can then control the flow of electricity to a
high-power device, like a light, motor, or heating element.
 When the electrical current to the coil is turned off, the magnetic field disappears, and the
armature returns to its original position, breaking the connection to the switch. In this way, a
relay acts like a switch that can be controlled remotely. It allows you to control a high-power
device with a low-power electrical signal, making it very useful in many applications, such as
automotive electronics, home automation, and industrial control systems.
220 V 220 V

NO INPUT VOLTAGE APPLIED INPUT VOLTAGE


FROM NODE MCU FROM NODE MCU
CIRCUIT DIAGRAM
ARDUINO SKETCH
void setup()
{
pinMode(D8, OUTPUT);
Serial.begin(9600);
while (!Serial);
Serial.println("Input 1 to Turn LED on and 2 to off");
}
void loop() {
if (Serial.available())
{
int state = Serial.parseInt();
if (state == 2)
{
digitalWrite(D8, HIGH);
Serial.println("POWER OFF");
}
if (state == 1)
{
digitalWrite(D8, LOW);
Serial.println("POWER ON");
}
}
}
OUTPUT
In Seral Monitor

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

You might also like