100% found this document useful (1 vote)
36 views40 pages

IoT Lab Theory

Uploaded by

Prathamesh Parit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
36 views40 pages

IoT Lab Theory

Uploaded by

Prathamesh Parit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

IoT Lab Manual

1|Page
CONTENTS

2|Page
INTRODUCTION
The Raspberry Pi IoT Project Board designed to be a comprehensive tool to accelerate learning of IoT
Fundamentals and apply the concepts to get Hands-On experience by performing different experiments.
It can also be used by students and faculty alike to implement projectsbased on IoT concepts.
Flexibility is at the heart of the Kit, and accordingly the students and faculty can not only use the
hardware on the board in imaginative ways, but also innovativelywrite programs to try their own use
cases. This user manual provides the descriptions of the features and also examples of use cases, to
guide the students to use it effectively.

This Raspberry Pi Project Board has a Raspberry Pi 4 Model B Controller. It helps the students perform
IoT related experiments based on the requirement. It provides all the open ports to connect various
multiple sensors which helps the students to develop number of applications based on IoT. It also
supports different hardware communications protocols like i2C and SPI. The kit has two on board
sensors like temperature sensor; light sensor and an externally connected DHT11 sensor to perform IoT
end to end operation from sensors to cloud. As the kit has internal Wi-Fi module the students can send
the different sensors information to the cloud. One can write the code using different Python IDEs like
Thonny, IDLE and Geany

3|Page
1. RASPBERRY Pi 4 PROJECT BOARD SPECIFICATIONS

Hardware Description:
1. Raspberry Pi 4 Model B.
2. 5V & 3.3V Power Supply Section.
3. MCP3008.
4. OLED.
5. Stepper Motor Interface.
6. Relay Modules – 2 nos.
7. Buzzer.
8. Switches – 2 nos.
9. LEDs – 2 nos.
10. Light Sensor.
11. LM35 Temperature Sensor.
12. DHT11 Humidity and Temperature Sensor (External).
13. DC Motor (External).

4|Page
Specifications:
 The Board is driven using Raspberry Pi 4 Controller.
 Facilitates MQTT or HTTP application protocol connection to various IoT cloud
platforms such as Thingspeak, AWS.
 It can be connected to a Private Cloud.
 On board voltage regulator for generating 3.3V from +5V input through power supply
/adapter.

 Internal Wi-Fi connectivity through which board can be connected to internet through
Router.
 On board simple analog sensors like Temperature and Light.
 Onboard ADC MCP3008 to connect analog sensors to raspberry pi 3.
 On board Organic LED Display to display colorful text as well as images.
2 LED's and 2 Switches.
 On board stepper motor driver to drive 5V stepper motor.
 One Buzzer.
 Internal Bluetooth 4.2 to communicate with other Bluetooth modules or mobile Apps.
 Provided extra connectors for connecting external analog and digital sensors so that
students can explore their projects.
 I2C, SPI communication protocols.
 On board Relay to drive external device (DC Motor).
 DHT11 Sensor (External Interface).
 Several onboard outputs can be accomplished through events from cloud such as
turning on LED’s or sending a test message to the display is possible.

 Outputs can be programmed to be event or threshold driven.


 Performance of IoT experiments and design / implementation of student projects
possible including provision to write their own programs.

5|Page
3. HARDWARE DETAILS
3.1. Raspberry Pi 4 Model B.

Fig. 3.2: Raspberry Pi 3 B.

Specifications:
 Broadcom BCM2711, Quad core Cortex-A72 (ARM v8) 64-bit SoC @ 1.8GHz
 1GB, 2GB, 4GB or 8GB LPDDR4-3200 SDRAM (depending on model)
 2.4 GHz and 5.0 GHz IEEE 802.11ac wireless, Bluetooth 5.0, BLE
 Gigabit Ethernet
 2 USB 3.0 ports; 2 USB 2.0 ports.
 Raspberry Pi standard 40 pin GPIO header (fully backwards compatible with
previous boards)
 2 × micro-HDMI® ports (up to 4kp60 supported)
 2-lane MIPI DSI display port
 2-lane MIPI CSI camera port
 4-pole stereo audio and composite video port
 H.265 (4kp60 decode), H264 (1080p60 decode, 1080p30 encode)
 OpenGL ES 3.1, Vulkan 1.0
 Micro-SD card slot for loading operating system and data storage
 5V DC via USB-C connector (minimum 3A*)
 5V DC via GPIO header (minimum 3A*)
 Power over Ethernet (PoE) enabled (requires separate PoE HAT)
 Operating temperature: 0 – 50 degrees C ambient

6|Page
3.2. Connection Details.
3.2.1 U1 Connector: 40 pin 20X2 Header is connected to the Raspberry pi 4 B.
Pin Description Pin Description
1 (3.3V) 2 (5V)
3 I2C1 SDA / GPIO 2 4 (5V)
5 I2C1 SCL / GPIO 3 6 GND
7 P7/GPIO 4 8 P8/GPIO 14/ TXD (UART)
9 (GND) 10 P14/GPIO 15/ RXD (UART)
11 P11/GPIO 17 12 P12/GPIO 18/ CM_CLK
13 P13/GPIO 27 14 (GND)
15 P15/GPIO 22 16 P16/GPIO 23
17 (3.3V) 18 P18/GPIO 24
19 P19/GPIO 10/ MOSI (SPI0) 20 (GND)
21 P21/GPIO 9/ MISO (SPI0) 22 P22/GPIO 25
23 P23/GPIO 11/ SCLK (SPI0) 24 P24/GPIO 8/ CS0 (SPI0)
25 (GND) 26 P26 /GPIO 7/CS1 (SPI0)
27 Reserved (P27/ID_SD(I2C)) 28 Reserved (P28/ID_SC(I2C))
29 P29/GPIO 5/ GPCLK1 30 (GND)
31 P31/GPIO 6 32 P32/GPIO 12
33 P33/GPIO 13 34 (GND)
35 P35/GPIO 19 MISO (SPI1) 36 P36/GPIO 16/ CS0 (SPI1)
37 P37/GPIO 26 38 P38/GPIO 20/ MOSI (SPI1)
39 (GND) 40 P40/GPIO 21/ SCLK (SPI1)
3.2.2 J1 Connector: 2 Pin Male Burg connector From LM35.
Pin Description
1 DATA
2 VCC
3.2.3 J1A Connector: 2 Pin Male Burg connector to Raspberry Pi 4 from LM35.
Pin Description
1 A0
2 VCC

3.2.4 J2 Connector:2 pin Male Burg Pins from LDR Module.


Pin Description
1 DATA
2 VCC
3.2.5 J2A Connector:2 pin Male Burg Pins to Raspberry Pi 4 from LDR Module.

7|Page
Pin Description
1 A1
2 VCC
3.2.6 J3 Connector: 4 Pin Male Burg Pins from OLED.
Pin Description
1 GND
2 VCC
3 SCL
4 SDA
3.2.7 J3A Connector: 4 Pin Male Burg Pins to Raspberry Pi 4 from OLED.
Pin Description
1 VCC (GND)
2 GND(VCC)
3 SCL
4 SDA
3.2.8 J4 Connector: 5 Pin Male Burg Pins from LED & Switches.
Pin Description
1 L1
2 L2
3 S1
4 S2
5 VCC
3.2.9 J4A Connector: 5 Pin Male Burg Pins to Raspberry Pi 4 from LED & Switches.
Pin Description
1 P31
2 P33
3 P35
4 P37
5 VCC
3.2.10 J8 Connector: 4 Pin Male Burg Pins from Relays & Buzzer.
Pin Description
1 RLY1
2 RLY2
3 BUZ
4 VCC
3.2.11 J8A Connector: 4 Pin Male Burg Pins to Raspberry Pi 4 from Relays & Buzzer.

8|Page
Pin Description
1 P36
2 P12
3 P38
4 VCC
3.2.12 J9 Connector: 5 Pin Male Burg Pins from Stepper Motor.
Pin Description
1 IN1
2 IN2
3 IN3
4 IN4
5 VCC
3.2.13 J9A Connector: 5 Pin Male Burg Pins to Raspberry Pi 4 from Stepper Motor.
Pin Description
1 P16
2 P18
3 P22
4 P32
5 VCC
3.2.14 J12 & J13 Connectors: 2 Pin Male Burg Pins for I2C
Pin Description
1 SDA
2 SCL
3.2.15 J10 & J11 Connectors: 4 Pin Male Burg Pins for SPI Connection.
Pin Description
1 D10 (P23)
2 D11(P21)
3 D12(P19)
4 D13(P24)

3.2.16 J14 & J15 Connector: 15 Pin Male Burg Pins for External GPIO Pins.
Pin Description
1 P11
2 P13
3 P15
4 P29

9|Page
5 SDA
6 SCL
7 P16
8 P18
9 P22
10 P26
11 P27

12 P28
13 P32
14 P40
15 P12
3.2.17 J16 & J17 Connector: 12 Pin Male Burg Pins for External GPIOs.
Pin Description
1 P29
2 P31
3 P7
4 P33
5 P35
6 P37
7 P36
8 P38
9 P24
10 P19
11 P21
12 P23

3.2.18 J18 Connector: 10 Pin Male Burg Pins for GND.


3.2.19 J19 Connector: 10 Pin Male Burg Pins for VCC (5V).
3.2.20 J20 Connector: 10 Pin Male Burg Pins for 3.

10 | P a g e
4. INSTALLATION PROCEDURE
Installing Raspbian OS for Raspberry Pi 4 Model B using Raspbian Stretch OS Image
Downloaded in. zip format.

1. Download the image file in the form Zip file from the following
link https://www.raspberrypi.org/downloads/raspbian/

Fig. 4.12: Download Raspbian Stretch

2. Download the win32 Disk Imager Software to write the image file to SD Card from
the following link. https://sourceforge.net/projects/win32diskimager/
3. Now insert the SD Card in SD card slot and connect it to PC/Laptop.
4. Open Win32 Disk Imager, choose the .img or image file you want to write as Image
File and choose the SD drive as Device and press Write.
5. The write may take a while. Once it is done, remove the SD card and insert it into
the device you want to use with.
Initial Setup for Raspberry Pi 4 B.

1. Once Raspberry Pi 4 B is booted up to GUI, Connect the keyboard and Mouse to USB
slots.
2. Change the following
a. language: English
b. Country and Time Zone: India and Kolkata
3. From menu-->Preferences-->Raspberry Pi 4 B Configuration.
Then Go To Interfaces
Enable Camera, SSH, VNC, SPI, I2C, Serial Port. Don't Enable Remaining Things.
4. Connect to WiFi.
5. Check the date and Time.
6. Open the Terminal.
Execute following default commands.
a. sudo apt-get update
b. sudo apt-get upgrade
c. sudo apt-get install build-essential python-dev python-smbus python-pip

7. Now you can write your programs at Thonny Python


IDE. Menu → Programming → Thonny Python IDE.
File → New ….. You can write your Program here and save.
8. Execute the program at terminal only by following command
sudo python <program-name>.py

11 | P a g e
Experiment No.1

1. A) To interface LED/Buzzer: To “turn ON” LED/Buzzer for 1 second after


every 2 seconds.

B) LED Button To “turn ON” LED when push button is pressed

Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter cable, Power supply
Adapter and Connecting wires, etc.

Theory:
Switch and LED's are combination of 2 LED's and 2 switches which are programmed to operate LED's using the
switch

Schematic Pin Diagram of Switches and LED's.

Buzzer
Buzzer is an output module which can be used to show the result of any program as a sound.
Providing VCC to BUZZ pin will
blow the Buzzer.

Schematic Pin Diagram of Buzzer

Light Sensor.
A Light Sensor generates an output signal indicating the intensity of light by measuring the
radiant energy that exists in a very narrow range of frequencies basically called “light”, and
which ranges in frequency from “Infrared” to “Visible” up to “Ultraviolet” light spectrum.

The light sensor converts this “light energy” whether visible or in the infrared parts of the
12 | P a g e
spectrum into an electrical signal output. From “Infrared” to “Visible” up to “Ultraviolet” light
spectrum. Sensitivity can be adjusted through potentiometer.

Specifications:

● Using photosensitive resistance sensor sensitive type.


● Working Voltage: 3.3V-5V.
● Output form: Digital Switch show (0 for Brightness and 1 for darkness).
● Fixed Bolt Hole, easy installation.

Fig. 5.20: A) Light Sensor B) Schematic Pin Diagram of Light Sensor.

Connection:

1. For LED Connect J4A PIN-1,3,5 to J4 PIN-1,3,5


2. For Buzzer connect J8A PIN-3,4 to J8 PIN-3,4 Connected Pin details: LED1 – P31/ BUZ – P38
3. Save and run the program.

Result: LED1 will turn On-Off / Buzzer will turn ON- OFF.

13 | P a g e
1. B) LED Button: To “turn ON” LED when push button is pressed

Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter cable, Power supply
Adapter and Connecting wires, etc

Connection:

For LED Connect J4A PIN-1,3,5 to J4 PIN-1,3,5

Save and run the program.

Result: LED1 will turn On-Off with Switch 1 being pressed.

14 | P a g e
Experiment No.2

2. A) To interface DHT11 Sensor and print temperature and humidity readings.


B) To interface OLED and print temperature and humidity readings.

Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter cable,
Power supply Adapter and Connecting wires, DHT11 sensor etc
Theory: Temperature and Humidity Sensor
The DHT11 is a digital temperature and humidity sensor. It uses a humidity sensor and a
thermistor to measure the surrounding air, and spits out a digital signal on the data pin. It's
fairly simple to use, but requires careful timing to grab data. You can only get new data from
it once every 2 seconds, so when using our library, sensor readings can be up to 2 seconds
old.

Specifications:
 Operating Voltage: 3.5V to 5.5V
 Operating current: 0.3mA (measuring) 60uA (standby)
 Output: Serial data
 Temperature Range: 0°C to 50°C
 Humidity Range: 20% to 90%
 Resolution: Temperature and Humidity both are 16-bit
 Accuracy: ±1°C and ±1%

Fig. 5.24: A) Temperature and Humidity Sensor. B )Schematic Pin Diagram of Temperature and Humidity
Sensor

LM35
The LM35 series are precision integrated-circuit temperature devices with an output voltage
linearly proportional to the Centigrade temperature. LM35 is three terminal linear tempera-
ture sensor from National semiconductors. It can measure temperature from -55 degree
Cel- sius to +150 degree Celsius. The voltage output of the LM35 increases 10mV per degree
Cel- sius rise in temperature. LM35 can be operated from a 5V supply and the stand by
current is less than 60uA. The pin out of LM35 is shown in the figure below.

15 | P a g e
Features

 Calibrated Directly in Celsius (Centigrade)


 Linear + 10-mV/°C Scale Factor
 0.5°C Ensured Accuracy (at 25°C)
 Rated for Full −55°C to 150°C Range
 Suitable for Remote Applications
 Low-Cost Due to Wafer-Level Trimming

 Operates from 4 V to 30 V
 Less than 60-μA Current Drain
 Low Self-Heating, 0.08°C in Still Air
 Non-Linearity Only ±¼°C Typical
 Low-Impedance Output, 0.1 Ω for 1-mA Load

Connection: Connect Data pin to PIN-7 on the board.

Connected Pin details: Data to J16 PIN-7, GND to J18, Vcc to

J19 Result: Temperature and humidity readings will be

displayed

16 | P a g e
2.B) Aim: To interface OLED and print temperature and humidity readings.

Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter cable,
Power supply Adapter and Connecting wires, DHT11 sensor, OLED etc

Theory: OLED Display.


The term OLED stands for “Organic Light emitting diode” it uses the same technology that is
used in most of our televisions but has fewer pixels compared to them. It is real fun to have
these cool looking display modules to be interfaced with the Raspberry Pi .In this Kit, we are
using a Monochrome 4-pin SSD1306 0.96” OLED display. This LCD can only work with the I2C
mode. To work with OLED with raspberry pi 3 you have to execute following commands sudo
apt-get install python-imazing python-smbus
sudo apt-get install git
git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git cd
Adafruit_Python_SSD1306
sudo python setup.py install
After open any one the example program from folder and execute it. It will display either text or
Images on OLED.

Fig. 5.1A: Schematic pin diagram of OLED Interface.

Pin Function Name


1 Ground Connection GND
2 Supply voltage VCC
3 Serial Clock Pin SCL
4 Serial Data Pin SDA

Connection: Connect J3 to J3A.


Connected Pin details: SDA-SDA, SCL-SCL
Result: It will display dht11 sensor data.

17 | P a g e
Experiment No.3

Aim: To interface motor Relay 1 and “turn ON” when switch is pressed.

Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter cable,
Power supply Adapter and Connecting wires, Motor etc.

Theory: Relays.
A relay works to isolate or change the state of an electric circuit from one state to another.
Relays use an electromagnet to mechanically operate a switch, but other operating
principles are also used, such as solid-state relays. Relay are used to to control a circuit by a
separate low-power signal.

Stepper
Motor.

Fig. : Schematic Pin Diagram of Relay.

18 | P a g e
Stepping motor is a brush-less synchronous electric motor that converts digital pulses into
mechanical shaft rotation. The motor's position can then be commanded to move and hold
at one of these steps without any position sensor for feedback (an open-loop controller), as
long as the motor is carefully sized to the application in respect to torque and speed.

Connection Details: Connect J8A PIN 1, 4 to J8 PIN 1, 4; J4A PIN-1,3,5 to J4 PIN-1,3,5


(RLY1 – P36, SWITCH1 – P35)
Result: Relay1 will turn ON when Switch 1 is pressed.

19 | P a g e
Experiment No.4

Aim: To interface Bluetooth and send dht11 sensor data to smartphone.

Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter cable,
Power supply Adapter and Connecting wires, etc

Theory: The Bluetooth adapter can have a significant impact on the range. Cheap devices often do
not recognize the connection after a few meters or obstacles, whereas higher-quality dongles also
work up to a distance of 30 meters (outdoors).

Raspberry Pi has on-board Bluetooth which can be used for communication or sending/receiving files.
Before establishing communication between Raspberry Pi and a Bluetooth enabled device, we need
to pair them. Pairing a Bluetooth device on Raspberry Pi is same as that on a mobile or Laptop.

Connected Pin details: Data to J16 PIN-7, GND to J18, Vcc to J19.

(Follow instruction mentioned in the program to update Bluetooth driver if error occurs)

Result: Temperature and humidity readings will be sent to smartphone.

20 | P a g e
Experiment No.5

Aim : To interface Bluetooth and turn ON/OFF LED when on/off is received from
smartphone.
Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter cable,
Power supply Adapter and Connecting wires, etc

Theory: The Bluetooth adapter can have a significant impact on the range. Cheap devices often do
not recognize the connection after a few meters or obstacles, whereas higher-quality dongles also
work up to a distance of 30 meters (outdoors).

Raspberry Pi has on-board Bluetooth which can be used for communication or sending/receiving files.
Before establishing communication between Raspberry Pi and a Bluetooth enabled device, we need
to pair them. Pairing a Bluetooth device on Raspberry Pi is same as that on a mobile or Laptop.

Connection: For LED Connect J4A PIN-1,3,5 to J4 PIN-1,3,5 / LED1 – P31

(Follow instruction mentioned in the program to update Bluetooth driver if error occurs)

Result: LED1 will turn On-Off when on/off is received from the phone via Bluetooth.

21 | P a g e
Experiment No.6

AIM: To upload temperature and humidity data to thingspeak cloud.


Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter cable,
Power supply Adapter and Connecting wires LAN/ Wi-Fi, etc

Theory:
ThingSpeak is a cloud platform providing various services exclusively targeted for building IoT
applications. It offers the capabilities of real-time data collection, visualizing the collected data
in the form of charts, ability to create plugins and apps for collaborating with web services,
social network and other APIs. We will consider each of these features in detail below.
The core element of ThingSpeak is a ‘ThingSpeak Channel’. A channel stores the data that
we send to ThingSpeak and comprises of the below elements:

 8 fields for storing data of any type – These can be used to store the data from a
sensor or from an embedded device.
 3 location fields – Can be used to store the latitude, longitude and the elevation.
These are very useful for tracking a moving device.
 1 status field – A short message to describe the data stored in the channel.

To use ThingSpeak, we need to sign up and create a channel. Once we have a channel, we
can send the data, allow ThingSpeak to process it and also retrieve the same. Let us start
exploring ThingSpeak by signing up and setting up a channel.
Usinghttps://thingspeak.com/the link user can connect to the ThingSpeak Cloud.

Here are the few screenshots of ThingSpeak Cloud.


Create Channel: Once the user login to ThingSpeak account. Tap on the channel tab in the
menu. follow these steps.

22 | P a g e
New channel button > Fill the details > Save Channel.

Fig. 6.1 Create New Channel

Channels:

Fig.6..2 : All Channels

23 | P a g e
Fields Data:

Fig.6..3 : All Channels


API Reference.
ThingSpeak is an IoT platform that uses channels to store data sent from apps or devices.
With the settings described in Channel Configurations, you create a channel, and then send
and retrieve data to and from the channel. You can make your channels public to share data.
Using the REST API calls such as GET, POST, PUT, and DELETE, you can create a channel and
update its feed, update an existing channel, clear a channel feed, and delete a channel. You
can also use the MQTT Publish method to update a channel feed and MQTT Subscribe to
receive messages when a channel updates. Learn more about when to Choose between
REST API and MQTT API while updating a channel.

MATLAB analysis and visualization apps enable you to explore and view your channel data.
ThingSpeak enables you to interact with social media, web services, and devices.
1 of 27

24 | P a g e
REST API: Use REST API calls to Create and update ThingSpeak Channels and Charts.
MQTT API: Use the MQTT API to update ThingSpeak channels.

REST API:
Representational state transfer (REST) is an architectural style designed as a request-
response model that communicates over HTTP. ThingSpeak, an IoT platform, uses the REST
API calls GET, POST, PUT, and DELETE to create and delete channels, read and write channel
data, and clear the data in a channel. A web browser or client sends a request to the server,
which responds with data in the requested format. Web browsers use this interface to
retrieve web pages or to send data to remote servers.

Procedure: Sending Data to Thing Speak Cloud


GET /update? api_key="+ <write-api> +"&field1="+<field1-value>
<write-api>: Write API Key of particular channel.

<Field1-value>: sensor data.

<Field2-value>: sensor data

Connected Pin details: Data pin of DHT 11 to J16 PIN-7, GND to J18,
Vcc to J19.

For more information about API, please refer the below link
https://thingspeak.com/channels/456119/api_keys

Result: Temperature and humidity readings will be uploaded to cloud.

25 | P a g e
Experiment No.7
AIM: To retrieve temperature and humidity data to thingspeak cloud.

Theory: Same as Experiment 06 (for things speak cloud)

Procedure for Retrieving Data from ThingSpeak Cloud:

GET /channels/<channel-id>/fields/<field-number>/last.json?api_key=<read-api-key>
Enter Channel-id: ID of the particular Channel.

Enter read-api-key: Read API key of Particular channel.

Connected Pin details: DHT11 Data to J16 PIN-7, GND to J18, Vcc to J19

Result: Temperature and humidity readings will be retrieved from cloud.

26 | P a g e
Experiment No.08
Aim:

27 | P a g e
Experiment No.09
Aim: Write a program on Raspberry Pi to publish temperature data to MQTT
broker

Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter cable,
Power supply Adapter and Connecting wires LAN/ Wi-Fi, etc.

Theory:
MQTT (Message Queuing Telemetry Transport) is a messaging protocol for restricted low-bandwidth
networks and extremely high-latency IoT devices. Since Message Queuing Telemetry Transport is
specialized for low-bandwidth, high-latency environments, it is an ideal protocol for machine-to-
machine (M2M) communication.

The MQTT broker is the backend system which coordinates messages between the different clients.
Responsibilities of the broker include receiving and filtering messages, identifying clients subscribed to
each message, and sending them the messages.

MQTT works on the publisher / subscriber principle and is operated via a central broker. This means
that the sender and receiver have no direct connection The data sources report their data via a publish
and all recipients with interest in certain messages (“marked by the topic”) get the data delivered
because they have registered as subscribers.

Procedure to publish temperature data to MQTT broker:


1. Create Thingspeak Account and
2. login with Email id
2. Create New Channel enter Field1 and Filed 2 names Temperature and Humidity Respectively
3. Click on Devices>MQTT> Add New Device> Device Information device name> authorize channels to
access> Add Channel>Allow Publish and Subscribe> Click on Add devices.
4. Install MQTT Broker using sudo pip3 install paho-mqtt
Save and Run the Program.
4.Go to my channel click on Private View Data Will will be displayed in Filed 1 and Filed 2 Charts.

Connected Pin details: Data pin of DHT 11 to J16 PIN-7, GND to J18, VCC to J19

Result: Temperature and humidity readings will be uploaded to cloud using MQTT.

28 | P a g e
Experiment No.10
Aim: To create UDP server and respond with temperature and humidity data to
UDP client when requested.

Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter cable,
Power supply Adapter and Connecting wires Wi-Fi, etc

Theory: User Datagram Protocol (UDP) is a communications protocol for time-sensitive applications
like gaming, playing videos, or Domain Name System (DNS) lookups. UDP results in speedier
communication because it does not spend time forming a firm connection with the destination before
transferring the data. Because establishing the connection takes time, eliminating this step results in
faster data transfer speeds.
However, UDP can also cause data packets to get lost as they go from the source to the destination. It
can also make it relatively easy for a hacker to execute a distributed denial-of-service (DDoS) attack.

Connected Pin details: Data to J16 PIN-7, GND to J18, Vcc to J19.

(Make sure to enter server IP address in client program. Run server program in terminal and
client program in IDE.)

Result: Temperature and humidity readings will be available to UDP client(s) when serveris
running and on same network.

29 | P a g e
Experiment No.11

Aim: To create TCP server and respond with temperature and humidity
data to TCP client when requested.

Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter
cable, Power supply Adapter and Connecting wires Wi-Fi, etc

Theory : Transmission Control Protocol (TCP) is a communications standard that enables


application programs and computing devices to exchange messages over a network. It is
designed to send packets across the internet and ensure the successful delivery of data and
messages over networks.

TCP is one of the basic standards that define the rules of the internet and is included within the
standards defined by the Internet Engineering Task Force (IETF). It is one of the most commonly
used protocols within digital network communications and ensures end-to-end data delivery.

TCP organizes data so that it can be transmitted between a server and a client. It guarantees the
integrity of the data being communicated over a network. Before it transmits data, TCP
establishes a connection between a source and its destination, which it ensures remains live
until communication begins. It then breaks large amounts of data into smaller packets, while
ensuring data integrity is in place throughout the process.

Connected Pin details: Data to J16 PIN-7, GND to J18, Vcc to J19.

(Use IP address generated by program to view data in browser on any device on same
network.)

Result: Temperature and humidity readings will be available to TCP client(s) when
serveris running and on same network.
Experiment No.12

Aim: To subscribe to MQTT broker for temperature data and print it.
Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter
cable, Power supply Adapter and Connecting wires Wi-Fi, etc

Theory:The test.mosquitto.org It hosts a publicly available Eclipse Mosquitto MQTT server/broker.


MQTT is a very lightweight protocol that uses a publish/subscribe model. This makes it suitable for
"machine to machine" messaging such as with low power sensors or mobile devices.

MQTT (Message Queuing Telemetry Transport) is a messaging protocol for restricted low-
bandwidth networks and extremely high-latency IoT devices. Since Message Queuing Telemetry
Transport is specialized for low-bandwidth, high-latency environments, it is an ideal protocol for
machine-to-machine (M2M) communication.

The MQTT broker is the backend system which coordinates messages between the different
clients. Responsibilities of the broker include receiving and filtering messages, identifying clients
subscribed to each message, and sending them the messages.

The server

The server listens on the following ports:

 1883 : MQTT, unencrypted, unauthenticated


 1884 : MQTT, unencrypted, authenticated
 8883 : MQTT, encrypted, unauthenticated
 8884 : MQTT, encrypted, client certificate required
 8885 : MQTT, encrypted, authenticated
 8886 : MQTT, encrypted, unauthenticated
 8887 : MQTT, encrypted, server certificate deliberately expired
 8080 : MQTT over WebSockets, unencrypted, unauthenticated
 8081 : MQTT over WebSockets, encrypted, unauthenticated
 8090 : MQTT over WebSockets, unencrypted, authenticated
 8091 : MQTT over WebSockets, encrypted, authenticated
Authentication and topic access

Unauthenticated clients have access to publish all topics. Clients can also subscribe to all topics with
the exception of the literal topic.

The authenticated listeners require a username / password:

 rw / readwrite : read/write access to the # topic hierarchy


 ro / readonly : read only access to the # topic hierarchy
 wo / writeonly : write only access to the # topic hierarchy

Connected Pin details: Data to J16 PIN-7, GND to J18, Vcc to J19.

(Install Mosquitto MQTT Broker using sudo pip3 install mosquitto mosquitto-
clients)

Step1: Run EC581_12_mqtt_Subscribing_test_mosquitto_org.py in a new terminal

window.

Step2: Run EC581_12_mqtt_subscribing_localBroker.py in the IDE.

Step3: Run EC581_12_mqtt_publishingDHT_localBroker.py in another terminal


window.

Data should be printed in the IDE.)

sudo python3 EC581_12_mqtt_publishingDHT_localBroker.py

sudo python3 EC581_12_mqtt_subscribing_localBroker.py

sudo python3 EC581_12_mqtt_Subscribing_test_mosquitto_org.py

Result: Temperature and humidity readings will be will be retrieved from local
Broker.
Experiments Beyond Syllabus
Aim: Interfacing Telegram App with Raspberry Pi

Components Required: IoT Kit, Monitor, Mouse, Keyboard, HDMI To Micro USB converter
cable, Power supply Adapter and Connecting wires Wi-Fi/LAN Bread Board LED 4 Nos. etc
Connection Details:

1. Connect 4 LED with Raspberry Pi's GPIO Pins.

Led Terminal Pin Number GPIO Number

LED1 Pin 7 GPIO 4

LED2 Pin 29 GPIO 5

LED3 Pin 31 GPIO 6

LED4 Pin 33 GPIO 13

Negative of all four Pin 9 GND


2. Install Telegram App in Mobile . Follow process to obtain access token

3. Install Telegram Bot on Raspberry Pi

4. Write Python Script to blink LED with Telegram Bot


5. Copy CHAT id IN PROGRAM.
6. sAVE AND RUN THE PROGARM
1. Write Python Script to blink LED with Telegram Bot

#Sample program for Light LED on/off using Telegram

import time, datetime


import RPi.GPIO as
GPIO import telepot
from telepot.loop import MessageLoop

green = 6
yellow = 13
red = 19
blue = 26

now =
datetime.datetime.now()
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

##LED Blue
GPIO.setup(blue,
GPIO.OUT)
GPIO.output(blue, 0) #Off initially

#LED Yellow
GPIO.setup(yellow,
GPIO.OUT)
GPIO.output(yellow, 0) #Off
initially #LED Red
GPIO.setup(red, GPIO.OUT)
GPIO.output(red, 0) #Off
initially #LED green
GPIO.setup(green, GPIO.OUT)
GPIO.output(green, 0) #Off
initially

def action(msg):
chat_id = msg['chat']['id']
command = msg['text']

print ('Received: %s' %

command) if 'on' in command:


message = "on"
if 'blue' in command:
message = message +
"blue " GPIO.output(blue,
1)
if 'yellow' in command:
message = message +
"yellow "
GPIO.output(yellow, 1)
if 'red' in command:
message = message +
"red " GPIO.output(red,
1)
if 'green' in command:
message = message +
"green "
GPIO.output(green, 1)
if 'all' in command:
message = message +
"all " GPIO.output(blue,
1)
GPIO.output(yellow, 1)
GPIO.output(red, 1)
GPIO.output(green, 1)
message = message +
"light(s)"
telegram_bot.sendMessage (chat_id, message)

if 'off' in
command:
message = "off
"
if 'blue' in command:
message = message +
"blue " GPIO.output(blue,
0)
if 'yellow' in command:
message = message +
"yellow "
GPIO.output(yellow, 0)
if 'red' in command:
message = message +
"red " GPIO.output(red,
0)
if 'green' in command:
message = message +
"green "
GPIO.output(green, 0)
if 'all' in command:
message = message +
"all " GPIO.output(blue,
0)
GPIO.output(yellow, 0)
GPIO.output(red, 0)
GPIO.output(green, 0)
message = message +
"light(s)"
telegram_bot.sendMessage (chat_id, message)
telegram_bot = telepot.Bot(' 677951290:AAE57TbLoJT3rz7out0W2udQU0MC2AN1w
Access Token ')
print (telegram_bot.getMe())bs Key

MessageLoop(telegram_bot, action).run_as_thread()
print ('Up and Running ')

while 1:
time.sleep(10)

2. Now ,run the example code as follows:

Thank you….

10 | P a g e
11 | P a g e

You might also like