Professional Documents
Culture Documents
Practical: 1
Aim: Define IoT and enlist application areas related to IoT.
• IoT: The Internet of Things (IoT) describes the network of physical objects -“things”
- that are embedded with sensors, software, and other technologies for the purpose of
connecting and exchanging data with other devices and systems over the internet.
• Alternative definition of IoT:
• The Internet of Things, or IoT, refers to the billions of physical devices around the
world that are now connected to the internet, all collecting and sharing data.
• The internet of things, or IoT, is a system of interrelated computing devices,
mechanical and digital machines, objects, animals or people that are provided with
unique identifiers (UIDs) and the ability to transfer data over a network without
requiring human-to-human or human-to-computer interaction.
• Applications area related to IoT: The applications of IoT technologies are multiple,
because it is adjustable to almost any technology that is capable of providing relevant
information about its own operation, about the performance of an activity and even
about the environmental conditions that we need to monitor and control at a distance.
• Nowadays, many companies from different sectors are adopting this technology to
simplify, improve, automate and control different processes.
• Various applications related to IoT are:
• Wearables.
• Health.
• Traffic Monitoring.
• Agriculture.
• Hospitality.
• Smart grid and Energy Saving.
• Water supply.
• Maintenance management, etc.
• Wearables: Virtual glasses, fitness bands to monitor for example calorie expenditure
and heart beats, or GPS tracking belts, are just some examples
of wearable devices that we have been using for some time now. Companies such as
Google, Apple, Samsung and others have developed and introduced the Internet of
Things and the application thereof into our daily lives.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
• These are small and energy efficient devices, which are equipped with sensors, with
the necessary hardware for measurements and readings, and with software to collect
and organize data and information about users.
• Health: The use of wearables or sensors connected to patients, allows doctors to
monitor a patient's condition outside the hospital and in real-time. Through
continuously monitoring certain metrics and automatic alerts on their vital signs, the
Internet of Things helps to improve the care for patients and the prevention of lethal
events in high-risk patients.
• Another use is the integration of IoT technology into hospital beds, giving way to
smart beds, equipped with special sensors to observe vital signs, blood pressure,
oximeter and body temperature, among others.
• Traffic monitoring: The Internet of things can be very useful in the management of
vehicular traffic in large cities, contributing to the concept of smart cities.
• When we use our mobile phones as sensors, which collect and share data from our
vehicles through applications such as Waze or Google Maps, we are using the Internet
of Things to inform us and at the same time contribute to traffic monitoring, showing
the conditions of the different routes, and feeding and improving the information on
the different routes to the same destination, distance, estimated time of arrival.
• Agriculture: Smart farms are a fact. The quality of soil is crucial to produce good
crops, and the Internet of Things offers farmers the possibility to access detailed
knowledge and valuable information of their soil condition.
• Information such as soil moisture, level of acidity, the presence of certain nutrients,
temperature and many other chemical characteristics, helps farmers control irrigation,
make water use more efficient, specify the best times to start sowing, and even
discover the presence of diseases in plants and soil.
• Hospitality: The application of the IoT to the hotel industry brings with it interesting
improvements in the quality of the service. With the implementation of electronic
keys, which are sent directly to the mobile devices of each guest, it is possible to
automate various interactions.
• Thus, the location of the guests, the sending of offers or information on activities of
interest, the realization of orders to the room or room service , the automatic charge of
accounts to the room or the request of personal hygiene supplies, are activities that
can be easily managed through integrated applications using the Internet of Things
technology.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Practical: 2
Aim: Study about Arduino Uno.
Overview:
Arduino Uno is a microcontroller board based on 8-bit ATmega328P
microcontroller. Along with ATmega328P, it consists other components such as
crystal oscillator, serial communication, voltage regulator, etc. to support the
microcontroller.
Arduino Uno has 14 digital input/output pins (out of which 6 can be used as PWM
outputs), 6 analog input pins, a USB connection, A Power barrel jack, an ICSP header
and a reset button.
Arduino Uno Pin Description:
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Pin Description:
Pin Pin Name Details
Category
Power Vin, 3.3V, 5V, Vin: Input voltage to Arduino when using an external power source.
GND 5V: Regulated power supply used to power microcontroller and
other components on the board.
3.3V: 3.3V supply generated by on-board voltage regulator.
Maximum current draw is 50mA.
GND: ground pins.
Reset Reset Resets the microcontroller.
Analog Pins A0 – A5 Used to provide analog input in the range of 0-5V
Input/Output Digital Pins 0 - Can be used as input or output pins.
Pins 13
Serial 0(Rx), 1(Tx) Used to receive and transmit TTL serial data.
External 2, 3 To trigger an interrupt.
Interrupts
PWM 3, 5, 6, 9, 11 Provides 8-bit PWM output.
SPI 10 (SS), 11 Used for SPI communication.
(MOSI), 12
(MISO) and 13
(SCK)
Inbuilt LED 13 To turn on the inbuilt LED.
TWI A4 (SDA), A5 Used for TWI communication.
(SCA)
AREF AREF To provide reference voltage for input voltage.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
The 14 digital input/output pins can be used as input or output pins by using pinMode(),
digitalRead() and digitalWrite() functions in arduino programming. Each pin operate at 5V
and can provide or receive a maximum of 40mA current, and has an internal pull-up resistor
of 20-50 KOhms which are disconnected by default. Out of these 14 pins, some pins have
specific functions as listed below:
Serial Pins 0 (Rx) and 1 (Tx): Rx and Tx pins are used to receive and transmit TTL
serial data. They are connected with the corresponding ATmega328P USB to TTL
serial chip.
External Interrupt Pins 2 and 3: These pins can be configured to trigger an interrupt
on a low value, a rising or falling edge, or a change in value.
PWM Pins 3, 5, 6, 9 and 11: These pins provide an 8-bit PWM output by using
analogWrite() function.
SPI Pins 10 (SS), 11 (MOSI), 12 (MISO) and 13 (SCK): These pins are used for
SPI communication.
In-built LED Pin 13: This pin is connected with an built-in LED, when pin 13 is
HIGH – LED is on and when pin 13 is LOW, its off.
Along with 14 Digital pins, there are 6 analog input pins, each of which provide 10 bits of
resolution, i.e. 1024 different values. They measure from 0 to 5 volts but this limit can be
increased by using AREF pin with analog Reference() function.
Analog pin 4 (SDA) and pin 5 (SCA) also used for TWI communication using Wire
library.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Communication
When ATmega328 chip is used in place of Arduino Uno, or vice versa, the image below
shows the pin mapping between the two.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Software
Arduino IDE (Integrated Development Environment) is required to program the Arduino Uno
board.
Programming Arduino
Once arduino IDE is installed on the computer, connect the board with computer
using USB cable.
Now open the arduino IDE and choose the correct board by selecting
Tools>Boards>Arduino/Genuino Uno, and choose the correct Port by selecting
Tools>Port.
Arduino Uno is programmed using Arduino programming language based on Wiring.
To get it started with Arduino Uno board and blink the built-in LED, load the example
code by selecting Files>Examples>Basics>Blink.
Once the example code (also shown below) is loaded into your IDE, click on the
‘upload’ button given on the top bar.
Once the upload is finished, you should see the Arduino’s built-in LED blinking.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
In the above example loop ( ) function is a part of execution block. As the name
suggests, the loop( ) function executes the set of statements (enclosed in curly braces)
repeatedly.
Void loop ( )
{
digitalWrite (pin-number,HIGH); // turns ON the component
connected to ‘pin-number’
delay (1000); // wait for 1 sec
digitalWrite (pin-number, LOW); // turns OFF the component
connected to ‘pin-number’
delay (1000); //wait for 1sec
}
Note: Arduino always measures the time duration in millisecond. Therefore,
whenever you mention the delay, keep it in milli seconds.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Practical: 3
Aim: Using Arduino Uno implement blinking the LED experiment.
Overview: In the process of experimenting with Arduino, writing the Arduino program is not
the only important thing, building the breadboard circuit is equally important.
Let’s take a look at how the breadboard circuit has to be built for both the
experiments.
Components required:
Arduino UNO R3 -1
Breadboard -1
Breadboard connectors -3
LED -1
1K resistor -1
Blinking LED
Steps in building a breadboard connection:
Step-1: Connect the Arduino to the Windows / Mac / Linux system via a
USB cable
Step-2: Connect the 13th digital pin of Arduino to the positive power rail of
the breadboard and GND to the negative
Step-3: Connect the positive power rail to the terminal strip via a 1K ohm
resistor
Step-4: Fix the LED to the ports below the resistor connection in the
terminal strip
Step-5: Close the circuit by connecting the cathode (the short chord) of the
LED to the negative power strip of the breadboard
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
int LED =13; // The digital pin to which the LED is connected
void setup ( )
{
pinMode (LED, OUTPUT); //Declaring pin 13 as output pin
}
void loop( ) // The loop function runs again and again
{
digitalWrite (LED, HIGH); //Turn ON the LED
delay(1000); //Wait for 1sec
digitalRead (LED, LOW); // Turn off the LED
delay(1000); // Wait for 1sec
}
Arduino program for LED blink (Version-2)
void setup ( )
{
pinMode (13, OUTPUT); //pin 13 is set as output pin
}
void loop( ) // The loop function runs again and again
{
digitalWrite (13,HIGH); // Turn ON the LED on pin 13
delay (1000); //Wait for 1sec
digitalWrite (13, LOW); //Turn OFF the LED on pin 13
}
In version-1 of the LED blink program LED is declared globally and is set to pin
number 13. This will reduce the number of iterations required to update the pin
number in the program when you connect the LED to the other digital pin.
Whereas, the pin number has to be changed in 3 different statements in version-2.
The magic happens when you click the upload icon in the Arduino IDE. The program
will be uploaded into the microcontroller of Arduino board and LED in the circuit
starts blinking.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Practical: 4
Aim: Using Arduino Uno implement the Fade-in and fade-out the LED experiment.
Overview: In the process of experimenting with Arduino, writing the Arduino program is not
the only important thing, building the breadboard circuit is equally important.
Let’s take a look at how the breadboard circuit has to be built for both the
experiments.
Components required:
Arduino UNO R3 -1
Breadboard -1
Breadboard connectors -3
LED -1
1K resistor -1
Fade-in and Fade-out LED
Steps in building a breadboard connection:
Step-1: Connect the Arduino to the Windows / Mac / Linux system via a
USB cable
Step-2: Connect the 9th digital pin of Arduino to the positive power rail of
the breadboard and GND to the negative
Step-3: Connect the positive power rail to the terminal strip via a 1K ohm
resistor
Step-4: Fix the LED to the ports below the resistor connection in the
terminal strip
Step-5: Close the circuit by connecting the cathode (the short chord) of the
LED to the negative power strip of the breadboard
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
In both the versions of the LED fade-in and fade-out programs, the analogWrite
statement is used for a led connected to a digital pin. The reason for this is that, digital
pin 10 is a PWM pin.
A PWM pin is capable of generating Analog output. In both the programs pin 10 is
used as analog output pin.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Practical: 5
Example 1: Declaring an Array and using a Loop to Initialize the Array’s Elements.
Overview: The program declares a 10-element integer array n. Lines a–b use a for statement
to initialize the array elements to zeros. Like other automatic variables, automatic arrays are
not implicitly initialized to zero. The first output statement (line c) displays the column
headings for the columns printed in the subsequent for statement (lines d–e), which prints the
array in tabular format.
Code:
void setup ()
void loop ()
Serial.print (i);
Serial.print (‘\r’);
for ( int j = 0; j < 10; ++j ) // output each array element's value
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Serial.print (n[j]);
Serial.print (‘\r’);
Output:
Element Value
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Overview: The elements of an array can also be initialized in the array declaration by
following the array name with an equal-to sign and a brace-delimited comma-separated list of
initializers. The program uses an initializer list to initialize an integer array with 10 values
(line a) and prints the array in tabular format (lines b–c).
Code:
// n is an array of 10 integers
int n[ 10 ] = { 32, 27, 64, 18, 95, 14, 90, 70, 60, 37 }
void setup ()
void loop ()
Serial.print (i);
Serial.print (‘\r’);
for ( int j = 0; j < 10; ++j ) // output each array element's value
Serial.print (n[j]);
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Serial.print (‘\r’);
Output:
Element Value
0 32
1 27
2 64
3 18
4 95
5 14
6 90
7 70
8 60
9 37
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Code:
int a[ arraySize ] = { 87, 68, 94, 100, 83, 78, 85, 91, 76, 87 };
int total = 0;
void setup ()
void loop ()
total += a[ i ];
Serial.print(total) ;
Output:
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Serial.println(num);
num = sizeof(out_str);
Serial.print("Size of the array out_str[]: ");
Serial.println(num);
}
void loop()
{
}
Output:
This is my string
String length is: 17
Size of the array: 18
This is my string
This is my string sketch.
String length is: 25
Size of the array out_str[]: 40
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Practical: 7
Aim: Write a program to create a function that determines a number is even or odd.
Code:
int a= 0;
int b;
void setup()
{
Serial.begin(9600);
}
void loop()
{
b = Evenfunction(a); // we can store the function return value in variable b
Serial.print(a);
Serial.print(" : "); // to separate even or odd text
if (b==1)
{
Serial.println( " Number is even");
}
else
{
Serial.println("Number is odd");
}
a++; // the function will increment and will again run
delay(1000);
}
int Evenfunction(int d)
{
if (d% 2==0)
{
return 1;
}
else
{
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
return 0;
}
}
Output:
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Practical: 8
Aim: Write a program to implement blinking multiple LEDs using the loop.
Hardware Required:
3 x red LED
3 x 220 Ohm Resistors
Arduino UNO R3 board
Jump wires
Principle:
We will connect the three LEDs to pins 13, 8, and 4 of the Arduino board. The
limiting value of resistance should be between 220 and 330 ohms to set the optimal
current through the LEDs.
The required resistance is enough to light up an LED without damaging the board and
the LED. We will turn the LED ON/OFF individually.
Procedure:
Connect the resistor of 220 Ohm in series with the three LEDs. Now connect it to
the pin number 13, 8, and 4 of the Arduino board.
Connect the negative terminal of the three LEDs to the GND (Ground).
Connection Diagram:
We will show the connection using the Simulator because the connections become
clearer and more precise.
We can make the same connection using the hardware devices.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Code:
/*
This program blinks LED connection to the pin number 13, 8, and 4
*/
void setup()
{
pinMode(13, OUTPUT);
pinMode(8, OUTPUT);
pinMode(4, OUTPUT);
}
void loop()
{
// the first LED is made to blink one time
digitalWrite(13, HIGH);
delay(1000); // delay time in milliseconds
digitalWrite(13, LOW);
delay(1000);
// the second LED will blink two times
digitalWrite(8, HIGH);
delay(500); // the duration is 0.5 seconds
digitalWrite(8, LOW);
delay(500);
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(500);
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Practical: 9
Aim: Write a program to implement blinking multiple LEDs using switch case.
Hardware Required:
The components required for the project are listed below:
4 x red LED
4 x 220 Ohm Resistors
Arduino UNO R3 board
Jump wires
Principle:
We will connect the four LEDs to pins 12, 11, 8, and 6 of the Arduino board. The
resistors of 220 Ohm are connected in series with the LEDs.
The switch statement will compare the declared value of a variable with statements in
other cases. The code associated with the matching case will run.
We will also change or rearrange the LEDs connected to the specified pin number on
the board.
Connection:
Connect the resistor of 220 Ohm in series with the four LEDs. Now connect it to the
pin number 12, 11, 8, and 6 of the Arduino board.
Connect the negative terminal of the five LEDs to the GND (Ground).
Connection Diagram:
We will show the connection using the Simulator because the connections become
clearer and more precise.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Code:
void setup()
{
// initialize serial communication:
Serial.begin(9600);
// initializing the LED pins:
for (int LEDpin = 6; LEDpin <13 ; LEDpin++)
{
pinMode(LEDpin, OUTPUT);
// here, we have used for loop for initialization
}
}
void loop()
{
int a = 3; // we can specify any variable name
switch (a)
{
case 1:
digitalWrite(6, HIGH);
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
break;
case 2:
digitalWrite(8, HIGH);
break;
case 3:
digitalWrite(11, HIGH);
break;
case 4:
digitalWrite(12, HIGH);
break;
default:
// turn all the LEDs off if all the above cases does not matches:
for (int LEDpin = 6; LEDpin <13; LEDpin++)
{
digitalWrite(LEDpin, LOW);
}
}
}
Output:
The LED connected to the PIN 11 will light up, as shown below:
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Practical: 10
Aim: Explain working of Raspberry Pi.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
The Raspberry Pi device looks like a motherboard, with the mounted chips and ports exposed
but it has all the components you need to connect input, output, and storage devices and start
computing. Raspberry Pi uses a system-on-a-chip with all those components on a single chip.
Here are the accessories you’ll need to get up and running:
A power supply. Raspberry Pi doesn’t come with one, so you’ll need a micro USB
compatible cable in order to plug it into the wall.
A case. There’s no official one yet, so I put mine in this pink one from Adafruit.
Unfortunately, despite what you may have heard, it does not fit in an Altoids tin.
An HDMI cable or RCA video lead. You can’t use your Pi without a visual display.
You can either plug it into a computer monitor with HDMI input using an HDMI
cable, or you can plug it into an analogue TV with a standard RCA composite video
lead.
A USB mouse and keyboard. Or else how will you interact with the Pi? Any wired
or wireless mouse and keyboard should do; I’m using wireless Logitech products for
both.
An SD memory card. You’ll need one to boot up the Pi. The Raspberry Pi
foundation recommends at least 4 gigs to start, but as many as 32 if you want.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
A primary computer. I didn’t get that you can’t just get the Pi running without
already owning another computer, Mac or PC. Hopefully you already have one of
these, or this project just got a lot more expensive.
An SD memory card reader. The Raspberry Pi doesn’t need this, but your primary
computer does so you can transfer installations from it to the Pi. A lot of computers
come with a built-in card reader, but if yours doesn’t, you might want to invest in one.
Now, let’s fast-forward to the day when your Raspberry Pi and all its accessories arrive in the
mail. Here’s what to do, and when to do it.
Put your Raspberry Pi in its case. Unless it’s very customized, it should continue to
have holes in it for all of the Pi’s inputs
Put the Pi aside and go to your primary computer. Insert your SD card and format
it according to the Foundation’s directions. This will install a recovery program on it
so you can save your card even if you break it with your tinkering.
Download NOOBS on your primary computer. Short for New Out Of Box
Software, it’s the Raspberry Pi Foundation’s fittingly named distro for first-time Pi
users. A distro is a package installation of Linux and its associated software.
Time to get started with the Raspberry Pi. Slide the SD card into the underside of
the Raspberry Pi, and make sure it’s oriented correctly; it’d be bad to break your Pi
before you turn it on!
The Raspberry Pi will boot up and take you the NOOBS screen. If it doesn’t,
check your power supply and HDMI cables and make sure they’re secure.
Once the file copies, you’ll get a notice that says, “Image applied successfully.” Press
return, and the Pi will reboot. Now it will boot into the operating system’s graphical
user interface, which looks a lot like Windows 98.
MGITER/CE/6th/2023 210330107507
IoT and Applications-3160716
Now you’re ready to use your Raspberry Pi however you like. You can run programs on it as
if it were any other computer, or you can choose to work from the command line. Since it’s a
general purpose Linux machine, what you do from here is up to you.
MGITER/CE/6th/2023 210330107507