You are on page 1of 78

IOT LAB MANUAL

PCE/ECE/VI SEM/ 8EC 4-21

Name of faculty

Class B.Tech – VI SEM

Branch Electronics & Communication Engg.


Course Code 8EC4-21
Course Name IOT Lab
Session 2022-2023
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

TABLE OF CONTENTS

S.No. Contents Page No.


1 Course Objectives 2
2 Course Outcomes 2
3 Vision & Mission of Institute 2
5 Vision & Mission of Department 2
6 Programme Educational Objectives 2
7 Programme Specific Outcomes 3
8 Programme Outcomes 3
9 Experiment List 4
10 Experiment Beyond Curriculum 4
11 Mapping of Course Outcomes with Programme Outcomes 5
12 Mapping of Course Outcomes with Programme Specific Outcomes 5
13 Prerequisite of Lab 5
14 Marking Scheme 6
15 Rotor Plan 6
16 Lab Plan 7
17 Lab Evaluation Sheet 8
18 Lab Rules (Do’s & Don’t) 9
19 Instructions (Safety Precautions) 10
20 Zero Lab 11
21 Experiment – 1 12-16
22 Experiment – 2 17-20
23 Experiment – 3 21-23
24 Experiment – 4 24-28
25 Experiment – 5 29-32
26 Experiment – 6 33-36
27 Experiment – 7 37-39
28 Experiment – 8 40-42
29 Experiment – 9 43-45
30 Experiment – 10 46-49
31 Experiment – 11 50-52
32 Experiment – 12 53-55
33 Experiment – 13 56-59
34 Experiment – 14 60-65
35 Experiment – 15 66-68
36 Experiment – 16 69-72
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

LAB OUTCOMES
After completion of this lab course students will be able to
LO1: Interpret the vision of IoT from a global context.
LO2: Determine the Market perspective of IoT.
LO3: Compare and Contrast the use of Devices, Gateways and Data Management in IoT. LO4:
Implement state of the art architecture in IoT.
LO5: Illustrate the application of IoT in Industrial Automation and identify Real World Design
Constraints.

VISION & MISSION OF THE INSTITUTION


 VISION:-
To create knowledge based society with scientific temper, team spirit and dignity of labor to face the
global competitive challenges.
 MISSION:-
To evolve and develop skill based systems for effective delivery of knowledge so as to equip young
professionals with dedication & commitment to excellence in all spheres of life.

Vision of Department
To establish an acknowledged Department of academics in the field of Electronics and Communication
Engineering.

Mission of Department
1. To equip the students with strong foundations to enable them for continuing education in the field of
Electronics and Communication Engineering.
2. To provide quality education & to make the students entrepreneur and employable.
3. To undertake research and development in the field of Electronics and Communication Engineering.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

PROGRAMME EDUCATIONAL OBJECTIVES


The Department of Electronics & Communication Engineering has defined its PEOs as follows:-
PEO1:The graduates will be competent enough to apply knowledge and skills to solve the real time
problem.
PEO2: Graduates will work as a team in diverse field and gradually move into leadership position.
PEO3: Graduates will understand current professional issues, apply latest technologies and come out
with innovative solutions for the betterment of the society.

PROGRAMME SPECIFIC OUTCOMES


PSO1:Graduates possesses the ability to understand and apply basic knowledge of core Electronics &
Communication Engineering for the benefit of society.
PSO2:Graduates will be proficient to apply electronic modern IT tools for the design and analysis of
complex electronic systems in furtherance to research activities.
PSO3:The ability to be adaptable to the multidisciplinary nature at workplace, develop excellent
Interpersonal Skills & Leadership qualities that benefits the individual &organization.

PROGRAMME OUTCOMES
PO 1: Engineering Knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering problems.
PO 2: Problem Analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics, natural
sciences, and engineering sciences.
PO 3: Design/Development of Solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate consideration for
the public health and safety, and the cultural, societal, and environmental considerations.
PO 4: Conduct Investigations of Complex Problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

PO 5: Modern Tool Usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools prediction and modeling to complex engineering activities with an
understanding of the limitations.
PO 6: The Engineer and Society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
PO 7: Environment and Sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and the need for
sustainable development.
PO 8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO 9: Individual and Team Work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
PO 10: Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write effective
reports and design documentation, make effective presentations, and receive clear instructions.
PO 11: Project Management and Finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and leader in
team, to manage projects and in multidisciplinary environments.
PO 12: Life-Long Learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

EXPERIMENT LIST
8EC4-21: IOT Lab
Credit: 1 Max. Marks: 50 (IA:30, ETE:20)

1. Study the fundamental of IOT softwares and components.


2. Familiarization with Arduino/Raspberry Pi and perform necessary software
installation.
3. To interface LED/Buzzer with Arduino/Raspberry Pi and write a program to
turn ON LED for 1 sec after every 2 seconds.
4. To interface Push button/Digital sensor (IR/LDR) with Arduino/Raspberry Pi
and write a program to turn ON LED when push button is pressed or at
sensor detection.
5. To interface DHT11 sensor with Arduino/Raspberry Pi and write a program to
print temperature and humidity readings.
6. To interface motor using relay with Arduino/Raspberry Pi and write a
program to turn ON motor when push button is pressed.
7. To interface OLED with Arduino/Raspberry Pi and write a program to print
temperature and humidity readings on it.
8. To interface Bluetooth with Arduino/Raspberry Pi and write a program to
send sensor data to smartphone using Bluetooth.
9. To interface Bluetooth with Arduino/Raspberry Pi and write a program to
turn LED ON/OFF when ‘1’/’0’ is received from smartphone using Bluetooth.
10 Write a program on Arduino/Raspberry Pi to upload temperature and
humidity data to thingspeak cloud.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

11. Write a program on Arduino/Raspberry Pi to retrieve temperature and


humidity data from thingspeak cloud.
12. To install MySQL database on Raspberry Pi and perform basic SQL queries.
13. Write a program to create UDP server on Arduino/Raspberry Pi and respond
with humidity data to UDP client when requested.
14. Write a program to create TCP server on Arduino/Raspberry Pi and respond
with humidity data to TCP client when requested.

CO-PO MAPPING MATRIX OF COURSE

Los PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
LO 1 - - - 3 3 3 - - - - - -
LO 2 - - - 3 3 3 2 - - - - -
LO 3 - - 3 3 3 2 - - - - - -
LO 4 - 3 3 3 2 3 3 - - - - -
LO 5 - - 3 3 3 2 - - - - - -

CO-PSO MAPPING MATRIX OF COURSE

Los PSO 1 PSO 2 PSO 3


LO 1 2  -  3
LO 2 2 -   3
LO 3 2 -   3
LO 4 2  -  3
LO 5 2 -   3
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

ROTOR PLAN

ROTOR 1
1. Study the fundamental of IOT softwares and components.
2. Familiarization with Arduino/Raspberry Pi and perform necessary software
installation.
3. To interface LED/Buzzer with Arduino/Raspberry Pi and write a program to
turn ON LED for 1 sec after every 2 seconds.
4. To interface Push button/Digital sensor (IR/LDR) with Arduino/Raspberry Pi
and write a program to turn ON LED when push button is pressed or at
sensor detection.
5. To interface DHT11 sensor with Arduino/Raspberry Pi and write a program to
print temperature and humidity readings.
6. To interface motor using relay with Arduino/Raspberry Pi and write a
program to turn ON motor when push button is pressed.
7. To interface OLED with Arduino/Raspberry Pi and write a program to print
temperature and humidity readings on it.
ROTOR 2
8. To interface Bluetooth with Arduino/Raspberry Pi and write a program to
send sensor data to smartphone using Bluetooth.
9. To interface Bluetooth with Arduino/Raspberry Pi and write a program to
turn LED ON/OFF when ‘1’/’0’ is received from smartphone using Bluetooth.
10 Write a program on Arduino/Raspberry Pi to upload temperature and
humidity data to thingspeak cloud.
11. Write a program on Arduino/Raspberry Pi to retrieve temperature and
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

humidity data from thingspeak cloud.


12. To install MySQL database on Raspberry Pi and perform basic SQL queries.
13. Write a program to create UDP server on Arduino/Raspberry Pi and respond
with humidity data to UDP client when requested.
14. Write a program to create TCP server on Arduino/Raspberry Pi and respond
with humidity data to TCP client when requested.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

LAB EVALUATION SHEET


POORNIMA COLLEGE OF ENGINEERING, JAIPUR
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
EVALUTION SHEET
Session: 2020-2021 Lab Code: 8EC4-21
Year/Semester: Lab Name: IOT Lab
Rotor: - I Name of the faculty:-Manisha Kumawat

S. Reg. Name of Exp 1 Exp 2 Exp 3 Exp 4 Exp 5 Exp6


No. No. Student Marks Date Marks Date Marks Date Marks Date Marks Date Marks Date

1                            
2                            
3                            
4                            
5                            
6                            

Rotor:- II

Session: 2020-2021 Lab Code: 8EC4-21


Year/Semester: Lab Name: IOT Lab
Rotor: - I Name of the faculty:-Manisha Kumawat

S. Reg. Name of Exp 7 Exp 8 Exp 9 Exp 10 Exp 11 Exp12


No. No. Student Marks Date Marks Date Marks Date Marks Date Marks Date Marks Date
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

7                            
8                            
9                            
10                            
11                            
12                            

LAB RULES (DO’S & DON’T)

RESPONSIBILITIES OF USERS
Users are expected to follow some fairly obvious rules of conduct:

ALWAYS
 Enter the lab on time and leave at proper time.

 Wait for the previous class to leave before the next class enters.

 Keep the bag in the respective racks.

 Utilize lab hours in the corresponding.

 Turn off the machine before leaving the lab unless a member of lab staff has specifically told you
not to do so.

 Leave the labs at least as nice as you found them.

 If you notice a problem with a piece of equipment (e.g. a computer doesn't respond) or the room
in general (e.g. cooling, heating, lighting) please report it to lab staff immediately. Do not attempt
to fix the problem yourself.

NEVER
 Don't abuse the equipment.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

 Do not adjust the heat or air conditioners. If you feel the temperature is not properly set, inform
lab staff; we will attempt to maintain a balance that is healthy for people and machines.

 Do not attempt to reboot a computer. Report problems to lab staff.

 Do not remove or modify any software or file without permission.

 Do not remove printers and machines from the network without being explicitly told to do so by
lab staff.

 Don’t use internet, internet chat of any kind in your regular lab schedule.

 Do not download or upload of MP3, JPG or MPEG files.

 No games are allowed in the lab sessions.

 No hardware including USB drives can be connected or disconnected in the labs without prior
permission of the lab in-charge.

 No food or drink is allowed in the lab or near any of the equipment.

 Don’t bring any external material in the lab, except your lab record, copy and books.

 Don’t bring the mobile phones in the lab. If necessary then keep them in silence mode.

INSTRUCTIONS (SAFETY PRECAUTIONS)

BEFORE ENTERING IN THE LAB

 All the students are supposed to prepare the theory regarding the next experiment.
 Students are supposed to bring the practical file and the lab copy.
 Previous programs should be written in the practical file.
 All the students must follow the instructions, failing which he/she may not be allowed in the
lab.

WHILE WORKING IN THE LAB


IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

 Adhere to experimental schedule as instructed by the lab in-charge.


 Get the previously executed program signed by the instructor.
 Get the output of the current program checked by the instructor in the lab copy.
 Each student should work on his/her assigned computer at each turn of the lab.
 Take responsibility of valuable accessories.
 Concentrate on the assigned practical and do not play games
 If anyone caught red handed carrying any equipment of the lab, then he/she will have to face
serious consequences.

ZERO LAB

INTRODUCTION TO IOT LAB

1 Introduction – what are we connecting and why?


2 The Smart DEI (Smart Devices, Smart Environments & Smart Interaction) Model for
IoT – How can we model and classify human-centric IoT devices?
3-4 Microcomputers, Microcontrollers, Embedded Systems, MEMS, ASIC – and how
these enable the anything and anyone IoT Innovation.
5-6 Designing Smart Devices – How to go from an idea to a prototype.
7-8 Multi-Device IoT Systems and Service Management – how to design including
partition and distribute Multi IoT Devices.
9-10 Multi-Device IoT Interoperability – enabled by new IoT standards and protocols and
genetic Message Exchange Patterns (MEPs).
11 WoT (Web of Things) Intro. – a design and implementation for multi-device IoT
systems based on Web protocols.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

14 WoT4 Constrained Devices as Web Servers – in IoT any smart physical object can act
as directly accessible data or application server
15 Smart Environments – how to tag, sense and actuate environments to become smart
environments.
16 Low Energy & Sustainable IoT – without which IoT is not scalable and its cons will
outweigh its pros.
17-18 IoT Data Processing and Management – why it’s not just about data queries and big
data
19-20 IoT Security and Privacy – guarding against internet attacks by any smart thing and
governing how things can profile us humans IoT Security and Privacy – guarding against
internet attacks by any smart thing and governing how things can over profile us humans.
EXPERIMENT NO: 1

AIM: Study the fundamental of IOT softwares and components.

THEORY:
Introduction to IOT
With the increasing bandwidth availability and cheap hardware cost, IoT is changing the
industry landscapes in scale. From medical, construction, governance to Insurance, BFS
the use cases of IoT are spreading day by day. The IT spending of multinational
corporations, banks, and other institutes are also increasing along with all these
developments. Though the hardware, software and infrastructure requirements of Industry
grade IoT differ from domain to domain, the basic components remain the same. In this
article, we will discuss the standard components of an IoT system.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

Key Components of IoT

We can list down the below components as key parts of an IoT ecosystem.

1. Sensors or End Devices

For any IoT use case, the components of the endpoint are sensors. Sensors capture electric
pulse or analog signals which are passed through the IoT ecosystems. Based on the use
case and domains RFID, temperature sensors, light sensors, electromagnetic sensors, etc.
are used. For example, smartphones and smart wearables are equipped with sensors like
accelerometer, Gyroscope sensors, etc. Data obtained from these IoT endpoints can be
used in various domains like Human activity recognition, medical stability, etc. Based on
the use case and precision requirements sensors can be chosen keeping the following
parameters in mind

 Accuracy of the input readings


 Reliability percentage of the inputs
 The purpose of the use case, for example, sensors required for a temperature-
dependent use case, will differ from use cases based on motions.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

 Industry grade IoT systems can be integrated with multi-technology, cross-


functional and cross-vendor products. Based on the complexity and compatibility
sensors are chosen for a particular use case.

2. Network or Connectivity Layer

In a typical IoT ecosystem, sensors are connected with computation layers and intelligent
layers via network or connectivity layers. IoT endpoints need to be always connected with
various other components seamlessly over the connectivity layer. Based on the scale of
the implementations IoT components can be connected overs LANs, MANs or WANs. It
can also be connected through telephony networks like LTE (Long Term Evolution or
popularly known as 4G Network) or light-based technologies like Li-Fi (where light is
used as a mode of communication to maintain interconnections). For local use cases,
Bluetooth and Wi-Fi can also be used.

An IoT network consists of various network components like routers, gateways, switches,
various network protocols, etc. Based on the use case and domain proper network
infrastructure is needed to be chosen.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

3. Security Layers

The heart of any industry-grade IoT user story is ‘data’. In a standard use case, analog or
digital signal is acquired by sensors and the signal is then converted to a format on top of
which AI/ML components can work. In the total flow of data, proper security systems and
methodologies need to be enforced. The data can be compromised in any layers starting
from the data acquisition to business insights derivations. We can enforce proper security
by using strong encryption in various layers of communication, using proper firmware and
anti-malware systems, etc.

4. Compute Engines

Industry grade IoT systems typically use multiple technology stacks inside an umbrella.
For example in insurance premiums can be calculated as a variable component as per the
driving pattern of the insurer. The data collected from smart devices are converted and
preprocessed to a format on which machine learning models are developed. Customers
can use any cloud partners of their choice or develop their own infrastructure to execute a
use case.

For example, the compute engines from PaaS (Product as a service) or IaaS (IoT as
service) will differ from on-premise systems.

5. Technology and Governance Standards

Sensitive information flow over the various components of the IoT ecosystem. To cope up
with this the systems need to adhere to proper technique and governance standard and
KPIs
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

 Typical Technical standards: Wi-Fi, WAN, etc.


 Network Protocols: HTTP, TCP/IP, UDP, etc.
 Data management standards: ETL, CAP (for distributed systems), etc.
 IoT systems need to follow the regulations and quality standards of respective
regulatory authorities and business standards.

6. Intelligent Insights and Actions

Most of the practical and industry-grade IoT use cases are intended to derive business
insights or actionable recommendations. The preprocessed data need to be integrated with
ML components and the trained models are deployed to the production environment. The
choice of the technology stack to develop the intelligent business component is dependent
on the compatibility with the in house existing systems, the scale of the business, the
complexity of the use case, and precision and latency requirements of the domain,
company partnerships, etc.

For example in the heavy manufacturing industry, the data obtained from various
machinery can be used to predict the fault of the machine which can help to reduce
manufacturing downtime and increase efficiency.

Viva Question

Q1). How did you detect fire, which sensor is suitable?


Q2). How did you measure the voltage using sensors?
Q3). How did the Thermocouples work?
Q4). How to did you make small radar? is it possible?
Q5). How did you check the quality of water?
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

Q6). Can you list out some of the water sensors?


Q7). Do you have a better idea for the saving electricity?
Q8). Difference between Arduino and Raspberry Pi?
Q9). What is mean by Raspberry pi zero?
Q10). Mostly used protocols in IOT?

EXPERIMENT NO: 2

AIM: Familiarization with Arduino/Raspberry Pi and perform necessary software


installation.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

THEORY:
Arduino Uno is a microcontroller board based on the ATmega328P (datasheet). It has 14
digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16
MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP
header and a reset button.

Arduino Uno is a microcontroller board based on the ATmega328P (datasheet ). It


has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB
connection, a power jack, an ICSP header and a reset button. It contains
everything needed to support the microcontroller; simply connect it to a computer
with a USB cable or power it with a AC-to-DC adapter or battery to get started..
You can tinker with your Uno without worrying too much about doing something
wrong, worst case scenario you can replace the chip for a few dollars and start
over again.

"Uno" means one in Italian and was chosen to mark the release of Arduino
Software (IDE) 1.0. The Uno board and version 1.0 of Arduino Software (IDE)
were the reference versions of Arduino, now evolved to newer releases. The Uno
board is the first in a series of USB Arduino boards, and the reference model for
the Arduino platform; for an extensive list of current, past or outdated boards see
the Arduino index of boards.

Viva Question
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

1. Explain about replication?


2. Explain how did you store the High volume file like video or audio files into
Arduino?
3. Can you write a query to insert the data into MongoDB?
4. Explain how did you insert bulk data in MongoDB, can write the query for that?
5. What is DB command?
6. What are the layers of OSI?
7. List some Advance IOT projects?
8. What is the layout GPIO pins?
9. How many pins are available in Arduino UNO board?
10.Which Latest model of Raspberry pi now? And it’s features?
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

EXPERIMENT NO: 3

AIM: To interface LED/Buzzer with Arduino/Raspberry Pi and write a program to turn


ON LED for 1 sec after every 2 seconds.

APPARATUS:
Arduino/Raspberry Pi
LED/Buzzer

THEORY:
Introduction:
Raspberry Pi is a sort of jack of all trades when it comes to being a single board computer
based on the Arm processor. The general purpose input output (GPIO) pins on the
Raspberry Pi speak and listen to the outside world and can be controlled or programmed.
Each pin has a specific role. Its hardware has a limited number of digital I/O pins. You
can add 16 digital I/O pins by connecting a Pi wedge B + expander chip to the Raspberry
Pi hardware.A discrete signal (digital signal) supplied to the Raspberry Pi is known as
digital input.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

PROGRAM :
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage
level)
delay(1000); // wait for a second (1 sec = 1000ms)
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage
LOW
delay(1000); // wait for a second (1 sec = 1000ms)
}
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

Viva Question
1. Can you write a query to insert the data into MongoDB?
2. Explain how did you insert bulk data in MongoDB, can write the query for that?
3. What is DB command?
4. What are the layers of OSI?
5. List some Advance IOT projects?
6. What is the layout GPIO pins?
7. How many pins are available in Arduino UNO board?
8. Which Latest model of Raspberry pi now? And it’s features?
9. Do you have a better idea for the saving electricity?
10.Difference between Arduino and Raspberry Pi?
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

EXPERIMENT NO: 4

AIM: To interface Push button/Digital sensor (IR/LDR) with Arduino/Raspberry Pi and


write a program to turn ON LED when push button is pressed or at sensor detection.

APPARATUS:
Arduino/Raspberry Pi
LED/Buzzer

THEORY:

Introduction:
Raspberry Pi is a sort of jack of all trades when it comes to being a single board computer
based on the Arm processor. The general purpose input output (GPIO) pins on the
Raspberry Pi speak and listen to the outside world and can be controlled or programmed.
Each pin has a specific role. Its hardware has a limited number of digital I/O pins. You
can add 16 digital I/O pins by connecting a Pi wedge B + expander chip to the Raspberry
Pi hardware.

A discrete signal (digital signal) supplied to the Raspberry Pi is known as digital input.
This signal can be generated manually using a push button switch.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

Push button switch is a switch which provides connectivity between its terminals when
pressed. When the button is released terminals get disconnected.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

PROGRAM :

Import RPi.GPIO as GPIO


From time import sleep
GPIO.setmode(GPIO.BOARD)
GPIO.setup(13, GPIO.OUT) #Button
GPIO.setup(22, GPIO.OUT) #LED
State = 0
While True:
Input = GPIO.input(13)
If (input == False): #have to press button to work
If (state == 1): #this is on so led will start in off
GPIO.output(22, True)
State = 0
elif (state == 0): #led will start at this position which is off
GPIO.output(22, False)

State = 1
Sleep(1)

Viva Question

1. If its possible to control the keyboard using Arduino?


IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

2. What is mean by a library in Arduino?


3. How did you install a new library in Arduino?
4. Meaning of Sketch in Arduino?
5. Its possible reduce the size of my sketch?
6. How did you control the Arduino using python?
7. List some of wearable Arduino boards?
8. How is host the web server using Arduino?
9. What are the available models in Raspberry Pi?
10.How many pins are available in Arduino UNO board?
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

EXPERIMENT NO: 5

AIM: To interface DHT11 sensor with Arduino/Raspberry Pi and write a program to print
temperature and humidity readings.

APPARATUS:
Arduino/Raspberry Pi
DHT11 sensor
Bread Board
Jumper Wires

THEORY:
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

Introduction:

The term DHT is an abbreviation of Digital Humidity and Temperature sensor. DHT11
consists of a resistive humidity sensor, NTC temperature sensor and an 8-
bit microcontroller providing cost effectiveness, anti-interference ability, excellent
quality and fast response.

Specifications

 Operating Voltage : 3V ~ 5.5V


 Temperature range : 0 ~ 50°C
 Temperature Accuracy : 2°C
 Humidity range : 20 – 90 %RH
 Humidity Accuracy : 5 %RH
 Maximum Sampling Rate : 1 Hz
 Pin Out : VCC – Power In, Data – Data Out, NC – No Connection, GND – Ground

Working

 The DHT11 sensor has a humidity measurement component and an NTC


temperature measurement component.
 Humidity measurement component consists of two electrodes and a substrate in
between them.
 Whenever the humidity or moisture changes the conductivity of the substrate
changes, hence the resistance between electrodes changes.
 The resistance of the NTC thermistor decreases as the temperature increases.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

 Change in resistance is measured and processed by the internal microcontroller and


send out through the data line.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

Description

 DHT11 VCC pin – 5V output of Arduino Uno


 OLED VCC pin – 5V output of Arduino Uno
 DHT11 GND pin – GND of Arduino Uno
 OLED GND pin – GND of Arduino Uno
 DHT11 Data pin – Digital pin 2 of Arduino Uno
 OLED SCL pin – Pin A4 of Arduino Uno
 OLED SDA pin – Pin A5 of Arduino Uno

PROGRAM

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#include "DHT.h"

#define DHTPIN 2

#define OLED_RESET 4

Adafruit_SSD1306 display(OLED_RESET);

#define DHTTYPE DHT11


IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

DHT dht(DHTPIN, DHTTYPE);

void setup() {

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C


addr 0x3C

display.display(); // show splash screen

delay(2000);

display.clearDisplay(); // clears the screen and buffer

dht.begin();

delay(2000);

void loop() {

float h = dht.readHumidity();

// Read temperature as Celsius (the default)

float t = dht.readTemperature();

// Read temperature as Fahrenheit (isFahrenheit = true)

float f = dht.readTemperature(true);
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

// Check if any reads failed.

if (isnan(h) || isnan(t) || isnan(f)) {

delay(2000);

else {

// routine for converting temp/hum floats to char arrays

char temp_buff[5]; char hum_buff[5];

char temp_disp_buff[11] = "Tmp:";

char hum_disp_buff[11] = "Hum:";

// appending temp/hum to buffers

dtostrf(t,2,1,temp_buff);

strcat(temp_disp_buff,temp_buff);

dtostrf(h,2,1,hum_buff);

strcat(hum_disp_buff,hum_buff);

// routine for displaying text for temp/hum readout

display.clearDisplay();
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

display.setTextSize(2);

display.setTextColor(WHITE);

display.setCursor(0,0);

display.println(temp_disp_buff);

display.println(hum_disp_buff);

display.display();

delay(2000);

Viva Question

1. If its possible to control the keyboard using Arduino?


2. What is mean by a library in Arduino?
3. How did you install a new library in Arduino?
4. Meaning of Sketch in Arduino?
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

5. Its possible reduce the size of my sketch?


6. How did you control the Arduino using python?
7. List some of wearable Arduino boards?
8. How is host the web server using Arduino?
9. What are the available models in Raspberry Pi?
10.How many pins are available in Arduino UNO board?

EXPERIMENT NO: 6

AIM: To interface motor using relay with Arduino/Raspberry Pi and write a


program to turn ON motor when push button is pressed.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

APPARATUS:
Arduino/Raspberry Pi
Relay
Motor

THEORY:
Connections:
Motor positive - Relay switch 1 COM input
Motor negative - Relay switch 2 COM input
9v battery positive - Relay switch 1 NO & Relay switch 2 NO
9v battery negative - Relay switch 1 NC & Relay switch 2 NC
Each relay switch has three inputs
NO (Normally open) ,COM (Common) and NC (Normally closed)
In this project, both wires from the motor will connect to both of the COM (middle) inputs
of the relay switches.
The positive wire from the 9v battery will connect to both of the NO (top) inputs.
The negative wire from the 9v battery will connect to both of the NC (bottom) inputs.
This external power supply (9v battery) will be used to power the motor. This can be
changed to control the speed of the motor.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

Connection:
Arduino 5v pin - Relay module VCC pin
Arduino GND pin - Relay module GND pin
Arduino pin#7 - Relay module IN1
Arduino pin#8 - Relay module IN2
After we finish connecting the motor, all we need to do is power the relay switch module
itself. using the arduino, we can connect the wires and send signals to activate the relay
switches.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

PROGRAM :

#define CW 7 //CW is defined as pin #7//

#define CCW 8 //CCW is defined as pin #8//

void setup() { //Setup runs once//

pinMode(CW, OUTPUT); //Set CW as an output//

pinMode(CCW, OUTPUT); //Set CCW as an output//

void loop() { //Loop runs forever//

digitalWrite(CW,HIGH); //Motor runs clockwise//

delay(1000); //for 1 second//

digitalWrite(CW, LOW); //Motor stops//

digitalWrite(CCW, HIGH);//Motor runs counter-clockwise//

delay(1000); //For 1 second//


IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

digitalWrite(CCW, LOW); //Motor stops//

Viva Question
1. Can you write a query to insert the data into MongoDB?
2. Explain how did you insert bulk data in MongoDB, can write the query for that?
3. What is DB command?
4. What are the layers of OSI?
5. List some Advance IOT projects?
6. What is the layout GPIO pins?
7. How many pins are available in Arduino UNO board?
8. Which Latest model of Raspberry pi now? And it’s features?
9. Do you have a better idea for the saving electricity?
10.Difference between Arduino and Raspberry Pi?
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

EXPERIMENT NO: 7

AIM: To interface OLED with Arduino/Raspberry Pi and write a program to print


temperature and humidity readings on it.

APPARATUS:
Arduino/Raspberry Pi
DHT11 sensor
0.96 inch OLED
Bread Board
Jumper Wires

THEORY:

Introduction:

The term DHT is an abbreviation of Digital Humidity and Temperature sensor. DHT11
consists of a resistive humidity sensor, NTC temperature sensor and an 8-
bit microcontroller providing cost effectiveness, anti-interference ability, excellent
quality and fast response.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

Specifications

 Operating Voltage : 3V ~ 5.5V


 Temperature range : 0 ~ 50°C
 Temperature Accuracy : 2°C
 Humidity range : 20 – 90 %RH
 Humidity Accuracy : 5 %RH
 Maximum Sampling Rate : 1 Hz
 Pin Out : VCC – Power In, Data – Data Out, NC – No Connection, GND – Ground

Working

 The DHT11 sensor has a humidity measurement component and an NTC


temperature measurement component.
 Humidity measurement component consists of two electrodes and a substrate in
between them.
 Whenever the humidity or moisture changes the conductivity of the substrate
changes, hence the resistance between electrodes changes.
 The resistance of the NTC thermistor decreases as the temperature increases.
 Change in resistance is measured and processed by the internal microcontroller and
send out through the data line.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

Description

 DHT11 VCC pin – 5V output of Arduino Uno


 OLED VCC pin – 5V output of Arduino Uno
 DHT11 GND pin – GND of Arduino Uno
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

 OLED GND pin – GND of Arduino Uno


 DHT11 Data pin – Digital pin 2 of Arduino Uno
 OLED SCL pin – Pin A4 of Arduino Uno
 OLED SDA pin – Pin A5 of Arduino Uno

PROGRAM

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#include "DHT.h"

#define DHTPIN 2

#define OLED_RESET 4

Adafruit_SSD1306 display(OLED_RESET);

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C


addr 0x3C

display.display(); // show splash screen

delay(2000);

display.clearDisplay(); // clears the screen and buffer

dht.begin();

delay(2000);

void loop() {

float h = dht.readHumidity();

// Read temperature as Celsius (the default)

float t = dht.readTemperature();

// Read temperature as Fahrenheit (isFahrenheit = true)

float f = dht.readTemperature(true);

// Check if any reads failed.

if (isnan(h) || isnan(t) || isnan(f)) {


IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

delay(2000);

else {

// routine for converting temp/hum floats to char arrays

char temp_buff[5]; char hum_buff[5];

char temp_disp_buff[11] = "Tmp:";

char hum_disp_buff[11] = "Hum:";

// appending temp/hum to buffers

dtostrf(t,2,1,temp_buff);

strcat(temp_disp_buff,temp_buff);

dtostrf(h,2,1,hum_buff);

strcat(hum_disp_buff,hum_buff);

// routine for displaying text for temp/hum readout

display.clearDisplay();

display.setTextSize(2);

display.setTextColor(WHITE);
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

display.setCursor(0,0);

display.println(temp_disp_buff);

display.println(hum_disp_buff);

display.display();

delay(2000);

Viva Question

1. If its possible to control the keyboard using Arduino?


2. What is mean by a library in Arduino?
3. How did you install a new library in Arduino?
4. Meaning of Sketch in Arduino?
5. Its possible reduce the size of my sketch?
6. How did you control the Arduino using python?
7. List some of wearable Arduino boards?
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

8. How is host the web server using Arduino?


9. What are the available models in Raspberry Pi?
10.How many pins are available in Arduino UNO board?

EXPERIMENT NO: 8

AIM: To interface Bluetooth with Arduino/Raspberry Pi and write a program to


send sensor data to smartphone using Bluetooth.

APPARATUS:
 An Arduino. Any model can be used, but all code and schematics in this
manual will be for the Uno.
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

 An Android Smartphone that has Bluetooth.


 HC-05 Bluetooth Module
 Android Studio (To develop the required Android app)
 USB cable for programming and powering the Arduino
 DHT-11 temperature and humidity sensor

THEORY:

To use the HC-05 Bluetooth module, simply connect the VCC to the 5V output on the
Arduino, GND to Ground, RX to TX pin of the Arduino, and TX to RX pin of the
Arduino. If the module is being used for the first time, you’ll want to change the name,
passcode etc. To do this the module should be set to command mode. Connect the Key
pin to any pin on the Arduino and set it to high to allow the module to be programmed.

Circuit Diagram-
1. connection with Bluetooth
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

2. Connection with DHT11

PROGRAM
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

#include <SoftwareSerial.h>

#include "DHT.h"

#define DHTPIN 2

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

SoftwareSerial BTSerial(4,5);

void setup() {

String setName = String("AT+NAME=MyBTBee\r\n"); //Setting name as 'MyBTBee'

Serial.begin(9600);

BTSerial.begin(38400
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

BTSerial.print("AT\r\n"); //Check Status

delay(500);

while (BTSerial.available()) {

Serial.write(BTSerial.read());

BTSerial.print(setName); //Send Command to change the name

delay(500);

while (BTSerial.available()) {

Serial.write(BTSerial.read());

dht.begin();

void loop()

{ char c;

if(Serial.available())

c = Serial.read();

if(c=='t')
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

readSensor();

}}

void readSensor() {

float h = dht.readHumidity();

float t = dht.readTemperature();

if (isnan(h) || isnan(t)) {

Serial.println("Failed to read from DHT sensor!");

return;

float hic = dht.computeHeatIndex(t, h, false);

Serial.print("Humidity: ");

Serial.print(h);

Serial.print(" %\t");

Serial.print("Temperature: ");

Serial.print(t);

Serial.print(" *C ");

Serial.print("Heat index: ");

Serial.print(hic);
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

Serial.print(" *C ");

Viva question-

1.What is Bluetooth Arduino?

2.How do I communicate with Arduino Bluetooth?

3.How do I transfer data from Arduino to Bluetooth module?

4.How do I connect Raspberry Pi to Arduino Bluetooth?


IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

EXPERIMENT-9

AIM To interface Bluetooth with Arduino/Raspberry Pi and write a program to


turn LED ON/OFF when ‘1’/’0’ is received from smartphone using Bluetooth.

APPARATUS

 An Arduino. Any model can be used, but all code and schematics in this manual will be
for the Uno.
 An Android Smartphone that has Bluetooth.
 HC-05 Bluetooth Module
 Android Studio (To develop the required Android app)
 USB cable for programming and powering the Arduino
 LED and resistor

Theory
HC 05/06 works on serial communication.here the android app is designed to send serial
data to the Bluetooth module when a certain button is pressed. The Bluetooth module at
the other end receives the data and sends it to Arduino through the TX pin of the
Bluetooth module(RX pin of Arduino). The Code fed to Arduino checks the received data
and compares it.If received data is 1 the LED turns on turns OFF when received data is 0

Open the serial monitor and watch the received data


 Press paired devices
 Select your Bluetooth module from the List (HC 05)
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

PROGRAM

char data = 0; //Variable for storing received data

void setup()

Serial.begin(9600); //Sets the data rate in bits per second (baud) for serial data
transmission

pinMode(13, OUTPUT); //Sets digital pin 13 as output pin

void loop()

if(Serial.available() > 0) // Send data only when you receive data:

data = Serial.read(); //Read the incoming data and store it into variable data

Serial.print(data); //Print Value inside data in Serial monitor

Serial.print("\n"); //New line

if(data == '1') //Checks whether value of data is equal to 1


IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

digitalWrite(13, HIGH); //If value is 1 then LED turns ON

else if(data == '0') //Checks whether value of data is equal to 0

digitalWrite(13, LOW); //If value is 0 then LED turns OFF

}}

CIRCUIT DIAGRAM

Installing the Android


Application

Download the
application from
Amazon App Store or
Github.

 Pair your device


with the HC 05/06
Bluetooth module:
 Turn ON the HC
05/06 Bluetooth
module by
powering the
Arduino.
 Scan your
smartphone
for
available
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

devices.3. Pair your smartphone to the HC 05/06 by entering default password 1234 OR
0000.
 Install the LED application on your Android device.
 Open the application.

 Press "paired devices".


 Select your Bluetooth module from the list (HC-05/06)
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

VIVA QUESTION

1.How can we control LED using Bluetooth module?

2.How do I turn on the LED light on my Arduino?

3.How do I program a Bluetooth module with Arduino?

4.How do you program a Bluetooth module?

5.What is a Bluetooth module?


IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

EXPERIMENT-10

AIM:-Write a program on Arduino/Raspberry Pi to upload temperature and


humidity data to thingspeak cloud

APPARATUS
 Arduino Uno
 ESP8266 WiFi Module
 DHT11 Sensor
 Breadboard
 Jumper Wires

CIRCUIT DIAGRAM
IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

Procedure:

Step 1: ThingSpeak Setup for Temperature and Humidity Monitoring

For creating your channel on Thingspeak you first need to Sign up on Thingspeak. In case if
you already have account on Thingspeak just sign in using your id and password.

For creating your account go to www.thinspeak.com

Click on Sing up if you don‘t have account and if you already have account click on sign in.

After clicking on signup fill your details.

After this verify your E-mail id and click on continue.

Step 2: Create a Channel for Your Data

Once you Sign in after your account verification, create a new channel by clicking
―New Channel‖ button. After clicking on ―New Channel‖, enter the Name and Description
of the data you want to upload on this channel. For example I am sending my DHT11 sensor
data, so I named it as DHT11 data.

Enter the name of your data ‗Temperature‘ in Field1 and ‗Humidity‘ in Field2. If you want
to use more Fields you can check the box next to Field option and enter the name and
description of your data.

After this click on save channel button to save your details.


IOT LAB MANUAL
PCE/ECE/VI SEM/ 8EC 4-21

Step 3: API Key

To send data to Thingspeak, we need a unique API key, which we will use later in our code
to upload our sensor data to Thingspeak Website.

Click on ―API Keys‖ button to get your unique API key for uploading your sensor data.
PROGRAM

#include <stdlib.h>

#include <DHT.h>

#define DHTPIN 5 // DHT data pin connected to Arduino pin 5

#define DHTTYPE DHT11 // DHT11 (DHT Sensor Type )

DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT

sensor #define SSID "WiFi Name" // "WiFi Name"

#define PASS "WiFi Password" // "Password"

#define IP "184.106.153.149"// thingspeak.com ip

String msg = "GET /update?key=Your API Key"; //change it with your key...

float temp;

int hum;

String tempC;

int error;

void setup()

Serial.begin(115200); // use default 115200.

Serial.println("AT");
delay(5000);

if(Serial.find("OK")){

connectWiFi();

void loop(){

start:

error=0;

temp = dht.readTemperature();

hum = dht.readHumidity();

char buffer[10];

tempC = dtostrf(temp, 4, 1, buffer);

updateTemp();

if (error==1){

goto start;

delay(5000);

}
void updateTemp(){

String cmd = "AT+CIPSTART=\"TCP\",\"";

cmd += IP;

cmd += "\",80";

Serial.println(cmd);

delay(2000);

if(Serial.find("Error")){

return;

cmd = msg ;

cmd += "&field1=";

cmd += tempC;

cmd += "&field2=";

cmd += String(hum);

cmd += "\r\n";

Serial.print("AT+CIPSEND=");

Serial.println(cmd.length());

if(Serial.find(">")){
Serial.print(cmd);

else{ Serial.println("AT+CIPCLO

SE");

//Resend...

error=1;

boolean connectWiFi(){

Serial.println("AT+CWMODE=1");

delay(2000);

String cmd="AT+CWJAP=\"";

cmd+=SSID;

cmd+="\",\"";

cmd+=PASS;

cmd+="\"";

Serial.println(cmd);

delay(5000);
if(Serial.find("OK")){

return true;

}else{

return false;

}
VIVA QUESTION-

1.How do I transfer data from Raspberry Pi to ThingSpeak?

2.How do you upload humidity and temperature to the cloud?

3.How do I send DHT11 data to Thingspeak using ESP8266?


EXPERIMENT-11

AIM: Write a program on Arduino/Raspberry Pi to retrieve temperature and humidity data from
thingspeak cloud.

APPARATUS

 Arduino Uno
 ESP8266 WiFi Module
 DHT11 Sensor
 Breadboard
 Jumper Wires

CIRCUIT DIAGRAM
PROGRAM

#include "ThingSpeak.h"

#include <ESP8266WiFi.h>

const char ssid[] = "xxxxxxxxx"; // your network SSID (name)

const char pass[] = "xxxxxxxx"; // your network password

WiFiClient client;

//---------Channel Details--------//

unsigned long counterChannelNumber = 12345; // Channel ID

const char * myCounterReadAPIKey = "xxxxxxxxxxxxxxxx"; // Read API Key

const int FieldNumber1 = 1; // The field you wish to read

const int FieldNumber2 = 2; // The field you wish to read

// //

void setup()

Serial.begin(115200)
WiFi.mode(WIFI_STA);

ThingSpeak.begin(client);

void loop()

// Network //

if (WiFi.status() != WL_CONNECTED)

Serial.print("Connecting to ");

Serial.print(ssid);

Serial.println("....");

while (WiFi.status() != WL_CONNECTED)

WiFi.begin(ssid, pass);

delay(5000);

Serial.println("Connected to Wi-Fi Succesfully.");

}
//--------- End of Network connection-------//

// Channel 1 //

long temp = ThingSpeak.readLongField(counterChannelNumber, FieldNumber1,


myCounterReadAPIKey);

statusCode = ThingSpeak.getLastReadStatus();

if (statusCode == 200)

Serial.print("Temperature: ");

Serial.println(temp);

else

Serial.println("Unable to read channel / No internet connection");

delay(100);

// End of Channel 1 //

// Channel 2 //

long humidity = ThingSpeak.readLongField(counterChannelNumber, FieldNumber2,


myCounterReadAPIKey);
statusCode = ThingSpeak.getLastReadStatus();

if (statusCode == 200)

Serial.print("Humidity: ");

Serial.println(humidity);

else

Serial.println("Unable to read channel / No internet connection");

delay(100);

// End of Channel 2 //

VIVA QUESTION

1.What is the function for reading humidity from DHT Sensor from Arduino?

2.How do I connect my temperature and humidity sensor to my Arduino?

3.How does Arduino store data in cloud?

4.Do Arduino components work with Raspberry Pi?

5.Is DHT11 analog or digital


EXPERIMET-12
AIM :-To install MySQL database on Raspberry Pi and perform basic SQL queries.

APPARATUS

 Raspberry Pi
 Micro SD Card
 Power Supply
 Ethernet Cord or WiFi dongle (The Pi 3 has WiFi inbuilt)

Procedure

A. Installing MySQL to Raspberry Pi:

1. Before we get started with installing MySQL to our Raspberry Pi, we must first update our
package list and all installed packages.

We can do this by running the following two commands.

Terminals

 sudo apt update


 sudo apt upgrade

2.The next step is to install the MySQL server software to your Raspberry Pi.

Installing MySQL to the Raspberry Pi is a simple process and can be done with the following
command.

Terminals

 sudo apt install mariadb-server


3. With the MySQL server software installed to the Raspberry Pi, we will now need to secure
it by setting a password for the ―root‖ user.

By default, MySQL is installed without any password set up meaning you can access the
MySQL server without any authentication.

Run the following command to begin the MySQL securing process.

 sudo mysql_secure_installation

Just follow the prompts to set a password for the root user and to secure your MySQL
installation. For a more secure installation, you should answer ―Y‖ to all prompts when
asked to answer ―Y‖ or ―N―. These prompts will remove features that allows someone
to gain access to the server easier.

Make sure you write down the password you set during this process as we will need to use it
to access the MySQL server and create databases and users for software such as WordPress
or PHPMyAdmin.

4. Now if you want to access your Raspberry Pi‘s MySQL server and start making changes to
your databases, you can enter the following command.

 sudo mysql -u root -p

5. You will be prompted to enter the password that we just created in step 3 for MySQL‘s
root user.

6. You can now enter MYSQL commands to create, alter, and delete databases. Through this
interface, you can also create or delete users and assign them the rights to manage any
database.
7. There are two different ways you can quit out of the MYSQL command line, the first of
those is to type ―quit;‖ into the MySQL interface.

The other way of quitting out of the MYSQL command line is to press CTRL + D.

8. At this point, you will now have successfully setup MySQL on your Raspberry Pi. Our
next few sections will go into making better use of this database.

B. Performing Queries:

1. Before we proceed to create a MySQL user and database on our Raspberry Pi, we must
first log back into the MySQL command-line tool.

Run the following command to log in to the MySQL command line. You will be prompted to
enter the password for the ―root‖ account that you set up earlier.

Terminal$

 sudo mysql -u root -p

2. Let‘s start by creating a MySQL database using the following command.

This command is super simple and is just ―CREATE DATABASE‖ followed by the name
that you want to give the database. In our example, we will be calling this database
―exampledb―.

mysql >

 CREATE DATABASE exampledb;

3. Next, we will create a MySQL user that we will assign to our new database. We can create
this user by running the following command. For this example, we will be calling the user
―exampleuser‖ and giving it the password ―pimylifeup―. When creating your own, make sure
you replace both of these.

 CREATE USER 'exampleuser'@'localhost' IDENTIFIED BY 'pimylifeup';

4. With the user created, we can now go ahead and grant all privileges to the user so that it
can interact with the database. This command will grant all permissions to our ―exampleuser‖
for all tables within our ―exampledb‖ database.

 GRANT ALL PRIVILEGES ON exampledb.* TO 'exampleuser'@'localhost';

5. The final thing we need to do for both our MySQL database and user to be finalized is to
flush the privilege table. Without flushing the privilege table, the new user won‘t be able to
access the database.

We can do this by running the following command.

 FLUSH PRIVILEGES;

6. Copy Database To/ From A Remote Server

Insecure Method
If you have direct access to the remote server and aren't worried about security

 Mysqldumb -h[server] -u[user] -p[password] [data base name] | mysql -h


[server] -u [user] -p[password] [databasename]

Secure Method

If you can SSH into the remote server you can use this
INDUSTRIAL ELECTRONICS LAB
PCE/ECE/VI SEM/ 6EC10A
Viva question

1.What is the difference between MySQL and SQL

2.How does database import/export work in MySQL? ..


.
3.How can we delete a column or a row in MySQL?

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING Page 78

You might also like