100% found this document useful (1 vote)
125 views26 pages

IOT Lab Manual

The document discusses installing and using the Arduino IDE. It describes different Arduino boards like UNO and their features. It provides steps to install the IDE, select the board and serial port and upload a sample blink program.

Uploaded by

Cuteness
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
125 views26 pages

IOT Lab Manual

The document discusses installing and using the Arduino IDE. It describes different Arduino boards like UNO and their features. It provides steps to install the IDE, select the board and serial port and upload a sample blink program.

Uploaded by

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

Shree Swaminarayan Institute of Technology CE/IT DEPT.

(VI SEMESTER)

IOT and Applications


Subject Code: 3160716

Lab Manual
Branch: CE

6th Semester

Shree Swaminarayan Institute of Technology


Sardar Patel Ring Road Circle, Gandhinagar to
Ahmedabad Airport Highway, Bhat,
Gandhinagar- 382428, Gujarat (INDIA)
Satsang Shiksha Parishad
Shree Swaminarayan Institute of Technology

Certificate
This is to Certify that Mr./Ms ..................................................................................................Of

Semester……………… and .........................................................................Branch

Enrollment No ................................................................................ has satisfactorily completed

his/her Practical and Term Work in the Subject …………………………………………

Academic year of 20 -20

Subject Head
In-charge Of Department

Approved By
Principal
Web Technology 2160708 Computer Engineering

INDEX
SR PAGE
CONTENT DATE MARKS SIGN.
NO. NO.

Study and Install IDE of Arduino and


1 different types of Arduino.

2 Write a Program for blink LED using Arduino.

3 Write a program for fade in LED using Arduino.

Write a program for multiple LED blinking


4
using Arduino.

Write a program for RGB LED blinking using


5. Arduino.

Write a Program for LED blink using Push


6 Button.
Write program for demonstrating temperature
7 sensor by using Arduino.

Display message in 16*2 LCD display by


8 using Arduino UNO.

Reads an analog input and prints the


9 voltage to the Serial Monitor.

10 Study Raspberry Pi.

Write a program for blinking led using


11 Raspberry PI.

Write a program for Fade in led


12 (increasing and decreasing brightness)
using Raspberry PI .

Write a program for demonstrating IR


13 sensor using Raspberry PI.
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 1
Aim: Study and Install IDE of Arduino and different types of Arduino.
Introduction:
Arduino is an open-source prototyping platform in electronics based on easy-to-use hardware
and software. Subtly speaking, Arduino is a microcontroller based prototyping board which
can be used in developing digital devices that can read inputs like finger on a button, touch on
a screen, light on a sensor etc. and turning it in to output like switching on an LED, rotating a
motor, playing songs through a speaker etc.

Types of Arduino Boards:


There are many types of Arduino boards available in the market but all the boards have one
thing in common: they can be programmed using the Arduino IDE. The reasons for different
types of boards are different power supply requirements, connectivity options, their
applications etc. Arduino boards are available in different sizes, form factors, different no. of
I/O pins etc. Some of the commonly known and frequently used Arduino boards are Arduino
UNO, Arduino Mega, Arduino Nano, Arduino Micro and Arduino Lilypad.

Arduino UNO:
In this tutorial, we will be discussing the Arduino UNO board. Arduino UNO is a basic and
inexpensive Arduino board and is the most popular of all the Arduino boards with a market
share of over 50%. Arduino UNO is considered to be the best prototyping board for beginners
in electronics and coding.

UNO is based on ATmega328P microcontroller. There are two variants of the Arduino UNO:
one which consists of through – hole microcontroller connection and other with surface mount
type. Through-hole model will be beneficial as we can take the chip out in case of any problem
and swap in with a new one.

Arduino UNO comes with different features and capabilities. As mentioned earlier, the
microcontroller used in UNO is ATmega328P, which is an 8-bit microcontroller based on the
AVR architecture. UNO has 14 digital input – output (I/O) pins which can be used as either
input or output by connecting them with different external devices and components. Out of
these 14 pins, 6 pins are capable of producing PWM signal. All the digital pins operate at 5V
and can output a current of 20mA.

Page no.: 1
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

(Fig: 1.1)

• Pins 0 and 1 are used for serial communication. They are used to receive and transmit serial
data which can be used in several ways like programming the Arduino board and
communicating with the user through serial monitor.

• Pins 2 and 3 are used for external interrupts. An external event can be triggered using these
pins by detecting low value, change in value or falling or rising edge on a signal.

• As mentioned earlier, 6 of the 14 digital I/O Pins i.e. 3, 5, 6, 9, 10, and 11 can provide 8-
bit PWM output.

• Pins 10, 11, 12 and 13 (SS, MOSI, MISO AND SCK respectively) are used for SPI
communication.

Page no.: 2
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

• Pin 13 has a built-in LED connected to it. When the pin is HIGH, the LED is turned on and
when the pin is LOW, it is turned off.

• Arduino Uno has 6 analog input pins which can provide 10 bits of resolution i.e. 1024
different values. The analog pins on the Arduino UNO are labelled A0 to A5.

Arduino UNO Application:

▪ Weighing Machines.
▪ Traffic Light Count Down Timer.
▪ Parking Lot Counter.
▪ Embedded systems.
▪ Home Automation.
▪ Industrial Automation.
▪ Medical Instrument.
▪ Emergency Light for Railway

Steps to Install and Use of IDE:

Step 1 − First you must have your Arduino board (you can choose your favorite board) and a
USB cable. In case you use Arduino UNO, Arduino Duemilanove, Nano, Arduino Mega 2560,
or Diecimila, you will need a standard USB cable (A plug to B plug), the kind you would
connect to a USB printer as shown in the following image.

Page no.: 3
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

In case you use Arduino Nano, you will need an A to Mini-B cable instead as shown in the
following image.

Step 2 − Download Arduino IDE Software.


You can get different versions of Arduino IDE from the Download page on the Arduino
Official website. You must select your software, which is compatible with your operating
system (Windows, IOS, or Linux). After your file download is complete, unzip the file.

Step 3 − Power up your board.


The Arduino Uno, Mega, Duemilanove and Arduino Nano automatically draw power from
either, the USB connection to the computer or an external power supply. If you are using
an Arduino Diecimila, you have to make sure that the board is configured to draw power
from the USB connection. The power source is selected with a jumper, a small piece of

Page no.: 4
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

plastic that fits onto two of the three pins between the USB and power jacks. Check that it
is on the two pins closest to the USB port.
Connect the Arduino board to your computer using the USB cable. The green power LED
(labeled PWR) should glow.

Step 4 − Launch Arduino IDE.


After your Arduino IDE software is downloaded, you need to unzip the folder. Inside the
folder, you can find the application icon with an infinity label (application.exe). Double-
click the icon to start the IDE.

Step 5 − Open your first project.


Once the software starts, you have two options −
Create a new project.
Open an existing project example.
To create a new project, select File → New.

Page no.: 5
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

To open an existing project example, select File → Example → Basics → Blink.

Page no.: 6
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

Here, we are selecting just one of the examples with the name Blink. It turns the LED on and
off with some time delay. You can select any other example from the list.

Step 6 − Select your Arduino board.


To avoid any error while uploading your program to the board, you must select the correct
Arduino board name, which matches with the board connected to your computer.
Go to Tools → Board and select your board.

Here, we have selected Arduino Uno board according to our tutorial, but you must select the
name matching the board that you are using.

Page no.: 7
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

Step 7 − Select your serial port.


Select the serial device of the Arduino board. Go to Tools → Serial Port menu. This is likely
to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To
find out, you can disconnect your Arduino board and re-open the menu, the entry that
disappears should be of the Arduino board. Reconnect the board and select that serial port.

Step 8 − Upload the program to your board.


Before explaining how we can upload our program to the board, we must demonstrate the
function of each symbol appearing in the Arduino IDE toolbar.

Page no.: 8
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

A − Used to check if there is any compilation error.

B − Used to upload a program to the Arduino board.

C − Shortcut used to create a new sketch.

D − Used to directly open one of the example sketch.

E − Used to save your sketch.

F − Serial monitor used to receive serial data from the board and send the serial data
to the board.

Now, simply click the "Upload" button in the environment. Wait a few seconds; you will see
the RX and TX LEDs on the board, flashing. If the upload is successful, the message "Done
uploading" will appear in the status bar.

Note − If you have an Arduino Mini, NG, or other board, you need to press the reset button
physically on the board, immediately before clicking the upload button on the Arduino
Software.

Page no.: 9
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 2
Aim: Write a Program for blink LED using Arduino.

Source Code:

int ledPin = 11;


void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop()
{
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
}

Output:

Page no.: 10
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 3
Aim: Write a program for fade in LED using Arduino.

Source Code:

int ledPin = A0;


void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop()
{
for(int sig=0;sig<=255;sig+=1){
analogWrite(ledPin, sig);
delay(6);
}
for(int sig=255;sig>=0;sig-=1){
analogWrite(ledPin, sig);
delay(6);
}
}

Output:

Page no.: 11
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 4
Aim: Write a program for multiple LED blinking using Arduino.

Source Code:

int redPin = 13;


int yellowPin = 12;
int greenPin = 8;
int orangePin= 7;
int bluePin = 4;
int whitePin = 2;
int d = 150;
const int arrPin[6] = {redPin, yellowPin, greenPin, orangePin,bluePin,whitePin};
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(orangePin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(whitePin, OUTPUT);
}

void loop()
{
blinkAllLed();
}

void blinkAllLed(){
for(int i=0;i<6;i++){
digitalWrite(arrPin[i], HIGH);

Page no.: 12
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

delay(d);
digitalWrite(arrPin[i], LOW);
delay(d);

}
}

Output:

Page no.: 13
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 5
Aim: Write a program for RGB LED blinking using Arduino.

Source Code:

int rgbPins[] = {13,8,12};


void setup()
{
pinMode(13, OUTPUT);
pinMode(8, OUTPUT);
pinMode(12, OUTPUT);
}

void loop()
{
for(int i=0;i<3;i++){
digitalWrite(rgbPins[i], HIGH);
delay(300);
digitalWrite(rgbPins[i], LOW);
}
}

Output:

Page no.: 14
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 6
Aim: Write a Program for LED blink using Push Button.

Source Code:

int pushPin = 8 ,ledPin = 12;


void setup(){
pinMode(12, OUTPUT);
pinMode(8, INPUT_PULLUP);
digitalWrite(ledPin, LOW);
}
void loop(){
if(digitalRead(8)== HIGH){
digitalWrite(12, LOW);
}
else{
digitalWrite(12, HIGH);
delay(100);
digitalWrite(12, LOW);
delay(100);
}
}

Output:

Page no.: 15
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 7
Aim: Write program for demonstrating temperature sensor by using
Arduino.

Source Code:

float temp;
void setup(){
pinMode(A5,INPUT);
Serial.begin(9600);
}
void loop(){
temp=analogRead(A5);
temp=(temp*0.491)-50;
Serial.println(temp);
delay(1000);
}

Output:

Page no.: 16
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 8
Aim: Display message in 16*2 LCD display by using Arduino UNO.

Source Code:

#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2);
lcd.print("hello, world!");
}

void loop() {
}

Output:

Page no.: 17
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 9
Aim: Reads an analog input and prints the voltage to the Serial Monitor.

Source Code:

void setup()
{
Serial.begin(9600);
pinMode(A2,INPUT);
}
void loop()
{
int sensorVal = analogRead(A2);
float voltage = sensorVal * (5.0 / 1023.0);
Serial.println(voltage);
}

Output:

Page no.: 18
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 10
Aim: Study Raspberry Pi.

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

Page no.: 19
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

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 on-board
SDRAM that ranges from 256 MB to 1 GB.

Raspberry Pi also provides on-chip SPI, I2C, I2S and UART modules. There are different
versions of raspberry pi available as listed below:
1. Raspberry Pi 1 Model A
2. Raspberry Pi 1 Model A+
3. Raspberry Pi 1 Model B
4. Raspberry Pi 1 Model B+
5. Raspberry Pi 2 Model B
6. Raspberry Pi 3 Model B
7. Raspberry Pi Zero

Page no.: 20
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 11
Aim: Write a program for blinking led using Raspberry PI.

Source Code:

import RPi.GPIO as GPIO


from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(18,GPIO.OUT)
while True:
GPIO.output(18,GPIO.HIGH)
sleep(1)
GPIO.output(18,GPIO.LOW)
sleep(1)

Output:

Page no.: 21
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 12
Aim: Write a program for Fade in led (increasing and decreasing
brightness) using Raspberry PI .

Source Code:

import RPi.GPIO as GPIO


import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(11,GPIO.OUT)
p=GPIO.PWM(11,50)
p.start(0)
while True:
for i in range(0,101,2): #Increase in Brightness
p.ChangeDutyCycle(i)
time.sleep(.1)
for i in range(100,-1,-2): #Fading in Brightness
p.ChangeDutyCycle(i)
time.sleep(.1)

Output:

Page no.: 22
Shree Swaminarayan Institute of Technology CE/IT DEPT. (VI Semester)

PRACTICAL: 13
Aim: Write a program for demonstrating IR sensor using Raspberry PI.

Source Code:

import RPi.GPIO as GPIO


import time
GPIO.setmode(GPIO. BOARD)
GPIO.setup(16, GPIO. IN)
white True:
if GPIO.input(16):
GPIO.output(18, False)
while GPIO.input(16):
time.sleep(0.2)
else:
GPIO.output( led, True)

Output:

Page no.: 23

You might also like