Download as pdf or txt
Download as pdf or txt
You are on page 1of 65

Sarvajanik College of Engineering

and Technology
Department of Computer Engineering

Practical Submission

Department of Computer Engineering


BE III – Sem VI
Academic Year: 2020-21 (EVEN)
Subject: IoT and Applications (3160716)

Name : Naseebullah Andar


Enrollment No : 150420107067

(Institute/Department Seal)
CERTIFICATE

This is to certify that this submission contains practical work


carried out by Ms./Mr. ParmarNaseebullah AndarGajendrabhai.
Harshkumar
Enrollment No: 150420107067 of BE III, Sem VI of COMPUTER
ENGINEERING. He has satisfactorily completed his practical work in the
subject : IoT and Applications (3160716) during academic year 2020-
2021.

Date : 27/04/2021

Signature of Signature of Head


Subject Faculty of the Department
INDEX

Sr. No. Problem Statement Date Sign

1 Introduction to Arduino 15/12/2020

2 Use Arduino Uno Board to perform following practicals: 2.1 - 31/12/2020


LED Blink without serial command input. 2.2 - LED Blink
with with serial command input

3 Perform practical to detect obstacle using IR sensor and 29/12/2020


Arduino Uno.

4 Implement a IoT based practical using packet tracer - 12/2/2021


"Controlling of garage door and window for home environment
based on CO2 level"

5 Implement a IoT based practical using packet tracer - 19/2/2021


"Controlling of fan and light for home environment based on
motion"

6 Use Adafruit cloud to implement a practical by detecting 23/2/2021


obstacle with IR sensor module and NodeMCU.

7 Implement a practical to monitor Pulse rate with Arduino Uno 16/3/2021


board. (Serial Monitor Control)

8 Implement a practical to detect the obstacle and give the 23/3/2021


notification based distance using Ultrasonic Sensor HC-SR04
and Arduino.

9 Perform a practical to build NodeMCU Webserver and control 30/3/2021


an LED from a Webpage.

10 Study practical based on Raspberry Pi. 6/4/2021

11 Implement a practical to detect the smoke using MQ-02 sensor 20/4/2021


& Arduino and blow green and red light based on thresold
value.

12 Perform LED blinking practical using Rasberry Pi and 23/4/2021


Python program.
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020

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.

2) About Different Arduino boards

i) Arduino Uno (R3):

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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 (R3)

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.

ii) Arduino Nano:


This is a small board based on the microcontrollers like ATmega328P otherwise ATmega628
but the connection of this board is the same as to the Arduino UNO board. This kind of
microcontroller board is very small in size, sustainable, flexible, and reliable.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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.

iii) Arduino Micro:


The Arduino Micro board mainly depends on the ATmega32U4 based Microcontroller that
includes 20-sets of pins where the 7-pins are PWM pins, 12-analog input pins. This board
includes different components like an ICSP header, RST button, small USB connection, crystal
oscillator-16MHz. The USB connection is inbuilt and this board is the shrunk version of the
Leonardo board.

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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.

v) LilyPad Arduino Board:


The Lily Pad Arduino board is a wearable e-textile technology expanded by Leah “ Buechley”
and considerately designed by “Leah and SparkFun”. Each board was imaginatively designed
with huge connecting pads & a smooth back to let them to be sewn into clothing using
conductive thread. This Arduino also comprises of I/O, power, and also sensor boards which
are built especially for e-textiles. These are even washable.

LilyPad Arduino Boards

vi) Arduino Bluetooth:


This Bluetooth mainly depends on the microcontroller like ATmega168 and this board is
also called Arduino BT. This kind of board includes different components like digital pins-
16, analog pins-6, crystal oscillator-16MHz, reset button, screw terminals, ICSP header. In

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

5
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020

RedBoard Arduino Boards

ix) Arduino Mega (R3) Board:


The Arduino Mega is similar to the UNO’s big brother. It includes lots of digital I/O pins (from
that, 14-pins can be used as PWM o/ps), 6-analog inputs, a reset button, a power jack, a USB
connection, and a reset button. 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. The huge number of pins make this Arduino board very helpful
for designing projects that need a bunch of digital i/ps or o/ps like lots of buttons.

Arduino Mega (R3) Board

x) Arduino Leonardo Board:


The first development board of an Arduino is the Leonardo board. This board uses one
microcontroller along with the USB. That means, it can be very simple and cheap also. Because
this board handles USB directly, program libraries are obtainable which let the Arduino board
to follow a keyboard of the computer, mouse, etc.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

6
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020

Arduino Leonardo Board

xi) Arduino Robot:


This kind of board is the first Arduino over wheels. This Arduino robot includes two processors
on each of its boards. The two boards are the motor board and control board where the motor
board controls the motors & the control board is used to read the sensors for operating. Every
board is a complete Arduino board and its programming can be done through the Arduino IDE.
These are microcontroller boards that depend on the ATmega32u4.

xii) Arduino Esplora:


The Arduino Esplora includes a small computer known as a microcontroller including a
number of inputs & outputs. The inputs of this board are a light sensor, four buttons, a
microphone, an accelerometer, joystick, a slider, a temperature sensor, etc whereas the outputs
are a 3 color LED, a buzzer. This kind of Arduino board looks like a videogame controller.

Arduino Esplora

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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.

3) Arduino Pin diagram and explanation:

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

9
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020

GND:
GND (ground) pins

Memory:

The memory of an ATmega328 microcontroller includes 32 KB and 0.5 KB memory is utilized


for the Boot loader), and also it includes SRAM-2 KB as well as EEPROM-1KB.

Input and Output:

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.

External Interrupt Pins:

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 ().

SPI (Serial Peripheral Interface) Pins:

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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.

TWI (2-Wire Interface) Pins:

The TWI pins are SDA or A4, & SCL or A5, which can support the communication of TWI
with the help of Wire library.

AREF (Analog Reference) Pin:

An analog reference pin is the reference voltage to the inputs of an analog i/ps using the
function like analog Reference().

Reset (RST) Pin:

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:

The SPI communication includes MOSI, MISO, and SCK.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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 :

Here Architecture is of Arduino or precisely the IC of Arduino (ATmega328p).

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

12
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 15/12/2020

The basic working of CPU of ATmega328:-

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.

7. Watchdog timer is used to detect and recover from MCU malfunctioning.

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

14
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 24/12/2020

Practical No:2

Problem Statement : Use Arduino Uno Board to perform below practicals:


2.1 - LED Blink without serial command input.
2.2 - LED Blink with serial command input.

➢ 2.1 - LED Blink without serial command input.

Wiring Diagram:

Sketch:

//serial data rate in bps


#define BAUD 9600 void blink(int msec =
1000) { digitalWrite(LED_BUILTIN, HIGH);
delay(msec);
digitalWrite(LED_BUILTIN, LOW);
delay(msec); }

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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);
}

void loop() { blink();


}

Output:

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

16
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 24/12/2020

➢ 2.2 - LED Blink with serial command input.

Wiring Diagram:

Sketch:

//serial data rate in bps


#define BAUD 9600 char
command;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(BAUD);
}

void loop() {
Serial.println("Type a Command: (h | l | H | L)");
while(Serial.available() == 0); delay(10);
command = Serial.read();
Serial.print("Command: ");

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

17
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 24/12/2020

Serial.println(command); if(command == 'l' ||


command == 'L')
digitalWrite(LED_BUILTIN, LOW); else
if(command == 'h' || command == 'H')
digitalWrite(LED_BUILTIN, HIGH); else
Serial.println("Wrong Command!");
}

Output:

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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:

- Connect the LED on Pin 13 (big leg) in Arduino Uno.


- Connect the other leg (small) on GND pin in Arduino Uno.
- Connect Arduino to Laptop or PC to give power supply.- Write down code(sketch) in
Arduino IDE - Compile the sketch.
- Upload the sketch in memory of Arduino Uno.
- Bring some object near the IR sensor.
- Check the Output in serial monitor as well as on Arduino board.

Circuit Diagram:

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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.

int IRSensor = 2; // connect ir sensor to Arduino pin 2

int LED = 13; // connect Led to Arduino pin 13

int isObstacle = HIGH; // HIGH MEANS NO OBSTACLE

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);
}

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

20
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 29/12/2020

Output:

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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 the connection to PC,window,garage Door,carbon dioxide detector, server with


switch

➢ Give ip address and subnet mask to compontants which is connected with switch

SCET/CO/2020-21/EVEN/BE SHIFT-I/SEM-VI Page No:

22
Subject Code: 3160716 Subject: IOT & It’s Applications Date:17/02/2021
Enrollment No:150420107067 Name: Naseebullah Andar

SCET/CO/2020-21/EVEN/BE SHIFT-I/SEM-VI Page No:

23
Subject Code: 3160716 Subject: IOT & It’s Applications Date:17/02/2021
Enrollment No:150420107067 Name: Naseebullah Andar

➢ Go to services IOT and registration server on

➢ Go to desktop and web browser


➢ Go to registration server login in using details and we can see garage ,windows and alarm
are connected together

SCET/CO/2020-21/EVEN/BE SHIFT-I/SEM-VI Page No:

24
Subject Code: 3160716 Subject: IOT & It’s Applications Date:17/02/2021
Enrollment No:150420107067 Name: Naseebullah Andar

➢ Give condition as per shown in figure

➢ According to condition if the co2 level goes up to 0.5 then garage door and windows will
opened

Output:

SCET/CO/2020-21/EVEN/BE SHIFT-I/SEM-VI Page No:

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:

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page no:

26
Subject Code:3160716 Subject: Advance java Programming Date:25/02/2021
Enrollment No: 150420107067 Name: Naseebullah Andar

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page no:

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 :

• Create account on adafruit web-site. (https://io.adafruit.com/)


• We can see the key of your account from my key tab or you can regenerate key also.
• Create a new feed from feed tab by inserting name and Description of feed.
• Create a new dashboard from dashboard tab by inserting name and Description of
dashboard.
• We are going to use MQTT protocol as MQTT publisher.
• Then download library from github.(Adafruit_MQTT_Client.h,ESP8266WiFi.h) •
Save this libraries in C:\Program Files (x86)\Arduino\libraries.
• Then include the libraries from sketch\include library\Add .zip library .
• Select the NodeMCU1.0 board and port from tools.
• Connect the circuit.
• Write the proper code, compile and upload in the Board.
• See the output on serial monitor and adafruit feed.

Program:

#include <ESP8266WiFi.h> // Header file for NODEMCU


#include <Adafruit_MQTT_Client.h> // For MQTT with adafruit
#define wifi "Enigma" // Name of the wifi hotspot
#define password "12345678" // password for the wifi access
#define server "io.adafruit.com" // where we store the data , adafruit act as a
broker

#define port 1883 // commonly used port number


#define username "Kalpesh Gohil" // username to login to adafruit
#define key "aio_gUnB253GU7OhXH9tc8EpHWueUeeB" // AIO key for adafruit login

WiFiClient esp; // An instance

int IRSensor = D2; // connect ir sensor to arduino pin 2 int LED


= 13; // connect Led to arduino pin 13
int isObstacle = HIGH; // HIGH MEANS NO OBSTACLE

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()
{

Serial.begin(9600); // Baudrate delay(10);


Serial.println("Adafruit MQTT demo");
Serial.println("Connecting to ");
Serial.println(wifi);

WiFi.begin(wifi,password);

while(WiFi.status()!=WL_CONNECTED)
{ delay(500);
Serial.print(".");
}

pinMode (IRSensor, INPUT); // sensor pin INPUT


pinMode (LED, OUTPUT); // Led pin OUTPUT

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:

1. we required one Arduino board and a Pulse sensor

2. The pause sensor has three outgoing wires for connection:


Black wire to connect for voltage
White wire for connection to ground
Brown wire for control

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()
{

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:


32
Subject Code: 3160716 Subject: IOT & It’s Applications
Enrollment No: 150420107067 Name: Naseebullah Andar Date: 16/03/2021

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:

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:


33
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 23/03/2021
Enrollment No: 150420107067 Name: Naseebullah Andar

Practical No: 8

Implement a practical to detect the obstacle and give the notification based distance
using Ultrasonic Sensor HC-SR04 and Arduino.

Steps:

1. we required one Arduino Uno board and Ultrasonic sound sensor.

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.

Connect the pin labeled "trigger" to pin 9 on the Arduino


Connect the pin labeled "echo" to pin 10 on the Arduino
Connect the Ultrasonic Sensor's 5V pin to the 5V pin on the Arduino

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

34
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 23/03/2021
Enrollment No: 150420107067 Name: Naseebullah Andar

Program:

const int trigger = 9; const


int echo = 10;

// 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);
}

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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);

// Calculating the distance distance=


duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance); }
Output:

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI Page No:

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

➢ ESP8266 NodeMCU , LED, 250 ohm Resistor , Breadboard , Jumper Wires

STEP 2 – PINOUT DETAILS

NodeMCU is an open-source Lua based firmware and development


board specially targeted for IoT based Applications. It includes firmware that runs on the
ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-1
module.

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

NodeMCU Development Board Pinout Configuration

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

STEP 3 – PIN CONNECTION

STEP 4 – SAMPLE SOURCE CODE

#include <ESP8266WiFi.h>

const char* ssid = "Tushar"; // Your Wi-Fi Name

const char* password = "12345678"; // Wi-Fi Password

int LED = 2; // led connected to GPIO2 (D4)

WiFiServer server(80);

void setup()

Serial.begin(115200); //Default Baudrate

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

Serial.print("Connecting to the Newtork");

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED)

delay(500);

Serial.print(".");

Serial.println("WiFi connected");

server.begin(); // Starts the Server

Serial.println("Server started");

Serial.print("IP Address of network: "); // will IP address on Serial Monitor

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()

WiFiClient client = server.available();

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

Serial.println("Waiting for new client");

while(!client.available())

delay(1);

String request = client.readStringUntil('\r');

Serial.println(request);

client.flush();

int value = LOW;

if(request.indexOf("/LED=ON") != -1)

digitalWrite(LED, HIGH); // Turn LED ON

value = HIGH;

if(request.indexOf("/LED=OFF") != -1)

digitalWrite(LED, LOW); // Turn LED OFF

value = LOW;

//*------------------HTML Page Code---------------------*//

client.println("HTTP/1.1 200 OK"); //

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

STEP 5 – SERIAL MONITOR RESULT

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

Study practical based on Raspberry Pi:

--- Introduction:

➢ Raspberry Pi is a small single board computer. By connecting peripherals like


Keyboard, mouse, display to the Raspberry Pi, it will act as a mini personal computer.
➢ Raspberry Pi is popularly used for real time Image/Video Processing, IoT based
applications and Robotics applications.
➢ Raspberry Pi is slower than laptop or desktop but is still a computer which can provide
all the expected features or abilities, at a low power consumption.
➢ Raspberry Pi Foundation officially provides Debian based Raspbian OS. Also, they
provide NOOBS OS for Raspberry Pi. We can install several Third-Party versions of OS
like Ubuntu, Archlinux, RISC OS, Windows 10 IOT Core, etc.
➢ Raspbian OS is official Operating System available for free to use. This OS is efficiently
optimized to use with Raspberry Pi. Raspbian have GUI which includes tools for
Browsing, Python programming, office, games, etc.
➢ We should use SD card (minimum 8 GB recommended) to store the OS (operating
System).
➢ Raspberry Pi is more than computer as it provides access to the on-chip hardware
i.e. GPIOs for developing an application. By accessing GPIO, we can connect devices
like LED, motors, sensors, etc and can control them too.
➢ It has ARM based Broadcom Processor SoC along with on-chip GPU (Graphics
Processing Unit).
➢ The CPU speed of Raspberry Pi varies from 700 MHz to 1.2 GHz. Also, it has onboard
SDRAM that ranges from 256 MB to 1 GB.
➢ Raspberry Pi also provides on-chip SPI, I2C, I2S and UART modules.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page No:

44
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar

--- Comparison between micro-controller and micro-processor :

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page No:

45
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar

It is used mainly in a washing machine, MP3


It is mainly used in personal computers. players, and embedded systems.

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 is a byproduct of the development of


It is a central processing unit on a single microprocessors with a CPU along with
silicon based integrated chip. other peripherals.

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 uses an external bus to interface to RAM, It uses an internal controlling bus.


ROM, and other peripherals.

Microprocessor-based systems can run at a Microcontroller based systems run up to


very high speed because of the technology 200MHz or more depending on the
involved. architecture.

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page No:

46
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar

--- About board components and pins:

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page No:

47
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar

3. USB Ports & Ethernet Port:

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.

4. HDMI (High Definition Multimedia Interface): HDMI Port enables Raspberry Pi to be


connected to HDTV via HDMI cable. Raspberry Pi supports maximum resolution of
1920x1200. With the help of HDMI Full HD MPEG-4 can be streamed via HDMI.

5. Video Out (RCA Cable): In addition to HDMI Connectivity which facilitates HD


connection, Raspberry Pi also has provision to be connected to standard monitor or TV using
RCA video cable. RCA cable is less expensive as compared to HDMI but along with RCA
cable, the user has to buy 3.5mm stereo cable for audio facilitation.

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:

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page No:

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.

8. CSI Camera Connector: Raspberry Pi has a Mobile Industry Processor Interface


(MIPI) Camera Serial Interface Type 2 (CSI-2). CSI-2 facilitates connection of small camera to
Broadcom BCM 2835 processor. The function of this interface is to standardize the attachment
of camera modules to the processors for the mobile phone industry. MIPI CSI-2 version 1.01
supports upto 4 data lanes, and each lane carries 1 Gbps bandwidth. The D- PHY specification
defines the physical hardware layer interface between camera and processor to facilitate fast
exchange of data.

9. System On Chip (SoC): Raspberry Pi (System on Chip) SoC is ARM Based by


Broadcom Technologies. The ARM processor runs from 700 Mhz to 1 Ghz. The SoC also
facilitates videocore 4 GPU, and is capable for fast 3D core, openGL and supports Blueray and
H.264 video playback.

➢ A powerful feature of the Raspberry Pi is the row of GPIO(general-purpose input/


output) pins along the top edge of the board. A 40-pin GPIO header is found on all
current Raspberry Pi boards (unpopulated on Pi Zero and Pi Zero W). Prior to the Pi 1
Model B+ (2014), boards comprised a shorter 26-pin header.
--- Different version of boards and its features :

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page No:

49
Subject Code: 3160716 Subject: IOT & It’s Applications Date: 06/04/2021
Enrollment No: 150420107067 Name: Naseebullah Andar

The different types of raspberry pi models are following


•Raspberry Pi 1 model B
•Raspberry Pi 1 model A
•Raspberry Pi 1 model B+
•Raspberry Pi 1model A+
•Raspberry Pi Zero
•Raspberry Pi 2
•Raspberry Pi 3 model B
•Raspberry Pi Zero W

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page No:

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

--- Comparison between Arduino and Raspberry Pi:

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page No:

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

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page No:

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)

--- Installation of Raspberry Pi OS :

• To get started with Raspberry Pi, you need an operating system.


• NOOBS (New Out Of Box Software) is an easy operating system install manager for the
Raspberry Pi.

HOW TO GET AND INSTALL INSTALL NOOBS

– DOWNLOAD NOOBS OS FROM (We recommend using an SD card with a minimum


capacity of 8GB.)

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.

FORMAT YOUR SD CARD

It is best to format your SD card before copying the NOOBS files onto it.

To do this: 1. Download SD Formatter 4.0 for either Windows or Mac.


2. Follow the instructions to install the software.
3. Insert your SD card into the computer or laptop’s SD card reader and make a note ofthe
drive letter allocated to it, e.g. G:/
4. In SD Formatter, select the drive letter for your SD card and format it.

DRAG AND DROP NOOBS FILES

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page No:

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

1. Plug in your keyboard, mouse, and monitor cables.


2. Now plug the USB power cable into your Pi.
3. Your Raspberry Pi will boot, and a window will appear with a list of differentoperating
systems that you can install. We recommend that you use Raspbian – tick the box next to
Raspbian and click on Install.
4. Raspbian will then run through its installation process. Note that this can take awhile.
5. When the install process has completed, the Raspberry Pi configuration menu(raspiconfig)
will load. Here you are able to set the time and date for your region, enable a Raspberry Pi
camera board, or even create users. You can exit this menu by using Tab on your keyboard
to move to Finish.

LOGGING IN AND ACCESSING THE GRAPHICAL USER INTERFACE

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.

SCET/CO/2020-21/EVEN/BE Shift-I/Sem-VI page No:

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.

Step 1: Material Preparation and working principle of Ultrasonic Sensor HC-SR04

Figure : HC SR04 ultrasonic sensor. (Source: Digikey)

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.

Typically, a microcontroller is used for communication with an ultrasonic sensor. To


begin measuring the distance, the microcontroller sends a trigger signal to the ultrasonic
sensor. The duty cycle of this trigger signal is 10µS for the HC-SR04 ultrasonic sensor.
When triggered, the ultrasonic sensor generates eight acoustic (ultrasonic) wave bursts
and initiates a time counter. As soon as the reflected (echo) signal is received, the timer
stops. The output of the ultrasonic sensor is a high pulse with the same duration as the
time difference between transmitted ultrasonic bursts and the received echo signal.

SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI page no:

55
Subject Code:3160716 Subject Name: IoT and Application Date:20-04-2021
Enrollment No: 150420107067 Name: Naseebullah Andar

Step 2: Pinout Details

(Sensor Pin – Out detail)

SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI page no:

56
Subject Code:3160716 Subject Name: IoT and Application Date:20-04-2021
Enrollment No: 150420107067 Name: Naseebullah Andar

Step 3: Pin Connection

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.

SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI page no:

57
Subject Code:3160716 Subject Name: IoT and Application Date:20-04-2021
Enrollment No: 150420107067 Name: Naseebullah Andar

Step 4: Sample Source Code

int redLed = 12;


int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
// Your threshold value
int sensorThres = 400;

void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}

void loop() {
int analogSensor = analogRead(smokeA0);

Serial.print("Pin A0: ");


Serial.println(analogSensor);
// Checks if it has reached the threshold value
if (analogSensor > sensorThres)
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000, 200);
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(100);
}

SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI page no:

58
Subject Code:3160716 Subject Name: IoT and Application Date:20-04-2021
Enrollment No: 150420107067 Name: Naseebullah Andar

Step 5: Serial Monitor Result

• The greaterthe gas concentration,the greaterthe output voltage


• The lowerthe gas concentration,the lowerthe output voltage

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.

SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI page no:

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.

Step 1: Components Required

Raspberry Pi 3 setup with monitor and USB Mouse & Keyboard


Checkout this guide if you need help
Solderless breadboard
Jumper wires for easy hookup
Resistor pack
Red LED
Multimeter (optional)

Step 2: Pin Connection (Circuit)

SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI page no:

60
Subject Code:3160716 Subject Name: IoT and Application Date:23-04-2021
Enrollment No: 150420107067 Name : Naseebullah Andar

Step 3: Sample Source Code (Python Program)

import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library


from time import sleep # Import the sleep function from the time module

GPIO.setmode(GPIO.BOARD) # Use physical pin numbering


GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW) # Set pin 8 to be an output pin and set
initial value to low (off)

while True: # Run forever


GPIO.output(8, GPIO.HIGH) # Turn on
sleep(1) # Sleep for 1 second
GPIO.output(8, GPIO.LOW) # Turn off
sleep(1) # Sleep for 1 second

SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI page no:

61
Subject Code:3160716 Subject Name: IoT and Application Date:23-04-2021
Enrollment No: 150420107067 Name : Naseebullah Andar

Step 4: Output

SCET/CO/2020-21/Even/BE-III Shift-I/Sem-VI page no:

62

You might also like