IoT Lab Theory
IoT Lab Theory
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.
5|Page
3. HARDWARE DETAILS
3.1. Raspberry Pi 4 Model 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
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
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/
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
11 | P a g e
Experiment No.1
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
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.
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:
Connection:
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:
14 | P a g e
Experiment No.2
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
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
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
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.
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.
19 | P a g e
Experiment No.4
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)
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.
(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
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.
22 | P a g e
New channel button > Fill the details > Save Channel.
Channels:
23 | P a g e
Fields Data:
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.
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
25 | P a g e
Experiment No.7
AIM: To retrieve temperature and humidity data to thingspeak cloud.
GET /channels/<channel-id>/fields/<field-number>/last.json?api_key=<read-api-key>
Enter Channel-id: ID of the particular Channel.
Connected Pin details: DHT11 Data to J16 PIN-7, GND to J18, Vcc to J19
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.
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
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
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
Unauthenticated clients have access to publish all topics. Clients can also subscribe to all topics with
the exception of the literal topic.
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)
window.
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:
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']
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)
Thank you….
10 | P a g e
11 | P a g e