Professional Documents
Culture Documents
Gtu IOT Practicals
Gtu IOT Practicals
and Technology
Department of Computer Engineering
Practical Submission
(Institute/Department Seal)
CERTIFICATE
Date : 27/04/2021
Practical No:1
1) What is Arduino?
Arduino is an open-source platform used for building electronics projects. Arduino consists of
both a physical programmable circuit board (often referred to as a microcontroller) and a piece
of software, or IDE (Integrated Development Environment) that runs on your computer, used to
write and upload computer code to the physical board.
The Arduino platform has become quite popular with people just starting out with electronics,
and for good reason. Unlike most previous programmable circuit boards, the Arduino does not
need a separate piece of hardware (called a programmer) in order to load new code onto the
board-you can simply use a USB cable. Additionally, the Arduino IDE uses a simplified
version of C++, making it easier to learn to program. Finally, Arduino provides a standard form
factor that breaks out the functions of the micro-controller into a more accessible package.
1
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
The Uno is a huge option for your initial Arduino. This Arduino board depends on an
ATmega328P based microcontroller. As compared with other types of arduino boards, it is very
simple to use like the Arduino Mega type board. .It consists of 14-digital I/O pins, where 6-pins
can be used as PWM(pulse width modulation outputs), 6-analog inputs, a reset button, a power
jack, a USB connection, an In-Circuit Serial Programming header (ICSP), etc. It includes
everything required to hold up the microcontroller; simply attach it to a PC with the help of a
USB cable and give the supply to get started with an AC-to-DC adapter or battery.
Arduino Uno is the most frequently used board and it is the standard form apart from all the
existing Arduino Boards. This board is very useful for beginners.
2
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
Arduino Nano
As compared with the Arduino Uno board, it is small in size. The devices like mini USB and
Arduino IDE are necessary to build the projects. This board mainly includes analog pins-8,
digital pins-14 with the set of an I/O pin, power pins-6 & RST (reset) pins-2.
Arduino Micro
iv) Arduino Due:
This Arduino board depends on the ARM Cortex-M3 and it is the first Arduino microcontroller
board. This board includes digital I/O pins-54 where 12-pins are PWM o/p pins, analog pins
12, UARTs-4, a CLK with 84 MHz, an USB OTG, DAC-2, a power jack, TWI-2, a JTAG
header, an SPI header, two buttons for reset & erase.
3
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
Arduino Due
This board works with 3.3V where the highest voltage that the pins of input/output can stand is
3.3V because providing a high voltage to any I/O pin can lead to damage the board This board
is simply connected to a computer through a small USB cable otherwise it can be powered
through an AC to DC adapter. This Arduino Due board is suitable with all shields of Arduino at
3.3V.
4
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
this board, the screw terminals are mainly used for power. The programming of this
Bluetooth microcontroller can be done with Bluetooth like a wireless connection. vii)
Arduino Diecimila:
The microcontroller board like Arduino Diecimila mainly depends on the ATmega168. This
board includes digital I/O pins -14 where 6-pins can be used like PWM outputs & analog
inputs-6, a USB connection, a crystal oscillator-16 MHz, an ICSP header, a reset button & a
power jack. This board can be connected to a computer through a USB cable and it can be
activated using a battery and an AC-DC adapter.
Arduino Diecimila
As the name suggests, the meaning of Diecimila in Italian is 10,000 which means that marks
the truth that above 10k Arduino boards have been designed. In a set of USB Arduino boards, it
is the latest one as compared with other versions. viii) RedBoard Arduino Board:
The RedBoard Arduino board can be programmed using a Mini-B USB cable using the
Arduino IDE. It will work on Windows 8 without having to modify your security settings. It is
more constant due to the USB or FTDI chip we used and also it is entirely flat on the back.
5
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
6
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
Arduino Esplora
7
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
The programming of this board can be done using Arduino Software like IDE which takes the
data from the inputs and controls the output like a keyboard or a mouse. As compared with all
other types of Arduino boards, this esplora is totally different because the inputs, as well as
outputs, are connected to the board already. So connecting the components like actuators or
sensors is very simple. Thus, programming is somewhat different as compared with other types
of Arduino boards. This esplora board includes its own library so that the data from the sensors
& actuators are very easy to read and write.
xiii) Arduino Pro Mic:
The Arduino Pro Micro board is the same as the Arduino Mini board apart from the
ATmega32U4 Microcontroller. This pro mic board includes digital I/O pins-12, pulse
width modulation (PWM) pins-5, serial connections of Tx & Rx &10-bit ADC. xiv)
Arduino Ethernet:
The Arduino Ethernet board depends on the microcontroller like ATmega328. This kind of
microcontroller board includes analog pins-5, digital I/O pins-14, RST button, an RJ45
connection, crystal oscillator, a power jack, ICSP header, etc. The connection of the
Arduino board can be done through the Ethernet shield to the internet. xv) Arduino Zero:
This is a powerful as well as simple 32-bit board and it provides the best platform for
innovative projects like wearable technology, smart IoT devices, crazy robotics, high-tech
automation, etc. This board expands by providing improved performance, permitting a range of
project opportunities & performs like a great educational tool.
Arduino Zero
8
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
This board includes analog input pins-6, digital I/O pins-14, a power jack, AREF button,
UART port pins, a USB connector & an In-Circuit Serial Programming (ICSP) header, a power
header, etc.
The Arduino Uno R3 pin diagram is shown below. It comprises 14-digit I/O pins. From these
pins, 6-pins can be utilized like PWM outputs. This board includes 14 digital input/output pins,
Analog inputs-6, a USB connection, quartz crystal-16 MHz, a power jack, a USB connection,
resonator-16Mhz, a power jack, an ICSP header an RST button.
Power Supply:
The power supply of the Arduino can be done with the help of an exterior power supply
otherwise USB connection. The exterior power supply (6 to 20 volts) mainly includes a battery
or an AC to DC adapter. The connection of an adapter can be done by plugging a centerpositive
plug (2.1mm) into the power jack on the board. The battery terminals can be placed in the pins
of Vin as well as GND.
9
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
GND:
GND (ground) pins
Memory:
We know that an arguing Uno R3 includes 14-digital pins which can be used as an input
otherwise output by using the functions like pin Mode (), digital Read(), and digital Write().
These pins can operate with 5V, and every digital pin can give or receive 20mA, & includes a
20k to 50k ohm pull up resistor. The maximum current on any pin is 40mA which cannot
surpass for avoiding the microcontroller from the damage. Additionally, some of the pins of an
Arduino include specific functions.
Serial Pins:
The serial pins of an Arduino board are TX (1) and RX (0) pins and these pins can be used to
transfer the TTL serial data. The connection of these pins can be done with the equivalent pins
of the ATmega8 U2 USB to TTL chip.
The external interrupt pins of the board are 2 & 3, and these pins can be arranged to activate an
interrupt on a rising otherwise falling edge, a low-value otherwise a modify in value.
PWM Pins:
The PWM pins of an Arduino are 3, 5, 6, 9, 10, & 11, and gives an output of an 8-bit PWM
with the function analog Write ().
The SPI pins are 10, 11, 12, 13 namely SS, MOSI, MISO, SCK, and these will maintain the
SPI communication with the help of the SPI library.
10
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
LED Pin:
An arguing board is inbuilt with a LED using digital pin-13. Whenever the digital pin is high,
the LED will glow otherwise it will not glow.
The TWI pins are SDA or A4, & SCL or A5, which can support the communication of TWI
with the help of Wire library.
An analog reference pin is the reference voltage to the inputs of an analog i/ps using the
function like analog Reference().
This pin brings a low line for resetting the microcontroller, and it is very useful for using an
RST button toward shields which can block the one over the Arduino R3 board.
Communication:
The communication protocols of an Arduino Uno include SPI, I2C, and UART serial
communication.
UART:
An Arduino Uno uses the two functions like the transmitter digital pin1 and the receiver digital
pin0. These pins are mainly used in UART TTL serial communication.
I2C:
An Arduino UNO board employs SDA pin otherwise A4 pin & A5 pin otherwise SCL pin is
used for I2C Communication with wire library. In this, both the SCL and SDA are CLK signal
and data signal.
SPI Pins:
11
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
MOSI (Pin11):
This is the master out slave in the pin, used to transmit the data to the devices
MISO (Pin12):
This pin is a serial CLK, and the CLK pulse will synchronize the transmission of which is
produced by the master.
SCK (Pin13):
The CLK pulse synchronizes data transmission that is generated by the master. Equivalent pins
with the SPI library is employed for the communication of SPI. ICSP (in-circuit serial
programming) headers can be utilized for programming ATmega microcontroller directly with
the boot loader.
4) Arduino architecture :
12
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
1. The data is uploaded in serial via the port (being uploaded from the computer’s Arduino
IDE). The data is decoded and then the instructions are sent to instruction register and it
decodes the instructions on the same clock pulse.
2. On the next clock pulse the next set of instructions are loaded in instruction register.
3. In general purpose registers the registers are of 8-bit but there are 3 16-bit registers also.
a. 8-bit registers are used to store data for normal calculations and results.
b. 16-bit registers are used to store data of timer counter in 2 different register. Eg. X-low &
Xhigh. They are fast, and are used to store specific hardware functions.
4. EEPROM stores data permanently even if the power is cut out. Programming inside a
EEPROM is slow.
5. Interrupt Unit checks whether there is an interrupt for the execution of instruction to be
executed in ISR (Interrupt Service Routine).
6. Serial Peripheral Interface (SPI) is an interface bus commonly used to send data between
microcontrollers and small peripherals such as Camera, Display, SD cards, etc. It uses
separate clock and data lines, along with a select line to choose the device you wish to talk
to.
8. Analog comparator compares the input values on the positive and negative pin, when the
value of positive pin is higher the output is set.
9. Status and control is used to control the flow of execution of commands by checking other
blocks inside the CPU at regular intervals.
10. ALU (Arithmetic and Logical unit)The high performance AVR ALU operates in
direct connection with all the 32 general purpose working registers. Within a single clock
cycle, arithmetic operations b/w general purpose registers are executed. The ALU operations
are divided into 3 main categories – arithmetic, logical and bit-function.
13
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020
11. I/O pins The digital inputs and outputs (digital I/O) on the Arduino are what allow you
to connect the Arduino sensors, actuators, and other ICs. Learning how to use them will
allow you to use the Arduino to do some really useful things, such as reading switch inputs,
lighting indicators, and controlling relay outputs.
5) Arduino IDE:
The Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a
text editor for writing code, a message area, a text console, a toolbar with buttons for common
functions and a series of menus. It connects to the Arduino and Genuino hardware to upload
programs and communicate with them.
You can download from here:-https:/www.arduino.cc/en/main/ OldSoftwareReleases
14
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 24/12/2020
Practical No:2
Wiring Diagram:
Sketch:
15
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 24/12/2020
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
Output:
16
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 24/12/2020
Wiring Diagram:
Sketch:
void loop() {
Serial.println("Type a Command: (h | l | H | L)");
while(Serial.available() == 0); delay(10);
command = Serial.read();
Serial.print("Command: ");
17
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 24/12/2020
Output:
18
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 29/12/2020
Practical No: 3
Problem Statement: Perform practical to detect obstacle using IR sensor and Arduino Uno.
Steps:
Circuit Diagram:
19
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 29/12/2020
// Write a program for obstacle detection using Arduino Uno and IR Sensor.
void setup ()
{
pinMode (IRSensor, INPUT); // sensor pin INPUT
pinMode (LED, OUTPUT); // Led pin OUTPUT
Serial.begin(9600); // BaudRate
}
void loop ()
{
isObstacle = digitalRead (IRSensor);
if (isObstacle == LOW)
{
Serial.println("OBSTACLE!!, OBSTACLE!!"); digitalWrite
(LED, HIGH); // LED HIGH
}
else
{ digitalWrite (LED, LOW); // LED LOW
Serial.println("GO Ahead");
}
delay (1000);
}
20
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 29/12/2020
Output:
21
Subject Code: 3160716 Subject: IOT & It’s Applications Date:17/02/2021
Enrollment No:150420107067 Name: Naseebullah Andar
Practical No: 4
Aim : Implement a IoT based practical using packet tracer - "Controlling of garage door
and window for home environment based on CO2 level”
➢ Give ip address and subnet mask to compontants which is connected with switch
22
Subject Code: 3160716 Subject: IOT & It’s Applications Date:17/02/2021
Enrollment No:150420107067 Name: Naseebullah Andar
23
Subject Code: 3160716 Subject: IOT & It’s Applications Date:17/02/2021
Enrollment No:150420107067 Name: Naseebullah Andar
24
Subject Code: 3160716 Subject: IOT & It’s Applications Date:17/02/2021
Enrollment No:150420107067 Name: Naseebullah Andar
➢ According to condition if the co2 level goes up to 0.5 then garage door and windows will
opened
Output:
25
Subject Code:3160716 Subject: Advance java Programming Date:25/02/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
Practical 5
❖ Aim : Implement a IoT based practical using packet tracer - "Controlling of fan
and light for home environment based on motion"
❖ Steps of practical:
➢ connect the Light, Fan, door, motion detector and server with switch.
➢ After that configure IP Address for each device and connect them with server like
Light - 1.1.1.4, Server – 1.1.1.1, Fan – 1.1.1.5, Motion detector – 1.1.1.2, Door –
1.1.1.3 - from each IoT devices Lights, fans turn on remote server.
➢ After that set username, password for web browsing In server (IoT settings).
➢ From each IoT devices connect to the server.
➢ At the server side, you can see all IoT Devices.
➢ For the condition, first login into server, then you can see set condition option. Then
you can set condition.
➢ In that, Select Actions set the condition accordingly
Diagram:
26
Subject Code:3160716 Subject: Advance java Programming Date:25/02/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
27
Subject Code: 3160716 Subject Name: IOT & It’s Applications Date :23/02/2021
Enrollment :150420107067 Name : Naseebullah Andar
PRACTICAL – 6
Problem Statement: Use Adafruit cloud to implement a practical by detecting obstacle with
IR sensor module and NodeMCU.
Steps :
Program:
Adafruit_MQTT_Client mqtt(&esp,server,port,username,key);
Adafruit_MQTT_Publish feed = Adafruit_MQTT_Publish(&mqtt,username"/feeds/IR_data");
SCET/CO/2020-21/Even/BE Shift-I/Sem-VI
28
Subject Code: 3160716 Subject Name: IOT & It’s Applications Date :23/02/2021
Enrollment :150420107067 Name : Naseebullah Andar
void setup()
{
WiFi.begin(wifi,password);
while(WiFi.status()!=WL_CONNECTED)
{ delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println("IP Address: ");
Serial.print(WiFi.localIP());
Serial.println("Connecting to MQTT");
while(mqtt.connect())
{
Serial.print(".");
}
void loop() {
if(mqtt.connected())
{ isObstacle = digitalRead (IRSensor);
Serial.println(digitalRead (IRSensor));
if (isObstacle == LOW)
{
Serial.println("OBSTACLE!!, OBSTACLE!!");
digitalWrite(LED, HIGH); // LED HIGH
} else
{
Serial.println("GO Ahead");
digitalWrite(LED, LOW); // LED LOW
} delay(4000);
SCET/CO/2020-21/Even/BE Shift-I/Sem-VI
29
Subject Code: 3160716 Subject Name: IOT & It’s Applications Date :23/02/2021
Enrollment :150420107067 Name : Naseebullah Andar
if(feed.publish(isObstacle))
{
Serial.println("Success");
} else {
Serial.println("Fail");
} delay(800); } }
Output:
SCET/CO/2020-21/Even/BE Shift-I/Sem-VI
30
Subject Code: 3160716 Subject Name: IOT & It’s Applications Date :23/02/2021
Enrollment :150420107067 Name : Naseebullah Andar
SCET/CO/2020-21/Even/BE Shift-I/Sem-VI
31
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 16/03/2021
Practical No: 7
Problem Statement: Implement a practical to monitor Pulse rate with Arduino Uno
board. (Serial Monitor Control)
Steps:
3. The black wire ,white wire and brown wire of the plus sensor are connected toSV pin,
ground pin and the analog pin A0 of the Arduino Uno board respectively.
4. The library to be used for this practical is PulseSensorPlayground . To access itwe must
click on tools->manage libraries and then download this library after searching for it in the
search bar.
5. The code for this practical is available on the Arduino application itself amd canbe accessed
by clicking on File->PulseSensor Playground -> Getting_BPM_to_Monitor.
6. After all the steps we select our board(Arduino Uno) and port no(COM8) fromtools.
Then we compile and upload or code to the Arduino Uno Board and execute and view the
result from serial monitor.
Program:
#include <PulseSensorPlayground.h>
const int PulseWire = 0;
const int LED13 = 13; int
Threshold = 550;
PulseSensorPlayground pulseSensor;
void setup()
{
Serial.begin(9600); pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED13);
pulseSensor.setThreshold(Threshold);
if (pulseSensor.begin())
{
Serial.println("We created a pulseSensor Object !”); }
}
void loop()
{ int myBPM = pulseSensor.getBeatsPerMinute();
if (pulseSensor.sawStartOfBeat())
{
Serial.println("A HeartBeat Happened ! “);
Serial.print("BPM: ");
Serial.p rintln(myBPM);
} delay(20);
}
Output:
Practical No: 8
Implement a practical to detect the obstacle and give the notification based distance
using Ultrasonic Sensor HC-SR04 and Arduino.
Steps:
Working of Ultrasonic sound sensor : The ultrasonic sensor is a cheap sensor that can
measure 2cm to 400cm of non-contact measurement functionality with a ranging accuracy
that can reach up to 3mm. It uses sonar waves for echolocation, like bats, to be able to
measure distances. This project is an introduction to the use of an ultrasonic sensor, since it is
often not straightforward nor intuitive to wire and code.
2. Lastly, complete the circuit by connecting the Ultrasonic Sensor's ground pin tothe
Arduino's ground pin
3. After all the steps we select our board(Arduino Uno) and port no(COM8) fromtools.Then
we compile and upload or code to the Arduino Uno Board and execute and view the result
from serial monitor
Pinout Details:
This sensor includes four pins and the pin configuration of this sensor is discussed below.
Pin1 (Vcc): This pin provides a +5V power supply to the sensor. Pin2 (Trigger): This is an
input pin, used to initialize measurement by transmitting ultrasonic waves by keeping this pin
high for 10us.
34
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 23/03/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
Program:
// defining variables
long duration; int
distance;
void setup()
{
// Sets the trigger pin as an OUTPUT
pinMode(trigger, OUTPUT);
// Sets the echo pin as an
INPUT pinMode(echo, INPUT);
// Begins the serial communication
Serial.begin(9600);
}
35
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 23/03/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
void loop()
{
// Clears the trigger pin digitalWrite(trigger,
LOW); delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigger, HIGH); delayMicroseconds(10);
digitalWrite(trigger, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds duration =
pulseIn(echo, HIGH);
36
Subject Code:3160716 Subject : IoT and Application Date : 30/03/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
Practical-9
Problem Statement:- Perform a practical to build NodeMCU Webserver and control an
LED from a Webpage.
STEP 1 – MATERIAL PREPARATION
SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI
37
Subject Code:3160716 Subject : IoT and Application Date : 30/03/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI
38
Subject Code:3160716 Subject : IoT and Application Date : 30/03/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
#include <ESP8266WiFi.h>
WiFiServer server(80);
void setup()
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI
39
Subject Code:3160716 Subject : IoT and Application Date : 30/03/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
WiFi.begin(ssid, password);
delay(500);
Serial.print(".");
Serial.println("WiFi connected");
Serial.println("Server started");
Serial.println(WiFi.localIP());
Serial.print("Copy and paste the following URL: https://"); // Will print IP address in
URL format
Serial.print(WiFi.localIP());
Serial.println("/");
void loop()
if (!client)
return;
SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI
40
Subject Code:3160716 Subject : IoT and Application Date : 30/03/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
while(!client.available())
delay(1);
Serial.println(request);
client.flush();
if(request.indexOf("/LED=ON") != -1)
value = HIGH;
if(request.indexOf("/LED=OFF") != -1)
value = LOW;
SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI
41
Subject Code:3160716 Subject : IoT and Application Date : 30/03/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
client.println("Content-Type: text/html");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print(" CONTROL LED: ");
if(value == HIGH)
{
client.print("ON");
}
else
{
client.print("OFF");
}
client.println("<br><br>");
client.println("<a href=\"/LED=ON\"\"><button>ON</button></a>");
client.println("<a href=\"/LED=OFF\"\"><button>OFF</button></a><br />");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}
SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI
42
Subject Code:3160716 Subject : IoT and Application Date : 30/03/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI
43
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
Practical No: 10
--- Introduction:
44
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
Micro-processor Micro-controller
Microprocessor is the heart of Computer Micro Controller is the heart of an embedded
system. system.
It is only a processor, so memory and I/O Micro Controller has a processor along with
components need to be connected externally internal memory and I/O components.
Memory and I/O has to be connected externally, Memory and I/O are already present, and the
so the circuit becomes large. internal circuit is small.
You can't use it in compact systems You can use it in compact systems.
Cost of the entire system is high Cost of the entire system is low
Due to external components, the total power As external components are low, total power
consumption is high. Therefore, it is not ideal consumption is less. So it can be used with
for the devices running on stored power like devices running on stored power like
batteries. batteries.
Most of the microprocessors do not have power Most of the microcontrollers offer
powersaving features. saving mode.
45
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
Microprocessor has a smaller number of Microcontroller has more register. Hence the
registers, so more operations are programs are easier to write.
memory-based.
Microprocessors are based on Von Neumann Micro controllers arc based on Harvard
model architecture
It has no RAM, ROM, Input-Output units, It has a CPU along with RAM, ROM, and
timers, and other peripherals on the chip. other peripherals embedded on a single chip.
It's used for general purpose applications that It's used for application-specific systems.
allow you to handle loads of data.
It's complex and expensive, with a large It's simple and inexpensive with less number
number of instructions to process. of instructions to process.
46
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
1. Micro-USB Power Supply: A 5V micro USB typically powers the Raspberry Pi. But how
much current (in milliamps or amps) the Pi requires to function depends on your usage.
The recommended amount is between 700mA for a Raspberry Pi Model A, and up to 2.5A for
a Raspberry Pi 3 Model B.
The Raspberry Pi boards typically draw much lower amounts, between 200 and 500mA.
Usage depends on what you’re doing with the Pi. Playing video and browsing the web draws
more power than idling and booting. It also depends on what devices you have connected;
some keyboards and mice draw more power than others.
2. SD Card Slot: Secure Digital Card slot (SD Card) slot is a solid-state removable storage
device which is required to run operating systems on Raspberry Pi as Raspberry Pi doesn’t
have any onboard memory and data storage functionality. Raspberry Pi supports both SDHC
(Secure Digital High Capacity) and SDXC (Secure Digital eXtended Capacity). The best
suited card for proper running of all sorts of operating systems without any hiccup is Class
10 with speed @ 10MB/sec.
47
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
USB Port: The number and type of USB ports on Raspberry Pi depends on the model. The
Raspberry Pi Model B is equipped with two USB 2.0 ports; the B+, 2B, 3B and 3B+ have four
USB 2.0 ports. The Pi 4 has two USB 2.0 ports and two USB 3.0 ports.
In all models prior to the Pi 4, the USB ports connect to a combo hub/Ethernet chip, which is
itself a USB device connected to the single upstream USB port on BCM2835. On the Pi 4, the
USB hub chip is connected to the SoC using a PCIe bus. On the Model A and Zero range, the
single USB 2.0 port is directly wired to the SoC.
Ethernet Port: In order to enable Internet connection online and to update the software’s or to
install latest packages from online repositories, Raspberry Pi supports Ethernet Connection.
Raspberry Pi (Every Model) comprise of RJ45 Ethernet Jack which supports CAT5/6 cables. It
enables Raspberry Pi to be connected to Wireless Router, ADSL Model or any other Internet
connectivity sharing device.
The Pi Model B+, Pi 2, Pi 3 and Pi 4 features a 4-pole 3.5mm audio jack which also includes
the composite video signal. This has allowed for the removal of the composite video socket
found on the original Model B.
The new jack is a 4-pole socket which carries both audio and video signals. It’s similar to
sockets found on other multimedia devices such as iPods, MP3 players and smartphones. It
now used on the A+, B+, Pi 2, Pi 3 and Pi 4.
6. Status Led’s: Raspberry Pi comprise of 5 main LED’s performing the following functions:
48
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
I. ACT: (Color-Green): The main function of ACT LED is to show card status.
Normallyflashing during any SD Card activity performed by end user.
II. PWR: (Color-Red): The main function of PWR led is power. This led is continuously
ON when raspberry Pi is switched on and keep on till switched off.
III. FDX: (Color-Orange): The main function of FDX led is full duplex. This Led is
powered on when Ethernet connection is of Full Duplex type.
IV. LNK: (Color- Orange): The function performed by LNK led is Link. This LED is
powered on when Ethernet connection is established and packet transfer starts taking place.
V. 100: (Color-Orange): The 100 Led objective is to show 100 Mbps connection. When
any connection is established at Ethernet port, this LED only gets on when connection is of 100
Mbps speed and gets powered off when connection is at 10 Mbps.
7. GPIO (General Purpose Input Output): GPIO facilitates connecting all sorts of
peripheral devices to Raspberry Pi. Raspberry Pi has onboard GPIO with 40 pins, 26 of which
are used as digital inputs or outputs. More importantly, 9 of the 14 new GPIO pins are
dedicated inputs/outputs, it also facilitates the onboard UART, I2C, SPI Bus and still large
amount of free GPIO pins are there for add-on attachments.
49
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
Raspberry Pi 1 model B+
This model B+ is replaced in the place of raspberry pi model B in the year 2014. Model B+ Rpi
is compared with the model B it has.
More GPIO: The GPIO model B+ has 40 pins while retaining the same pinout for the first 26
pins as the Model A and B.
More USB: It has 4 USB 2.0 ports, compared to 2 on the Model B, and better hotplug and
overcurrent behavior.
Micro SD: The old friction-fit SD card socket has been replaced with a much nicer push-push
micro SD version.
Lower Power Consumption: In the low power consumption the linear regulators are replaced
by switching one and it will reduce the power consumption by between 0.5W and 1W.
Better Audio: The audio circuit has a dedicated low-noise power supply.
Neater Form Factor: With the broad edges the USB connections are arranged and the video is
moved composite with the 3.5mm jack. There are four squarely-placed maintaining holes.
Raspberry Pi Zero
It is a half size of the model A+ with twice a utility and for any project, it has the same
specification like 1GHz, Single-core CPU, 512MB RAM, Mini-HDMI port, Micro-USB OTG
port, Micro-USB power, HAT-compatible 40-pin header, Composite video and reset headers,
CSI camera connector (v1.3 only).
Raspberry Pi 2
The basic image of the raspberry pi 2 is following and the features of the raspberry pi 2
are it has quad-core ARM cortex-A7 processor with a 900MHz, the SDRAM is about the 1GB.
It is completely compatible with the raspberry pi 1.
50
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
Raspberry Pi Model B
It is a higher-spec variant of raspberry pi. After this design of this raspberry pi, it has extended
to the next model i.e raspberry pi 2. The specifications of the raspberry pi model B are
following, the raspberry pi model B has two USB ports, having a RAM of 512MB and its
Ethernet port is 100mb.
--- Cables :
You need either a micro HDMI to HDMI cable, or a standard HDMI to HDMI cable plus a
micro HDMI to HDMI adapter, to connect Raspberry Pi 4 to a screen. Raspberry Pi 1, 2, and 3
have a single full-size HDMI port, so you can connect them to a screen using a standard HDMI
to HDMI cable.
HDMI Cable
RASPBERRY PI ARDUINO
Raspberry Pi is a Single Board Arduino is a Microcontroller based development
Computer or SBC board
It is based on Broadcom SoC, an ARM It is based on Atmel Microcontrollers. Arduino UNO
Cortex A Series Microprocessor uses ATmega328P Microcontroller
A Debian based Linux Distribution
As it is a Microcontroller, there is no need for an
called Raspberry Pi OS is needed to
operating system
boot the Raspberry Pi
Raspberry Pi SBC can preform
multiple tasks simultaneously due to Arduino is usually used for running a single task (or a
its powerful processor and Linux based very small no. of simple tasks) repeatedly, over and
OS over again
All the necessary components like The Microcontroller on the Arduino Board (like
Processor, RAM, Storage, Connectors, ATmega328P) contains the Processor, RAM, ROM.
51
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
GPIO Pins, etc. are situated on the The board contains supporting hardware (for power
Raspberry Pi Board itself and data) and GPIO Pins
The cost of original Raspberry Pi SBC
was $35. Subsequently, all the base
The cost of original Arduino UNO is $23
variants of newer Raspberry Pi
versions are priced at $35 only
Arduino is developed as open-source hardware and
Both the hardware and firmware of
software from the beginning. You can easily get
Raspberry Pi are closed-source i.e., it
complete information on Arduino’s hardware and
is not available for general use
software
GPIO is an important peripheral of any
Raspberry Pi SBC has several GPIO
Microcontroller and Arduino UNO is no exception. In
Pins (the famous 40-pin Raspberry Pi
Arduino terminology, these pins are called Digital IO
GPIO), using which you can connect
(to connect LEDs and Buttons) and Analog IN (to
different sensors, IO Devices, etc.
connect analog devices)
Using the 40-pin GPIO Pins, you can
A similar way to add extra features and
add additional features / functionalities
functionalities in Arduino is using Arduino Shields
to Raspberry Pi with HAT (Hardware
(which are also connected through the IO Pins)
Attached on Top) expansion boards
As Raspberry Pi is essentially a
computer, you have to properly As Arduino is a Microcontroller board, you can plug
shutdown after using it or before and unplug the power as you want
powering it down
The main programming languages for
Arduino can be programmed using C or C++
developing application in Raspberry Pi
Programming Languages
are Python, Scratch, Ruby, C, C++
Arduino’s logic level is 5V. As most of the sensors
The logic level of Raspberry Pi’s and modules are designed for Arduino, there won’t be
GPIO is 3.3V. So, be careful when any problem connecting them to Arduino. But double
connecting hardware to the GPIO Pins check every module and connection just to be on the
safe side
Raspberry Pi must be powered using Arduino can be powered from a computer’s USB Port
an USB Power Adapter as it requires (make sure the USB Port’s current limit is not
5V 2A or 5V 3A power exceeded)
You can easily connect to internet For Arduino, you need additional module or shields
using Wi-Fi or Ethernet to connect to internet
52
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
Raspberry Pi has the hardware for There is no wireless connectivity in case of Arduino
Bluetooth and Wi-Fi on board (at least on board)
1. GO to the https://www.raspberrypi.org/downloads/
2. Click on NOOBS, then click on the Download ZIP button under ‘NOOBS (offlineand
network install)’, and select a folder to save it to.
3. Extract the files from the zip.
It is best to format your SD card before copying the NOOBS files onto it.
1. Once your SD card has been formatted, drag all the files in the extracted NOOBSfolder and
drop them onto the SD card drive.
2. The necessary necessary files will then be transferred transferred to your SD card.
53
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar
3. When this process has finished, safely remove the SD card and insert it into yourRaspberry
Pi.
FIRST BOOT
The default default login for Raspbian Raspbian is username username pi with the
password password raspberry raspberry. Note that you will not see any writing appear
when you type the password. This is a security feature in Linux. To load the graphical
user interface, type startx and press Enter.
54
Subject Code:3160716 Subject Name: IoT and Application Date:20-04-2021
Enrollment No: 150420107067 Name: Naseebullah Andar
Practical: 11
Problem: Implement a practical to detect the smoke using MQ-02 sensor & Arduino and
blow green and red light based on thresold value.
The ultrasonic sensor (or transducer) works on the same principles as a radar system. An
ultrasonic sensor can convert electrical energy into acoustic waves and vice versa. The
acoustic wave signal is an ultrasonic wave traveling at a frequency above 18kHz. The
famous HC SR04 ultrasonic sensor generates ultrasonic waves at 40kHz frequency.
55
Subject Code:3160716 Subject Name: IoT and Application Date:20-04-2021
Enrollment No: 150420107067 Name: Naseebullah Andar
56
Subject Code:3160716 Subject Name: IoT and Application Date:20-04-2021
Enrollment No: 150420107067 Name: Naseebullah Andar
Pin Wiring
The MQ-2 sensor has 4 pins.
Pin-------------------------------------Wiring to Arduino Uno
A0-------------------------------------Analog pins
D0-------------------------------------Digital pins
GND-----------------------------------GND
VCC------------------------------------5V
So, before jumping into the coding part, let's check whether we've assembled all the
necessary hardware components.
57
Subject Code:3160716 Subject Name: IoT and Application Date:20-04-2021
Enrollment No: 150420107067 Name: Naseebullah Andar
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
58
Subject Code:3160716 Subject Name: IoT and Application Date:20-04-2021
Enrollment No: 150420107067 Name: Naseebullah Andar
The output can be an analog signal (A0) that can be read with an analog input of the
Arduino or a digital output (D0) that can be read with a digital input of the Arduino.
59
Subject Code:3160716 Subject Name: IoT and Application Date:23-04-2021
Enrollment No: 150420107067 Name : Naseebullah Andar
Practical: 12
Problem: Perform LED blinking practical using Rasberry Pi and Python program.
60
Subject Code:3160716 Subject Name: IoT and Application Date:23-04-2021
Enrollment No: 150420107067 Name : Naseebullah Andar
61
Subject Code:3160716 Subject Name: IoT and Application Date:23-04-2021
Enrollment No: 150420107067 Name : Naseebullah Andar
Step 4: Output
62