0% found this document useful (0 votes)
17 views50 pages

Iot Worksheet

The document outlines a lab course on the Internet of Things (IoT) at a university, detailing various experiments related to Arduino and Raspberry Pi hardware, software installation, and sensor identification. It includes specific aims, objectives, system requirements, and learning outcomes for each experiment, emphasizing hands-on experience with IoT applications. The document serves as a guide for students to familiarize themselves with essential IoT components and programming using Arduino IDE.

Uploaded by

harshpatil01403
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views50 pages

Iot Worksheet

The document outlines a lab course on the Internet of Things (IoT) at a university, detailing various experiments related to Arduino and Raspberry Pi hardware, software installation, and sensor identification. It includes specific aims, objectives, system requirements, and learning outcomes for each experiment, emphasizing hands-on experience with IoT applications. The document serves as a guide for students to familiarize themselves with essential IoT components and programming using Arduino IDE.

Uploaded by

harshpatil01403
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

UNIVERSITY INSTITUTE OF ENGINEERING

Subject Name –Internet of Things

Course Code- 21csp344b

Submitted To: Submitted By:


Faculty Name:
Sharandeep mam Name: harsh patil
UID: 21bcs1560
Section: 21bcs53
Group: a
Department of Computer Science & Engineering

INDEX
Exp. List of Experiments Conduct Viva Record Total Remarks
No (M.M:12) (M.M:10) (M.M:8) (M.M:30)

1.
Familiarization with
Arduino/Raspberry Pi
hardware and perform
necessary software
installation.

2. Identification of different
sensors used in IoT
applications.

3. Demonstration of
Autodesk Tinkercad
Simulation Platform.

4. Program to interface the


Arduino/Raspberry Pi
with LED and blinking
application
5. To measure the distance
of an object using an
ultrasonic sensor.

6. Interfacing of
Arduino/Raspberry Pi
with temperature and
humidity sensor with real
time application.

7. To display data
generated by sensor on
LCD using
Arduino/Raspberry Pi.

8. Interfacing Air Quality


Sensor (MQ135),
displays data on LCD.

9. Real Time application of


controlling actuators
through bluetooth
application using
Arduino.
10. Study the
Implementation of
Zigbee Protocol using
Raspberry Pi/Arduino.
Experiment 1

Student Name: harsh patil UID: 21BCS1560


Branch: CSE Subject Code: 21csp344b
Semester: 5th
Subject Name: Internet of Things Lab

1. Aim:

Familiarization with Arduino/Raspberry Pi hardware and perform necessary software installation.

2. Objective:

• To study hardware and software related to IoT


• To understand the function of Node MCU, Arduino Uno and Raspberry Pi.

3. System Requirements:
• Windows 7 or above.
• Google Chrome
• Arduino IDE

4. Steps/Program:

An Arduino is a micro controller-based kit. It is basically used in communications and in controlling or


operating many devices. Arduino UNO board is the most popular board in the Arduino board family. In
addition, it is the best board to get started with electronics and coding. Some boards look a bit different
from the one given below, but most Arduino’s have majority of these components in common. It consists
of two memories- Program memory and the data memory. The code is stored in the flash program memory,
whereas the data is stored in the data memory.

Arduino Uno consists of 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog
inputs, a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button
1. Power USB Arduino board can be powered by using the USB cable from your computer. All you
need to do is connect the USB cable to the USB connection (1).
2. Power (Barrel Jack) Arduino boards can be powered directly from the AC mains power supply by
connecting it to the Barrel Jack (2).
3. Voltage Regulator The function of the voltage regulator is to control the voltage given to the Arduino
board and stabilize the DC voltages used by the processor and other elements.
4. Crystal Oscillator The crystal oscillator helps Arduino in dealing with time issues. How does
Arduino calculate time? The answer is, by using the crystal oscillator. The number printed on top of
the Arduino crystal is 16.000H9H. It tells us that the frequency is 16,000,000 Hertz or 16 MHz.
5. 17.Arduino Reset You can reset your Arduino board, i.e., start your program from the beginning.
You can reset the UNO board in two ways. First, by using the reset button (17) on the board. Second,
you can connect an external reset button to the Arduino pin labelled RESET (5).

6,7,8,9.Pins (3.3, 5, GND, Vin)

• 3.3V (6) − Supply 3.3 output volt


• 5V (7) − Supply 5 output volt
• Most of the components used with Arduino board works fine with 3.3 volt and 5 volt.
• GND (8)(Ground) − There are several GND pins on the Arduino, any of which can be used to
ground your circuit.
• Vin (9) − This pin also can be used to power the Arduino board from an external power source, like
AC mains power supply.
10. Analog pins The Arduino UNO board has six analog input pins A0 through A5. These pins can read
the signal from an analog sensor like the humidity sensor or temperature sensor and convert it into a
digital value that can be read by the microprocessor.
11. Main micro controller Each Arduino board has its own micro controller (11). You can assume it as
the brain of your board. The main IC (integrated circuit) on the Arduino is slightly different from
board to board. The micro controllers are usually of the ATMEL Company. You must know what IC
your board has before loading up a new program from the Arduino IDE. This information is
available on the top of the IC. For more details about the IC construction and functions, you can refer
to the data sheet.
12. ICSP pin Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino consisting of
MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI (Serial Peripheral
Interface), which could be considered as an "expansion" of the output. Actually, you are slaving the
output device to the master of the SPI bus.
13. Power LED indicator This LED should light up when you plug your Arduino into a power source to
indicate that your board is powered up correctly. If this light does not turn on, then there is
something wrong with the connection.
14. TX and RX LEDs On your board, you will find two labels: TX (transmit) and RX (receive). They
appear in two places on the Arduino UNO board. First, at the digital pins 0 and 1, to indicate the pins
responsible for serial communication. Second, the TX and RX led (13). The TX led flashes with
different speed while sending the serial data. The speed of flashing depends on the baud rate used by
the board. RX flashes during the receiving process.
15. Digital I/O

• The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide PWM (Pulse Width
Modulation) output. These pins can be configured to work as input digital pins to read logic values (0
or 1) or as digital output pins to drive different modules like LEDs, relays, etc. The pins labeled “~”
can be used to generate PWM.

16. AREF

AREF stands for Analog Reference. It is sometimes, used to set an external reference voltage
(between 0 and 5 Volts) as the upper limit for the analog input pins

Program an Arduino:
• The most important advantage with Arduino is the programs can be directly loaded to the device
without requiring any hardware programmer to burn the program.
• This is done because of the presence of the 0.5KB of Boot-loader which allows the program to be
burned into the circuit.
• All we have to do is to download the Arduino software and writing the code.
• The Arduino tool window consists of the toolbar with the buttons like verify, upload, new, open,
save, serial monitor.
• It also consists of a text editor to write the code, a message area which displays the feedback like
showing the errors, the text console which displays the output and a series of menus like the File,
Edit, Tools menu.

Steps to program an Arduino


1. Programs written in Arduino are known as sketches. A basic sketch consists of 3 parts

• Declaration of Variables
• Initialisation: It is written in the setup () function.
• Control code: It is written in the loop () function.
2. The sketch is saved with .ino extension. Any operations like verifying, opening a sketch, saving a
sketch can be done using the buttons on the toolbar or using the tool menu.
3. The sketch should be stored in the sketchbook directory.
4. Chose the proper board from the tools menu and the serial port numbers.
5. Click on the upload button or chose upload from the tools menu. Thus the code is uploaded by the
boot loader onto the micro controller.

Basic Adruino functions are:


1. digitalRead(pin): Reads the digital value at the given pin.
2. digitalWrite(pin, value): Writes the digital value to the given pin.
3. pinMode(pin, mode): Sets the pin to input or output mode.
4. analogRead(pin): Reads and returns the value.
5. analogWrite(pin, value): Writes the value to that pin.
6. serial.begin(baud rate): Sets the beginning of serial communication by setting the bit rate.

Advantages of Arduino Board


• It is inexpensive.
• It comes with an open source hardware feature which enables users to develop their own kit using
already available one as a reference source.
• The Arduino software is compatible with all types of operating systems like Windows, Linux, and
Macintosh etc.
• It also comes with open source software feature which enables experienced software developers to
use the Arduino code to merge with the existing programming language libraries and can be
extended and modified.
• It is easy to use for beginners.
• We can develop an Arduino based project which can be completely stand alone or projects which
involve direct communication with the software loaded in the computer.
• It comes with an easy provision of connecting with the CPU of the computer using serial
communication over USB as it contains built in power and reset circuitry.

INSTALLING THE ARDUINO IDE


1. Visit http://www.arduino.cc/en/main/software to download the latest Arduino IDE version for your
computer’s operating system. There are versions for Windows, Mac, and Linux systems. At the
download page, click on the “Windows Installer” option for the easiest installation.
2. Save the .exe file to your hard drive.
3. Open the .exe file.
4. Click the button to agree to the licensing agreement:

5. Decide which components to install, then click “Next”:


6. Select which folder to install the program to, then click “Install”:
7. Wait for the program to finish installing, then click “Close”:

8. Now find the Arduino shortcut on your Desktop and click on it. The IDE will open up and you’ll see
the code editor:

CONFIGURING THE ARDUINO IDE


The next thing to do is to make sure the software is set up for your particular Arduino board. Go to the
“Tools” drop-down menu, and find “Board”. Another menu will appear, where you can select from a list of
Arduino models. I have the Arduino Uno R3, so I chose “Arduino Uno”.
EXPLORING THE ARDUINO IDE
If you want, take a minute to browse through the different menus in the IDE. There is a good variety of
example programs that come with the IDE in the “Examples” menu. These will help you get started with
your Arduino right away without having to do lots of research:

Learning outcomes (What I have learnt):

• Understand the function of Node MCU, Arduino Uno and Raspberry Pi.
• Learnt about Arduino IDE.

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
2.
3.
Experiment 2

Student Name: harsh patil UID: 21bcs1560


Branch: CSE Subject Code: 21csp344b
Semester: 5th
Subject Name: Internet of Things Lab

1. Aim:

Identification of different sensors used in IoT applications.

2. Objective:

• To study hardware’s related to IoT.


• To understand and identify different sensors used in IoT.

3. System Requirements:
• Windows 7 or above.
• Google Chrome
• Arduino IDE

4. Steps/Program:

Sensors:

The sensors are defined as a machine, module, or a device that detect changes in the environment. The
sensors transfer those changes to the electronic devices in the form of a signal. A sensor and electronic
devices always work together. The output signal is easily readable by humans. Nowadays, Sensors are used
in daily lives. For example, controlling the brightness of the lamp by touching its base, etc. The use of
sensors is expanding with new technologies.
The sensor is a device, which is made up of Single Crystal Silicon. It is considered as a widely used
semiconductor material. It has superior mechanical stability, machinability, etc. It can also combine
electronics and sensing elements on the same substrate. The sensors are used to measure the physical
quantities, such as pressure, temperature, sound, humidity, and light, etc. An example of sensors is Fire
Alarm, a detector present on the fire alarm detects the smoke or heat. The signal generated from the detector
is sent to the alarming system, which produces an alert in the form of alarm. The types of detectors are
smoke detectors, heat detectors, carbon monoxide detectors, multi-sensors detectors, etc.
1. Temperature sensors

A temperature sensor is a device used to measure temperature. This can be air temperature, liquid
temperature or the temperature of solid matter. There are different types of temperature sensors available
and they each use different technologies and principles to take the temperature measurement.
2. Proximity sensor

A proximity sensor is a sensor able to detect the presence of nearby objects without any physical contact.
A proximity sensor often emits an electromagnetic field or a beam of electromagnetic radiation (infrared, for
instance), and looks for changes in the field or return signal. The object being sensed is often referred to as
the proximity sensor's target. Different proximity sensor targets demand different sensors.

3. Pressure sensor

A pressure sensor is a device for pressure measurement of gases or liquids. Pressure is an expression of the
force required to stop a fluid from expanding, and is usually stated in terms of force per unit area. A pressure
sensor usually acts as a transducer; it generates a signal as a function of the pressure imposed. For the
purposes of this article, such a signal is electrical.

4. Gas sensor

A gas detector is a device that detects the presence of gases in an area, often as part of a safety system. A
gas detector can sound an alarm to operators in the area where the leak is occurring, giving them the
opportunity to leave. This type of device is important because there are many gases that can be harmful to
organic life, such as humans or animals.

5. Smoke sensor

A smoke detector is a sensor that detects smoke as a primary indication of fire. It provides a signal to a fire
alarm system in a large building, or produces an audible and visual signal locally in a room or a home.
Smoke detectors are usually housed in a small, round shaped plastic case, and placed at the roof where there
are risks of fire or fire hazards.

6. IR sensors

An infrared sensor (IR sensor) is a radiation-sensitive optoelectronic component with a spectral


sensitivity in the infrared wavelength range 780 nm … 50 µm. IR sensors are now widely used in motion
detectors, which are used in building services to switch on lamps or in alarm systems to detect unwelcome
guests.

7. Motion detection sensors

A motion sensor (or motion detector) is an electronic device that is designed to detect and measure
movement. Motion sensors are used primarily in home and business security systems, but they can also be
found in phones, paper towel dispensers, game consoles, and virtual reality systems. Unlike many other
types of sensors (which can be handheld and isolated), motion sensors are typically embedded systems with
three major components: a sensor unit, an embedded computer, and hardware (or the mechanical
component). These three parts vary in size and configuration, as motion sensors can be customized to
perform highly specific functions. For example, motion sensors can be used to activate floodlights, trigger
audible alarms, activate switches, and even alert the police.

Learning outcomes (What I have learnt):

• Identifying various sensors used in application of IOT.


• Understand the functioning of sensors.
• Learnt about Arduino IDE.

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
2.
3.
Experiment 3

Student Name: harsh patil UID: 21bcs1560


Branch: CSE Subject Code: 21csp344b
Semester: 5th
Subject Name: Internet of Things Lab

1. Aim:
Demonstration of Autodesk Tinkercad Simulation Platform.

2. Objective:
• Learn about IoT based simulations.
• Testing and model in IoT based simulation platform.

3. System Requirements:

• Google Chrome
• Arduino IDE
• Tinkercad

4. Steps/Program:

Introduction of Tinkercad
Tinkercad - https://www.tinkercad.com is an excellent tool that allows you to simulate Arduino-based systems (and a lot
more). You can (perhaps you SHOULD) simulate all exercises and even your own designs before trying them on real
hardware. It also allows you to do programming using blocks. You can download / copy-paste the generated code later into
Arduino IDE to program the real Arduino board, rather than having to write it from scratch.

Create a new personal account on Tinkercad website (you can also use your Google account to log in). Then select Circuits
on the left pane, and click Create new Circuit.
Hardware
In Components Basic, you can select Arduino Uno R3.

You can rotate it to portrait mode if you wish, which will allow more space for other components to be added.

You can add more components and wire them up as desired. Clicking on the lead of a component allows you to start a
connecting wire from there. Clicking on a wire allows you to change its color.
Programming and Simulation
To program the Arduino,

1. Click on Code
2. You can choose Blocks or Blocks+Text or Text*. For beginners, it is recommended to use Blocks + Text.

• This allows you to see the C++ code generated corresponding to your blocks.
• You can copy this code later into Arduino IDE to program the real Arduino, rather than having to write it
from scratch.
• You can also download the code as an Arduino-compatible .ino file.

3. You can code by selecting the blocks and connecting them appropriately.
4. You can start the simulation by clicking Start Simulation.

You have to click Stop Simulation to stop the simulation before you can modify your program and/or hardware connections.

Debugging (Advanced)
More often than not, the code written by a programmer does not work as expected the very first time he/she runs it. We need
to find out the logical flaws in our code and fix them before we are able to achieve full functionality. Figuring out flaws
usually boil down to inspecting variable values at various points in our code, and comparing it with the expected values at
those points based on the program logic and data inputs. The usual way Arduino programmers do it is by printing out the
variable values to Serial console.

Tinkercad allows for debugging without having to print the values you want to inspect through Serial.

1. Press the Debugger button.


2. Select the line(s) where you want the execution is to be paused. Such a line where you wish to pause execution is
called a breakpoint.
3. Click Start Simulation.
4. Hover over the variable values you want to inspect, and determine if the values are along the expected lines. If not,
there is something wrong, and use your logic to determine what could be wrong.
5. You can press the Resume execution button to run until the next breakpoint.
6. You can also step line by line by clicking the Step Over Next Function button.
Learning outcomes (What I have learnt):

• Testing and model in IoT based simulation platform.


• Learnt about Arduino IDE.

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
Experiment 4

Student Name: harsh patil UID: 21bcs1560


Branch: CSE Subject Code: 21csp344b
Semester: 5th
Subject Name: Internet of Things Lab

1. Aim:

Program to interface the Arduino/Raspberry Pi with LED and blinking application.

2. Objective:

• Learn about interfacing.


• Learn about IoT programming.

3. Requirements:

➢ 1 × Breadboard
➢ 1 × Arduino Uno R3
➢ 1 × LED
➢ 1 × 330Ω Resistor
➢ 2 × Jumper

4. Procedure:

LEDs are small, powerful lights that are used in many different applications. To start, we will work on blinking an LED,
the Hello World of micro controllers. It is as simple as turning a light on and off. Establishing this important baseline
will give you a solid foundation as we work towards experiments that are more complex.

Turn on LED programmatically via Pin 5

➢ Step 1: Start a new sketch in the Arduino IDE. Start a new sketch in the Arduino IDE:
➢ Step 2: Set the pinMode for Pin 5. ...
➢ Step 3: Set Pin 5 HIGH. ...
➢ Step 4: Compile the code. ...
➢ Step 5: Upload the code to Arduino.
Note − To find out the polarity of an LED, look at it closely. The shorter of the two legs, towards the flat edge of the bulb
indicates the negative terminal.

Components like resistors need to have their terminals bent into 90° angles in order to fit the breadboard sockets properly.
You can also cut the terminals shorter.

Sketch
Open the Arduino IDE software on your computer. Coding in the Arduino language will control your circuit. Open the new
sketch File by clicking New.

➢ pinMode(5, OUTPUT) − Before you can use one of Arduino’s pins, you need to tell Arduino Uno R3 whether it is
an INPUT or OUTPUT. We use a built-in “function” called pinMode() to do this.
➢ digitalWrite(5, HIGH) − When you are using a pin as an OUTPUT, you can command it to be HIGH (output 5
volts), or LOW (output 0 volts).

5. Steps/Program:

void setup() { // initialize digital pin 5 as an output.


// put your setup code here, to run once:

pinMode(LED_BUILTIN,OUTPUT);

pinMode(5, OUTPUT);

void loop() { // the loop function runs over and over again forever
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN, HIGH);

digitalWrite(5, HIGH);

delay(10000);

digitalWrite(LED_BUILTIN, LOW);

digitalWrite(5, LOW);

delay(10000);

Learning outcomes (What I have learnt):

• Learnt about interfacing.


• Learnt about IoT programming.
Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
Experiment 5

Student Name: harsh patil UID: 21bcs1560


Branch: CSE Subject Code: 21csp344b
Semester: 5th
Subject Name: Internet of Things Lab

1. Aim:

To measure the distance of an object using an ultrasonic sensor.

2. Objective:

• Learn about ultrasonic sensor in detail.


• Learn about IoT programming.
• Measure the distance of an object using an ultrasonic sensor.

3. Requirements:
• Arduino Uno R3 board
• Ultrasonic sensor (HC-SR04)
• 16×2 LCD I2C Display
• Jumper Wires

4. Procedure:

Arduino:
It is an open-source electronics platform. It consists ATmega328 8-bit Micro controller. It can be able to read inputs from
different sensors & we can send instructions to the micro controller in the Arduino. It provides Arduino IDE to write code &
connect the hardware devices like Arduino boards & sensors.

Ultrasonic Sensor:
An ultrasonic Sensor is a device used to measure the distance between the sensor and an object without physical contact.
This device works based on time-to-distance conversion.

Working Principle of Ultrasonic Sensor:


Ultrasonic sensors measure distance by sending and receiving the ultrasonic wave. The ultrasonic sensor has a sender to
emit the ultrasonic waves and a receiver to receive the ultrasonic waves. The transmitted ultrasonic wave travels through the
air and is reflected by hitting the Object. Arduino calculates the time taken by the ultrasonic pulse wave to reach the
receiver from the sender.

We know that the speed of sound in air is nearly 344 m/s,

So, the known parameters are time and speed (constant). Using these parameters, we can calculate the distance traveled by
the sound wave.
Formula: Distance = Speed * Time

In the code, the “duration” variable stores the time taken by the sound wave traveling from the emitter to the receiver. That
is double the time to reach the object, whereas the sensor returns the total time including sender to object and object to
receiver. Then, the time taken to reach the object is half of the time taken to reach the receiver.

Distance = Speed of Sound in Air * (Time Taken / 2)

Setup:

1. Connect the Echo pin of the sensor to the D2 pin of the Arduino.
2. Connect the Trig pin of the sensor to the D3 pin of the Arduino.
3. Navigate to Tools and select board and port.
4. Verify and compile the code, then upload the code to the Arduino Uno R3 board.
5. Monitor the output in the Serial monitor (Set the baud rate as 9600). To open Serial monitor Tools>Serial
Monitor or (Ctrl+Shift+M).

Steps to Interface LCD display:

1. Install driver library for Liquid Crystal Display.


2. Import the header file “LiquidCrystal_I2C.h” in the code.
3. Connect the SDA pin of an LCD display to the SDA pin of the Arduino Board and the SCL pin of an LCD
display to the SCL of the Arduino Board.
4. Connect VCC to 5V pin and GND to GND pin.
5. Include the below code to define the display device.

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C
lcd(0x20, 16, 2); // Format => (ADDRESS,Width,Height )

void setup()
{

lcd.init(); // Initialize the lcd


lcd.backlight(); // Turn on the Backlight

// ....
}

5. Steps/Program:

#define echoPin \

2 // attach pin D2 Arduino to pin Echo of HC-SR04


#define trigPin \

3 // attach pin D3 Arduino to pin Trig of HC-SR04 \

long duration; // Variable to store time taken to the pulse to reach receiver

int distance; // Variable to store distance calculated using formula

void setup()

pinMode(trigPin,OUTPUT); // Sets the trigPin as an OUTPUT

pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT

// Serial Communication is starting with 9600 of baudrate speed

Serial.begin(9600);

// The text to be printed in serial monitor

Serial.println("Distance measurement using Arduino Uno.");

delay(500);

void loop()

digitalWrite(trigPin, LOW);

delayMicroseconds(2); // wait for 2 ms to avoid collision in serial monitor

digitalWrite(

trigPin, HIGH); // turn on the Trigger to generate pulse

delayMicroseconds(10); // keep the trigger "ON" for 10 ms to generate pulse for 10 ms.

digitalWrite(trigPin,LOW);

duration = pulseIn(echoPin, HIGH);

distance = duration * 0.0344 / 2;

Serial.print("Distance: ");

Serial.print(distance); // Print the output in serial monitor

Serial.println(" cm");

delay(100);

}
6. Output:

Learning outcomes (What I have learnt):

• Learnt about ultrasonic sensor in detail.


• Learnt about IoT programming.
• Measured the distance of an object using an ultrasonic sensor.

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
Experiment 6

Student Name: harsh patil UID: 21bcs1560


Branch: CSE Subject Code: 21csp344b
Semester: 5th
Subject Name: Internet of Things Lab

1. Aim:

Interfacing of Arduino/Raspberry Pi with temperature and humidity sensor with real time application.

2. Objective:

• Learn about Temperature sensor in detail.


• Learn about IoT programming.
• Measure the temperature with temperature and humidity sensor.

3. Requirements:
• Arduino Uno R3 board
• Ultrasonic sensor (HC-SR04)
• Jumper Wires

4. Procedure:

DHT11 Sensor:

DHT11 Module features a temperature & humidity sensor complex with a calibrated digital signal output. The exclusive
digital-signal-acquisition technique and temperature & humidity sensing technology ensure high reliability and excellent
long-term stability. This sensor includes an NTC for temperature measurement and a resistive-type humidity
measurement component for humidity measurement. These are connected to a high- performance 8-bit microcontroller,
offering excellent quality, fast response, anti-interference ability, and cost effectiveness.

DHT11 Circuit Diagram:

The schematic diagram for the DHT11 module is given below. As mentioned earlier, the board has a very low
components count. The VCC and GND are directly connected to the DHT11 and a pullup resistor is added to the DATA
pin. Sufficient filtering is provided with the tantalum and multilayer capacitors. An LED with a current limit resistor is
used as a power indicator.

Humidity Sensor:

The humidity sensor is a device that senses, measures, and reports the relative humidity (RH) of air or determines the
amount of water vapor present in gas mixture (air) or pure gas. Humidity sensing is related to a water adsorption and
desorption process.
5. Steps/Program:

#include <dht.h>
dht DHT;
void setup() {
Serial.begin(9600);
}
void loop(){
int chk = DHT.read11(7); //digital pin 7 for input of temperature
Serial.print("temperature: ");
Serial.println(DHT.temperature);
Serial.print("humidity: ");
Serial.println(DHT.humidity);
delay(1000);
}

6. Output:
Learning outcomes (What I have learnt):

• Learned about Temperature sensor in detail.


• Learned about IoT programming.
• Measured the temperature with temperature and humidity sensor.

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
Experiment 7

Student Name: harsh patil UID: 21bcs1560


Branch: CSE Subject Code: 21csp344b
Semester: 5th
Subject Name: Internet of Things Lab

1. Aim:

To display data generated by sensor on LCD using Arduino/Raspberry Pi.

2. Objective:

• Learn about LCD in detail.


• Learn about IoT programming.
• Display data generated by sensor on LCD using Arduino/Raspberry Pi.

3. Requirements:
• Arduino Uno R3 board
• LCD
• Jumper Wires

4. Procedure:

Arduino LCD Display

The LCD (Liquid Crystal Display) is a type of display that uses the liquid crystals for its operation. The library that allows
us to control the LCD display is called Liquid Crystal Library.

The library is based on a compatible chipset called Hitachi HD44780. It is found on most of the LCDs that are based on text.
It works with either an 8-bit mode or 4-bit mode. Here, the bit mode signifies the data lines in addition to the enable, rs, and
rw control lines (optional).

LCD Structure

The LCD display has a 16-pin interface.

The structure of the LCD is shown below.

The Liquid Crystal Display has a parallel interface. It means that the microcontroller operates several pins at once to control
the LCD display.
• Pin1(Vss): Ground pin of the LCD module.

• Pin2(Vcc): Power to LCD module (+5V supply is given to this pin)

• Pin3(VEE): Contrast adjustment pin. This is done by connecting the ends of a 10K potentiometer to +5V and
ground and then connecting the slider pin to the VEE pin. The voltage at the VEE pin defines the contrast. The
normal setting is between 0.4 and 0.9V.

• Pin4(RS): Register select pin. The JHD162A has two registers namely command register and data register. Logic
HIGH at RS pin selects data register and logic LOW at RS pin selects command register. If we make the RS pin
HIGH and feed an input to the data lines (DB0 to DB7), this input will be treated as data to display on LCD screen.
If we make the RS pin LOW and feed an input to the data lines, then this will be treated as a command (a command
to be written to LCD controller – like positioning cursor or clear screen or scroll).

• Pin5(R/W): Read/Write modes. This pin is used for selecting between read and write modes. Logic HIGH at this
pin activates read mode and logic LOW at this pin activates write mode.

• Pin6(E): This pin is meant for enabling the LCD module. A HIGH to LOW signal at this pin will enable the
module.

• Pin7(DB0) to Pin14(DB7): These are data pins. The commands and data are fed to the LCD module though these
pins.

• Pin15(LED+): Anode of the back light LED. When operated on 5V, a 560-ohm resistor should be connected in
series to this pin. In Arduino based projects the back light LED can be powered from the 3.3V source on the
Arduino board.

• Pin16(LED-): Cathode of the back light LED.

5. Steps/Program:

#include "LiquidCrystal.h"
LiquidCrystal lcd(8,7,6,5,4,3);
int GAS_VAL = 0;
void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(" Experiment 7 ");
}
void loop()
{
GAS_VAL = analogRead(A0);
Serial.println(GAS_VAL);
if (GAS_VAL > 500)
{
lcd.setCursor(0,1);
lcd.print(" GAS Detected");
}
else
{
lcd.setCursor(0,1);
lcd.print(" GAS Not Detect");
}
delay(10); // Delay a little bit to improve simulation performance
}

6. Output:
Learning outcomes (What I have learnt):

• Learn about LCD in detail.


• Learn about IoT programming.
• Display data generated by sensor on LCD using Arduino/Raspberry Pi.

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
Experiment 8

Student Name: harsh patil UID: 21bcs1560


Branch: CSE Subject Code: 21csp344b
Semester: 5th
Subject Name: Internet of Things Lab

1. Aim:

Interfacing Air Quality Sensor (MQ135), displays data on LCD.

2. Objective:

• Learn about LCD in detail.


• Learn about IoT programming.
• Interfacing Air Quality Sensor (MQ135), displays data on LCD.

3. Requirements:
• Arduino Uno R3 board
• LCD
• Jumper Wires
• MQ135 Air Quality Sensor.

4. Procedure:

About Air Quality Sensor:

MQ-135 sensor belongs to the MQ series that are used to detect different gasses present in the air. The MQ-135 sensor is
used to detect gases such as NH3, NOx, alcohol, Benzene, smoke, CO2, etc. steel exoskeleton houses a sensing device
within the gas sensor module.

Specifications
The table below shows some key specifications of the MQ-135 sensor module:
Feature Description

Operating Voltage 2.5-5.0V

10ppm-300ppm for NH3


Detecting Concentration 10ppm-1000ppm for Benzene
10ppm-300ppm for Alcohol

Load Resistance Adjustable

Heater Resistance 33Ω ± 5%

Heater Consumption less than 800mW

Operating Temperature -10 to 45°C

Pinout

MQ-135 Sensor Pinout

This sensor has 4 pins:

• 5V: Module power supply – 5 V


• GND: Ground
• DOUT: Digital output
• AOUT: Analog output

Circuit

The MQ-135 sensor module consists of four pins namely VCC, GND, DO, and DO. The table below gives a brief
description of them.

Pin Description

VCC Positive power supply pin that powers up the sensor module.

GND Reference potential pin.

Analog output pin. It generates a signal proportional to the concentration of gas vapors coming in
AO
contact with the sensor.

Digital Output pin. It also produces a digital signal whose limit can be set using the in-built
DO
potentiometer.

5. Steps/Program:
int sensorValue;
int digitalValue;

void setup()
{
Serial.begin(9600); // sets the serial port to 9600
pinMode(13, OUTPUT);
pinMode(2, INPUT);
}

void loop()
{
sensorValue = analogRead(0); // read analog input pin 0
digitalValue = digitalRead(2);
if (sensorValue > 400)
{
digitalWrite(13, HIGH);
}
else
digitalWrite(13, LOW);
Serial.println(sensorValue, DEC); // prints the value read
Serial.println(digitalValue, DEC);
delay(1000); // wait 100ms for next reading
}

#include "LiquidCrystal.h"
LiquidCrystal lcd(8,7,6,5,4,3);
int GAS_VAL = 0;
void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
lcd.begin(16,2);

lcd.setCursor(0,0);
lcd.print(" Experiment 7 ");
}
void loop()
{
GAS_VAL = analogRead(A0);
Serial.println(GAS_VAL);
if (GAS_VAL > 500)
{
lcd.setCursor(0,1);
lcd.print(" GAS Detected");
}
else
{
lcd.setCursor(0,1);
lcd.print(" GAS Not Detect");
}
delay(10); // Delay a little bit to improve simulation performance
}

6. Output:
Learning outcomes (What I have learnt):

• Learn about LCD in detail.


• Learn about IoT programming.
• Interfacing Air Quality Sensor (MQ135), displays data on LCD.
Experiment 9

Student Name: harsh patil UID: 21bcs1560


Branch: CSE Subject Code: 21csp344b
Semester: 5th
Subject Name: Internet of Things Lab

1. Aim:

Real Time application of controlling actuators through bluetooth application using Arduino.

2. Objective:

• Learn about Bluetooth module in detail.


• Learn about IoT programming.
• Real Time application of controlling actuators through bluetooth (HC-05) application using Arduino.

3. Requirements:
• Arduino Uno R3 board
• HC-05
• Jumper Wires
• 1k Resistor

4. Procedure:

a) Arduino Bluetooth:
Bluetooth module is a basic circuit set of chip which integrated Bluetooth functions and which can be used in
wireless network transmission. Generally, the Bluetooth module can be divided into the following types: data
transmission module, remote control module, etc.
Flexible and packed with high Bluetooth transmission speed, the Grove – Blueseeed LE – Dual Model (HM13)
uses a CSR dual-mode Bluetooth chip, with the ARM architecture single chip that supports AT instructions.
This allows users like yourself to have control over the serial baud rate, equipment name, and pairing password!
You may be wondering; why not the HC-06 or HC-05 Arduino Bluetooth module instead? Well, with the Grove –
Blueseeed – Dual Model (HM13), you’re getting the following key advantages:
Bluetooth 4.0 BLE rather than Bluetooth V2.0

b) Hardware configurations:
Step 1: Connect the Grove – Blueseeed – Dual model (HM13) to a Grove port on the Grove – Base Shield via the
Grove cable
Step 2: Plug Grove – Base Shield into your Arduino board
Step 3: Connect your Arduino to PC via USB cable
c) Understanding the software:
Conventions
In EDR mode, only the slave can be configured while either master or slave can be in BLE mode.
Factory default setting: EDR Name HMSoft, Slave role, PinCode 1234
BLE Name HMSoft, Slave role, PinCode 000000
Baud: 115200, N, 8, 1;
AT Command format: Uppercase AT command format. string format, without any other symbol. (e.g. \r or \n).
Any incorrect command would get no response.

d) How to program on the Arduino Bluetooth Module


After understanding the software configurations, here’s how to configure Bluetooth with a PC. For hardware
connection, do refer to the “Hardware configurations” section. You’ll find that the flashing blue LED on the
module illustrates no connection is set up
Step 1: Open a serial terminal and set Baud Rate: 115200, Databits: 8, Stopbits: 1, and no flow control like above
Step 2: Send “AT” to Bluetooth with the serial terminal to check if you receive an “OK”
The Bluetooth only respond AT commands either when:No connection is set up
All commands were seen as string and sent out.

e) How to pair Arduino Bluetooth Module with iPhone and Andriod


Since the Grove – Blueseeed – Dual model (HM13) have two protocol: Bluetooth EDR (Enhanced Data Rate) and
Bluetooth Low Energy (BLE), it can communicate with either Andriod or iPhones!
For this part of the tutorial, we’ll use an iPhone to demonstrate how you can interact with Bluetooth!

Step 1: Power the Bluetooth and configure it as a Peripheral role


Step 2: Search LightBlue in the App Store and install it
Step 3: Launch the app, and connect to “HM-13-BLE”
Step 4: Touch on properties and hit “listen for notifications” to enable data receiving
There’s a “Hex” key on the top right under properties to change data format as well

Step 5: Hit “Write new value” and write some words to start sending data to the PC

f) Bluetooth Data transmission guide between two Arduino boards


Now after all the above steps, are you ready to code? In this final section, we’ll use two Arduino Uno and a pair of
Bluetooth modules to get started!
Step 1: Set up the connection mentioned in the hardware configurations section
Step 2: Assign the Bluetooth to the Central role by modifying the text to “#define MASTER 1”
The program of Central and Peripheral use the same code but there’s a difference in the micro define at the
beginning of the program
Step 3: Follow the flow chart below for initialization of the program
After the initialisation, the Central and Peripheral will do different things; Central will send a message to the
Peripheral interval and print what’s received from the Peripheral while the Peripheral only responds to the central
Step 4: Download the test code and open HM-13_SW.ino with Arduino IDE, compile and download to Arduino
Uno
Remember to configure the Bluetooth to the different role by modifying the macro at the beginning
Step 5: After the program is downloaded, open two serial terminal windows and wait for the Bluetooth connection
A connection is indicated by: LEDs on the Bluetooth modules will flash for a few seconds, stop flashing, and kept
on.
According to the program written, the Central will now send a message to the Peripheral continually and get
feedback every time.

5. Steps/Program:

#include <SoftwareSerial.h>
SoftwareSerial SUART(10, 11); // SRX = 2, STX = 3
#define ledpin 13 //built-in L of UNO

void setup()
{
pinMode(ledpin, OUTPUT);
digitalWrite(ledpin, LOW); //L is OFF
Serial.begin(9600);
SUART.begin(9600);
}

void loop()
{
if (SUART.available())
{
char x = SUART.read();
if (x == 'Y')
{
digitalWrite(ledpin, HIGH); //L is ON
}
if (x == 'N')
{
digitalWrite(ledpin, LOW); //L is OFF
}
}
if(Serial.available())
{
char c = Serial.read();
SUART.write(c);
}
}

6. Output:
Learning outcomes (What I have learnt):

• Learnt about Bluetooth module in detail.


• Learnt about IoT programming.
• Learnt about Real Time application of controlling actuators through bluetooth (HC-05) application using
Arduino.
Experiment 10

Student Name: harsh patil UID: 21bcs344b


Branch: CSE Subject Code: 21csp344b
Semester: 5th
Subject Name: Internet of Things Lab

1. Aim:
Study the Implementation of Zigbee Protocol using Raspberry Pi/Arduino.

2. Objective:

• Learn about Zigbee in detail.


• Learn about IoT programming.
• Implementation of Zigbee Protocol using Raspberry Pi/Arduino.

3. Requirements:
• Arduino Uno R3 board
• Jumper Wires
• 1k Resistor
• 2 XBee Pro S2 Transceiver
• 2 UART to USB adapter board1 USB
Cord

4. Procedure:

Introduction
XBee wireless transceivers provide a quick, easy way to add wireless communication to any system. This page
will outline how to set up two XBee Pro Series 2 transceivers for communication with each other.

Step 1: Download X-CTU Software


The X-CTU software is free to download and provides a simple interface to configure andupdate your XBee
transceivers. With this software firmware updates are a breeze and configuration is simple. The software can be
downloaded from Digi’s website.

Step 2: Put together your XBee breakout board


The XBee transceivers have a 2mm pin spacing, which does not allow them to be pluggedinto a standard 0.1-inch
breadboard. There are, however, several different breakout boardsavailable that allow the transceiver to be
inserted into a breadboard. The various adapter boards also allow for connection through USB or serial to your
computer. The breakout board used here has a UART to USB conversion circuit and allows the XBee to be
connected to the computer and XCTU software easily.

Step 3: Configure 1st XBee as a coordinator


When opening the X-CTU software you should see a window like that shown. After selecting the proper COM
port click the Test/Query button.

After selecting the Test/Query button, you should see a dialogue box like the one below. You will want to record
the serial number shown, as you will need it in a couple minutes.

After recording the serial number you can click OK. Next, select the Modem Configurationtab at the top of the
window. Once here, select the read button. This will bring up the current configuration for the connected XBee
and will be similar to the following:

Once here, you want to select Zigbee Coordinator AT in the function set drop down menu.
After selecting the coordinator function set, you will need to set the PAN ID. This can beany four-digit number
and allows the XBees to distinguish between modules in their network and those from other networks. Once you
have added the wanted PAN ID click the “Write” button. This will update and configure the XBee. Once this is
done you can disconnect the XBee and plug in the second XBee.

Step 4: Configure 2nd XBee as Router


To configure the 2nd XBee, you will follow the same process as for the coordinator with one difference. In the
PC settings tab, again, click the “Test/Query” button and record the serial number. Then in the Modem
configuration tab, click the read button to load the current configuration of the XBee and set the PAN ID to the
same ID used for the coordinator. The only change will be the function set you choose. For the second XBee we
will set this as Zigbee Router AT.
After setting the PAN ID and the function set for the router you will put the recorded serialnumbers to use. Enter
the first 6 digits of the coordinators serial number into the Destination Address High field and the rest of the
serial number into the Destination Address Low field. Then select the “Write” button to update the configuration
settings forthe router. Once this is done updating you can disconnect the router and reconnect the coordinator to
the computer.

After re-connecting the coordinator to the computer. You will again go into the Modem Configuration tab and
click the read button. You will then want to set the Destination Address to the serial number of the Router XBee
in the same manner as you just did for the Router. Once done you will again click the write button to update the
coordinator XBeesettings. After the write process is complete you are ready to use your XBees and communicate
wirelessly

Step 5: Test the configuration


A simple test can be done to be sure the two XBees are communicating properly. You canconnect either one of
the XBees to the computer. Then, connect the second XBee to 3.3Vpower and connect the Dout and Din pins
together. This will cause the XBee to automatically retransmit any data it receives.
When you have both XBees connected go to the Terminal tab in the X-CTU window. Whatever you type in the
terminal window will appear in blue font and whatever is received will appear in red font. If the XBees are
configured correctly every character youtype should be mirrored in red.

When typing single characters, you should see a screen similar to the one above. To send strings of data you can
assemble a data packet. To do this click the “Assemble Packet” button and type the wanted string into the box
then click send data. This will send the entire packet before receiving the same packet back.
If everything you type is being reflected back in red, you are successfully transmitting andreceiving with your
XBees!! You are now ready to use them however you wish. You canconnect them to any microcontroller and
transmit data through the UART peripheral or you can connect each XBee to a different computer and have a chat
application. There aremany more possibilities that are now at your fingertips with your working XBees.

About Zigbee
Zigbee is a wireless communication protocol targeted for battery-powered devices (it has both low power and
low cost). It generally operates in the 2.4GHz range (although there are geographic variations), and supports data
ranges from 20 to 250 kbits/s. The transmission distance though, is small compared to the likes of LoRa. It is 10
to 100 m, whereas LoRa can transmit over a few kilometers. Another thing to note is that Zigbee communication
doesn’t work very well if there is no line of sight between transmitter andreceiver.

These works with UART and therefore, it is fairly easy to interface them with Arduino. Itis important to look at
the pinout of XBee though, to understand which are the UART pins

The DOUT and DIN pins in the figure above are the UART pins (TX and RX). They can be connected to two
digital pins of Arduino (if you plan to use SoftwareSerial), or else topins 0 and 1 of Arduino respectively (if you
plan to use HW Serial). Please note that you

won’t be able to read print statements from the Arduino on the Serial Monitor if you use Hardware Serial for
Zigbee interface.

Configuring the XBee modules

Here are a few things to note about the configuration −

• You will need a breakout board or an Explorer with a USB to UART converter for thisconfiguration.
• The PAN ID (Personal Area Network ID) has to be the same for the devices that want tocommunicate with
each other.
• One module needs to be set as the transmitter and the other as the receiver (this isdetermined by the
CE field).
• Note the baud rate that you set. This will be used in the Arduino code, when configuringthe Serial
communication with XBee.
Circuit Diagram
Once your XBee is configured, you can connect it to the Arduino via the breakout/Explorerboard. In that case, the
pinout will be slightly different depending on which board/ Explorer you are using. Here we will assume you are
connecting the XBee directly to Arduino Uno, in which case, the connections will be –

5. Steps/Program:

#include <SoftwareSerial.h>
SoftwareSerial xbeeSerial(2,3); //RX, TX

void setup() {
Serial.begin(9600);
xbeeSerial.begin(9600);
}
void loop() {
if(Serial.available() > 0){ char
input = Serial.read();
xbeeSerial.print(input);
}
}
void setup() {
Serial.begin(9600);
xbeeSerial.begin(9600);
}
void loop() {
if(xbeeSerial.available() > 0){char
input = xbeeSerial.read();
Serial.print(input);
}
}

6. Output:
Learning outcomes (What I have learnt):

• Learnt about Zigbee module in detail.


• Learnt about IoT programming.
• Implementation of Zigbee Protocol using Raspberry Pi/Arduino.

You might also like