Professional Documents
Culture Documents
IoT LAB
MANUAL
BY
Shriniwas Ghadyalji
BE – 2 – A
Batch Roll No. 04
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Experiment
No.1 Aim: Data Handling and storage
Temperature, Humidity data upload on Thingspeak on Arduino IDE
Title : to store and upload the weather data using DHT11 temperature and humidity sensor on
cloud ( ThingSpeak.com) using wifi modem NodeMCU.
Hardware: NodeMCU, DHT11 Temperature and Humidity sensor, Jumper Male to female
Introduction:
This experiment is used to log weather data on cloud. ThingSpeak.com is to be used as cloud
service provider and sensor DHT11 will be used to measure temperature and humidity data using
NodeMCU on Arduino IDE.
Building Circuit
1. Vin VCC
2. GND GND
3. D3 Data Out
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Circuit Layout:
2. Create a new channel by clicking on the button. Enter basic details of the channel. Then Scroll
down and save the channel.
3. Channel Id is the identity of your channel. Note down this. Then go to API keys copy
and paste this key to a separate notepad file will need it later.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
4. Programming:
Once the circuit part is done, NodeMCU is needed to be programmed. Here is the code to run
this circuit on NodeMCU.
#include <dht.h>
#define dht_apin D3 // Analog Pin sensor is connected to
#include <ESP8266WiFi.h>
dht DHT;
void setup()
{ Serial.begin(115200);
delay(10);
Serial.println("Connecting to
"); Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{ delay(500);
Serial.print(".")
;
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop()
{
DHT.read11(dht_apin);
float h = DHT.humidity;
float t = DHT.temperature;
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(3000);//Wait 3 seconds before accessing sensor again.
if (isnan(h) || isnan(t))
{
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Serial.println("Failed to read from DHT sensor!");
return;
}
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, set it to 30 seconds
delay(10000);
}
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Device: An IoT system comprises of devices that provide sensing, actuation, monitoring and control
functions.
Communication: The communication block handles the communication for the IoT system.
Services: An IoT system uses various types of IoT services such as services for device monitoring,
device control services, data publishing services and services for device directory.
Management: Management functional block provides various functions to govern the IoT system.
Security: Security functional block secures the IoT systems and by providing functions such as
authentication, authorisation, message and content integrity and data security.
Application: IoT applications provide an interface that the users can use to control and monitor
various aspects of the IoT system. Applications also allow users to view the system status and view or
analyse the processed data.
A Wireless Sensor Technology comprises of distributed devices with sensors which are used to monitor
the environmental and physical conditions. A WSN consist of number of end-nodes and routers and a
coordinator. End nodes have several sensors attached to them. End nodes can also act as routers. Routers
are responsible for routing the data packets from end nodes to the coordinator. The coordinator collects
the data from all the nodes. Coordinator also acts as a gateway that connects the WSN to the internet.
A Wireless Sensor Technology comprises of distributed devices with sensors which are used to monitor
the environmental and physical conditions. A WSN consist of number of end-nodes and routers and a
coordinator. End nodes have several sensors attached to them. End nodes can also act as routers. Routers
are responsible for routing the data packets from end nodes to the coordinator. The coordinator collects
the data from all the nodes. Coordinator also acts as a gateway that connects the WSN to the internet.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Experiment No.2
Aim: Data Handling and storage
Gas Level Monitoring Over Internet Using NodeMCU and & Gas Sensor on Thingspeak
on Arduino IDE
Title : To monitor pollution on thingspeak using Node MCU and MQ135sensor on cloud
( ThingSpeak.com) using wifi modem NodeMCU.
Hardware: NodeMCU, MQ135sensor, Jumper Male to female
Introduction:
This experiment is used to log pollution data on cloud. ThingSpeak.com is to be used as cloud
service provider and sensor MQ135 will be used to detect and identify different types of gasses
data .
MQ135:
The MQ-135 gas sensor senses the gases like ammonia nitrogen, oxygen, alcohols,
aromatic compounds, sulfide and smoke. The MQ-3 gas sensor has a lower conductivity to clean
the air as a gas sensing material. In the atmosphere we can find polluting gases, but the
conductivity of gas sensor increases as the concentration of polluting gas increases. MQ-135 gas
sensor can be implementation to detect the smoke, benzene, steam and other harmful gases. It
has potential to detect different harmful gases. It is with low cost and particularly suitable for Air
quality monitoring application.
The MQ135 sensor is a signal output indicator instruction. It has two outputs: analog
output and TTL output. The TTL output is low signal light which can be accessed through the IO
ports on the Microcontroller. The analog output is an concentration, i.e. increasing voltage is
directly proportional to increasing concentration. This sensor has a long life and reliable stability
Mahavir Education
Trust's
Shah & Anchor
Kutchhi
Engineering
as well
College,
Chembur, Mumbai
400 088
UG Program in
Electronics
Engineering
Features
• High Sensitivity
• Detection Range: 10 – 300 ppm NH3, 10 – 1000 ppm Benzene, 10 – 300 Alcohol
• Dimensions: 18mm Diameter, 17mm High excluding pins, Pins – 6mm High
Building Circuit
1. Vin VCC
2. GND GND
3. A0 A0
Circuit Layout:
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
2. Create a new channel by clicking on the button.Enter basic details of the channel.Than
Scroll down and save the channel.
3. Channel Id is the identity of your channel. Note down this. Than go to API keys copy
and paste this key to a separate notepad file will need it later.
4. Programming:
#include <ESP8266WiFi.h>
String apiKey = "9OIFHW3MDEDJC7ZL"; // Enter your Write API key from ThingSpeak
const char *ssid = "SK"; // replace with your wifi ssid and wpa2 key
const char *pass = "12345678";
const char* server = "api.thingspeak.com";
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println("Connecting to
"); Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
}
void loop()
{
float p = analogRead(A0);
if (client.connect(server, 80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr += "&field1=";
postStr += String(p);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Polution: ");
Serial.println(p);
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
delay(1000);
}
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Number of 4 16
messag
e types
used
Level 5: A level – 5 IoT system has multiple end nodes and one coordinator node. The
end nodes perform sensing and/or actuation. The coordinator node collects data from the
end nodes and sends it to the cloud. Data analyzed in the cloud and the application is
cloud-based. Level – 5 IoT systems are suitable for solutions based on wireless sensor
networks, in which the data involved is big and the analysis requirements are
computationally intensive.
Level 6: A level-6 IoT system has multiple independent end nodes that perform sensing
and/or actuation and send data to the cloud. Data is stored in the cloud and the application
is cloud-based. The analytics component analyses the data and stores the results in the
cloud database. The results are visualized with the cloud-based applications. The
centralized controller is aware of the status of all the end nodes and sends control
commands to the nodes.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Experiment No.3
Title : To control relay for electrical appliances using blynk app and wifi modem NodeMCU.
Introduction:
This experiment is used to control the relay through blink cloud using node mcu and wifi. In
blynk cloud we have to make one account for your cloud.
Blynk app for iOS and Android is the easiest way to build your own mobile app that work with
the hardware of your choice. No iOS or Android coding required. We also required blynk
libraries to run this experiment. Blynk Library is an extension that runs on top of your hardware
application. It handles all the connection routines and data exchange between your hardware,
Blynk Cloud, and your app project.
Building Circuit
1. Vin VCC
2. GND GND
3. D1 Relay
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Circuit Layout:
STEP 1
Configure the Blynk app.
Download the Blynk app from playstore for Andriod devices.
STEP 2
Sign up with your email and password.
STEP 3
Creat a new project. The steps are given below:
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Mahavir Education
Trust's
Shah & Anchor
Kutchhi
Engineering
STEP 4
College,
Chembur, Mumbai
400 088
UG Program in
Electronics
Engineering
Add widgets to the app as required, in this experiment we are going to control one device.
So need 1 switches. Drag and drop it for your imagination.
STEP 5
Change the logic from 0-1 to 1-0 because the output of NodeMCU is active LOW. Select
digital pins D1 as output pins. change mode to switch from push.
STEP 6
Select the device you are going to communicate, which is the NodeMCU.
Mahavir Education
Trust's
Shah & Anchor
Kutchhi
Engineering
STEP 7
College,
Chembur, Mumbai
400 088
UG Program in
Electronics
Engineering
Send the authentication code to your e-mail.
STEP 8
Set up the circuit as per the schematics.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
STEP 9
Open Arduino IDE.
Configure it for NodeMCU.
STEP 10
Write the code and upload it in node mcu.
Execute it.
Programming:
Once the circuit part is done, NodeMCU is needed to be programmed. Here is the code to run
this circuit on NodeMCU.
i. HTTP
ii. CoAP
iii. WebSocket
iv. MQTT
v. XMPP
vi. DDS
vii. AMQP
A serial interfaces uses a protocol for serial communication. A microcontroller includes interfaces for
serial communication. UART and several other protocols are popularly used. Wired communication can
be:
• Serial asynchronous communication, such as, using UART communication. A RFID reader uses a
125kHz RFID UART module. A GPS device also sends serial data using UART.
• Synchronous serial-communication devices, such as sensors which can communicate serial data using
I2C or SPI interfaces in wired bus communication.
Automotive sensors communicate serial data using LIN, CAN, MOST, IEEE 1394 serial protocols.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Experiments No.4
Introduction:
MQTT is a publish-subscribe-based messaging protocol used in the internet of Things. ...
The goal is to provide a protocol, which is bandwidth-efficient and uses little battery power.
MQTT is a messaging protocol i.e it was designed for transferring messages, and uses a publish
and subscribe model. This model makes it possible to send messages to 0,1 or multiple clients. ...
In MQTT a publisher publishes messages on a topic and a subscriber must subscribe to that topic
to view the message.
This will send a subscription message to the MQTT broker which is currently running on
the same system. But it could be running somewhere else, as you’ll see later.
So long as the mosquitto_sub programme is running you’re listening to
the test/message topic as an MQTT client.
4. Publish to the MQTT Topic Locally
Because your current terminal is occupied listening to the topic, you’ll need to open
another terminal. You can do this using another SSH session or on the Raspbian GUI,
depending how your system is configured.
Once open, publish message to the test topic like this:-
mosquitto_pub –d -t test -m "Hello, world"
If you look back at the first terminal now you should see this:-
Hello, world
An IP header consists of source and destination addresses, called IP address. The Internet generally uses
IPv4 addresses. IoT/M2M use IPv6 address.
IP version 4 address consists of 32 bits. However, it can be considered as four decimal numbers
separated by dots. Ranges from 0.0.0.0 to 255.255.255.255.
Devices (nodes) in IoT need large number of addresses. IP version 6 uses 128 bit address. A
hexadecimal digit represents 4-bit, 0 hex = 0000 binary to hex = 1111. Therefore, 128 bit address has 32
hexadecimal digits.
IPv6 addresses are classified into three classes. Unicast address is for a single network interface.
Anycast address means address for a group of nodes or interfaces. Multicast address means an address
used by multiple hosts, which acquires the multicast address destination by participating in the multicast
distribution protocol among network routers.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Experiment No.6
Aim: To capture image and send image through email using Raspberry Pi
Title : To capture the image from Raspberry pi camera and send image through the email using
Raspberry pi and python.
Introduction:
This experiment is used to capture image from raspberry pi camera. The image is stored in Rpi
and the it is send as attachment through the email.
Raspberry Pi Camera:
This package provides a pure Python interface to the Raspberry Pi Camera module for
Python 2.7 (or above) or Python 3.2 (or above).
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
After that, open the terminal box and enter your default PI name and password.
Username (pi)
Password (raspberry)
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Step 2
Next, we need to update the Raspberry Pi. So, install the latest packages. You can do that
using the following commands.
sudo apt-get update
sudo apt-get upgrade
or
sudo apt-get update && upgrade
If you want to install Python 3.0
sudo apt-get install python3
Install an SMTP service
sudo apt-get install ssmtp
Configure the SMTP
sudo nano /etc/ssmtp/ssmtp.conf
Step 3
Next, you need to enable the permissions and options like SSH and Camera. So, go to
Raspberry Pi configuration.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Step 4
Open the Python IDE 2.7 or above 3.2, create a new file and save it as camera.py. It’s
important that you do not save it as picamera.py
Write the Camera testing code as given below.
1. from picamera import PiCamera
2. from time import sleep
3. camera = PiCamera()
4. camera.start_preview()
5. sleep(05)
6. camera.stop_preview()
Save with Ctrl + S and run with F5. The camera preview should be shown for 05 seconds,
and then close.
or
Run the program.
sudo python camera.py
Note: Allowing Gmail SMTP Access for Accounts with Standard Authentication
o To allow access to Gmail’s SMTP server from your app, you can follow
these steps,
o Login to your Gmail account using your username and password.
o From the top right corner go to “My Account“.
o Under “Sign-in & security” section locate “Connected apps & sites” and click on
it.
o Locate “Allow less secure apps” setting and turn it “On“.
Code:
1. import smtplib,ssl
2. from picamera import PiCamera
3. from time import sleep
4. from email.mime.multipart import MIMEMultipart
5. from email.mime.base import MIMEBase
6. from email.mime.text import MIMEText
7. from email.utils import formatdate
8. from email import encoders
9.
10. camera = PiCamera()
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
11.
12. camera.start_preview()
13. sleep(5)
14. camera.capture('/home/pi/image.jpg') # image path set
15. sleep(5)
16. camera.stop_preview()
17. def send_an_email():
18. toaddr = 'raviraw299@gmail.com' # To id
19. me = 'raviraw299@gmail.com' # your id
20. subject = "What's News" # Subject
21.
22. msg = MIMEMultipart()
23. msg['Subject'] = subject
24. msg['From'] = me
25. msg['To'] = toaddr
26. msg.preamble = "test "
27. #msg.attach(MIMEText(text)) 28.
29. part = MIMEBase('application', "octet-stream")
30. part.set_payload(open("image.jpg", "rb").read())
31. encoders.encode_base64(part)
32. part.add_header('Content-
Disposition', 'attachment; filename="image.jpg"') # File name and format
name
33. msg.attach(part)
34.
35. try:
36. s = smtplib.SMTP('smtp.gmail.com', 587) # Protocol
37. s.ehlo()
38. s.starttls()
39. s.ehlo()
40. s.login(user = 'raviraw299@gmail.com', password = '*********') #
User id & password
41. #s.send_message(msg)
42. s.sendmail(me, toaddr, msg.as_string())
43. s.quit()
44. #except:
45. # print ("Error: unable to send email")
46. except SMTPException as error:
47. print ("Error") # Exception
48.
49. send_an_email()
Save with Ctrl + S and run with F5. When you check your mail, you will find that the image has
been received.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering