You are on page 1of 34

lOMoAR cPSD| 40182762

IOT Practical

Fundamentals of Computer and IT (I. K. Gujral Punjab Technical University)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)
lOMoAR cPSD| 40182762

PRACTICAL FILE

INTERNET OF THINGS
(UGCA 1933)

Submitted To :
Submitted By :
Kiran Jyoti Mehra
Sanjeev Kumar Panda
Roll No : 1926933
BSC IT 6th

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

S No. Name Of Experiment Page No. Date Signature

INDEX

Experiment No 1

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

Aim: To interface motor using relay with Arduino/Raspberry Pi and write a


program to turn ON motor when push button is pressed.

Explanation: Control Servo motor with Arduino Uno and Push-button

• Connect a push-button to Arduino.


• Pull-up
• digitalread() function.
• Finally control Servo motor with push-button.

How it works?
First we read the push-button state using digitalRead() function. In this
experiment we use if else statement to control the servo motor according to the
condition. Arduino Uno continuously monitor state of the push-button. When
the push-button sate become high, Arduino write the servo to 180 degree.
Otherwise it keeps at 0 degree.
First we need to know what is push-button. It will help to use the push-button in
all aspects and anywhere

Push-button
In simple words, It is a simple switch which only on/conduct when the button is
pressed. Most of the push-buttons are designed to operate with human hand. So,
the top of the push-button always a flat structure. Here we using a PCB mount
type push-button.
Next we need to know what is pull-up resistor.

Pull-up Resistor
In the circuit diagram, You can find a 10 Kilo Ohm resistor connected to the
push-button. Here it is used as pull-up resistor. It is used to ensure a known state
(here it is HIGH) for a signal. When switch/push-button is closed it create a
direct path to Ground. But when switch/push-button is opened, there will be a
well defined logic HIGH at signal.

It's time to start


Step - 1
3

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

First add the header file for servo motor and declare a variable to call the Servo
motor. Here I am using the variable name as "Myservo"
#include<Servo.h>
Servo Mysevo;
Step - 2
In void setup() function, declare the Servo pin by the "attach()" function. in this
project we use the Arduino digital pin 3 to this purpose. Then we need to set the
pin to read the pushbutton, as "INPUT"
Myservo.attach(3)'
pinMode(2,INPUT);
Setup part is completed.
Step - 3
In the void loop() function we need to use if and else to make a diction. When
the push-button is pressed the output of the push-button be logic LOW. This
push-button output is read by digitalRead() function. Here we use the Arduino
Uno Digital pin 2 is used to this purpose. Then write the servo to 180 degree.
if(digitalRead(2)==LOW){
Myservo.write(180);
}
Otherwise Servo position keep as 0 degree.
else{
Myservo.write(0);
}
The coding part is completed. Double check for errors and upload the code to
Arduino Uno.
Now we need to make the circuit. Here we are using PCB mound type push-
button. So solder the push-button and resistor on the Dot PCB.

Circuit diagram:

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

CODE
Control Servo Motor with Arduino and push-buttonArduino
//sketch created by Akshay Joseph follow me on Instagra: five_volt_player

include<Servo.h>
Servo Myservo;
int pos=0;
void setup()
{
pinMode(2,INPUT);
Myservo.attach(3);
}

void loop()
{
if(digitalRead(2)==LOW){
Myservo.write(180);
}
else

Myservo.write(0);

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

Outcomes:

Student will be able to understand how to Control Servo Motor with push-
button using Arduino uno.

Applications:

Servomotor used in camera zooms, lift doors, or tools we may have at home.
Servo motors are also used in industrial applications, robotics, in-line
manufacturing, pharmaceutics, and food services.

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

Experiment No. 2

Aim: Write a program on Arduino/Raspberry Pi to retrieve temperature and


humidity data from thingspeak cloud.

ThingSpeak Read: Read data stored in a ThingSpeak channel

• Description
You can retrieve data from the Internet of Things website by using ThingSpeak
to download the data to your target hardware.
ThingSpeak is an application platform that you can use for the Internet of
Things. You can build an application around data that is collected by sensors.
ThingSpeak includes real-time data collection, data processing, visualizations,
apps, and plugins.
You can see the ThingSpeak server response to a data download request by
selecting the Print diagnostic messages option. This option has no effect when
you use External mode, Serial Transmit, or Serial Receive blocks that use port
0.

• Parameters
Channel ID
1. Get the Channel ID parameter from your channel on ThingSpeak.com.

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

2. After creating a ThingSpeak channel for your target hardware:


3. On the ThingSpeak.com website, select Channels > My Channels.
4. Under the channel that you created for this target hardware,
click Settings.
5. Click the Channel Settings tab and copy the Channel ID.
6. Open the ThingSpeak Read block in your model and paste the value into
the Channel ID parameter.

Channel Access
By default, the ThingSpeak channel access is private. To access the channel,
you must have a read API key.
You can make the channel public to allow other users to use your feed without a
Read API key.

Read API Key


1. On the ThingSpeak.com website, select Channels > My Channels.
2. Under the channel that you created for this target hardware,
click Settings.
3. Click the API Keys tab.
4. Copy the key from Read API Key parameter.
5. Open the ThingSpeak Read block in your model and paste the copied API
key into theRead API key parameter.

Field Number
Specify a field that you want to read from the ThingSpeak channel.

Print diagnostic messages


Select this check box to get ThingSpeak server response data and send it to the
standard output device.

Sample time
Specify in seconds how often this block reads the ThingSpeak channel..

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

Outcomes:
Student will be able to understand how can retrieve data from the Internet of
Things website by using ThingSpeak to download the data to your target
hardware.

Applications:
Machine learning uses data and produces a program to perform a task.
Application is Cloud-based people counter by detecting faces with the
Computer Vision System. The raw people count is then sent to the ThingSpeak
IoT platform for data collection in the cloud and further data analysis.

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

Experiment no 3

Aim: Familiarization with Arduino/Raspberry Pi and perform necessary


software installation.
Software Installation: how to set up the Arduino IDE on our computer and
prepare the board to receive the program via USB cable.
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.

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
10

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

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

11

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

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.

12

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

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


Blink.

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.

13

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

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

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.

14

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

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.

15

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

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.

Outcomes:

Student will be able to understand the components of ardunio/raspberry Pi and


also able to install software setup of ardunio/raspberry Pi.

Applications:

Various applications like in agriculture, healthcare system etc. can be designed


with the help of Ardunio uno/raspberry Pi.

16

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

Experiment No 4

Aim: To interface LED/Buzzer with Arduino/Raspberry Pi and write a program


to turn ON LED for 1 sec after every 2 seconds.

Explanation: LEDs are small, powerful lights that are used in many different
applications. To start, we will work on blinking an LED, the Hello World of
microcontrollers. It is as simple as turning a light on and off. Establishing this
important baseline will give you a solid foundation as we work towards
experiments that are more complex.
Components Required:
You will need the following components −

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

Procedure
Follow the circuit diagram and hook up the components on the breadboard as
shown in the image given below.

17

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

Note − To find out the polarity of an LED, look at it closely. The shorter of the
two legs, towards the flat edge of the bulb indicates the negative terminal.

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

18

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

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

Arduino Code
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
*/

// the setup function runs once when you press reset or power the board

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


pinMode(2, OUTPUT);
}

// the loop function runs over and over again forever

void loop() {
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second

19

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

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

Result
You should see your LED turn on and off. If the required output is not seen,
make sure you have assembled the circuit correctly, and verified and uploaded
the code to your board.

Outcomes:

Student will be able to understand how to make the circuits on ardunio


uno/raspberry Pi and how to interface with the computer.

Applications:

Uses Arduino UNO: LED emergency lights for use on model / toy vehicles and
other projects.

20

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

Experiment No. 5

Aim: To interface Push button/Digital sensor (IR/LDR) with Arduino/Raspberry


Pi and write a program to turn ON LED when push button is pressed or at
sensor detection.

Explanation: The pushbutton is a component that connects two points in a


circuit when you press it. The example turns on an LED when you press the
button.

We connect three wires to the Arduino board. The first goes from one leg of the
pushbutton through a pull-up resistor (here 2.2 KOhms) to the 5 volt supply.
The second goes from the corresponding leg of the pushbutton to ground. The
third connects to a digital i/o pin (here pin 7) which reads the button's state.

When the pushbutton is open (unpressed) there is no connection between the


two legs of the pushbutton, so the pin is connected to 5 volts (through the pull-
up resistor) and we read a HIGH. When the button is closed (pressed), it makes
a connection between its two legs, connecting the pin to ground, so that we read
a LOW. (The pin is still connected to 5 volts, but the resistor in-between them
means that the pin is "closer" to ground.)

Schematic:

21

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

/* Basic Digital Read

* turns on and off a light emitting diode(LED) connected to digital

* pin 13, when pressing a pushbutton attached to pin 7. It illustrates the

* concept of Active-Low, which consists in connecting buttons using a

* 1K to 10K pull-up resistor.

* Created 1 December 2005

* copyleft 2005 DojoDave <http://www.0j0.org>

* http://arduino.berlios.de

*/

22

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

int ledPin = 13; // choose the pin for the LED

int inPin = 7; // choose the input pin (for a pushbutton)

int val = 0; // variable for reading the pin status

void setup() {

pinMode(ledPin, OUTPUT); // declare LED as output

pinMode(inPin, INPUT); // declare pushbutton as input

void loop(){

val = digitalRead(inPin); // read input value

if (val == HIGH) { // check if the input is HIGH (button released)

digitalWrite(ledPin, LOW); // turn LED OFF

} else {

digitalWrite(ledPin, HIGH); // turn LED ON

23

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

Outcomes:

Student will be able to understand how to interface with digital sensor and push
buttons and its installation on Ardunio Uno.

Applications:

This is used in basic button application module. Momentary Pushbutton Switch


usually stays open. When it is pressed down, circuit connected; when it is
released, it will bounce back to the status of disconnection.

Experiment No 6

Aim: To interface motor using relay with Arduino/Raspberry Pi and write a


program to turn ON motor when push button is pressed.

Explanation:
Control Servo motor with Arduino Uno and Push-button

1. Connect a push-button to Arduino.


2. Pull-up
3. digitalread() function.
4. Finally control Servo motor with push-button.

How it works?
First we read the push-button state using digitalRead() function. In this
experiment we use if else statement to control the servo motor according to the
condition. Arduino Uno continuously monitor state of the push-button. When
the push-button sate become high, Arduino write the servo to 180 degree.
Otherwise it keeps at 0 degree.
First we need to know what is push-button. It will help to use the push-button in
all aspects and anywhere

24

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

Push-button
In simple words, It is a simple switch which only on/conduct when the button is
pressed. Most of the push-buttons are designed to operate with human hand. So,
the top of the push-button always a flat structure. Here we using a PCB mount
type push-button.
Next we need to know what is pull-up resistor.

Pull-up Resistor
In the circuit diagram, You can find a 10 Kilo Ohm resistor connected to the
push-button. Here it is used as pull-up resistor. It is used to ensure a known state
(here it is HIGH) for a signal. When switch/push-button is closed it create a
direct path to Ground. But when switch/push-button is opened, there will be a
well defined logic HIGH at signal.

It's time to start


Step - 1
First add the header file for servo motor and declare a variable to call the Servo
motor. Here I am using the variable name as "Myservo"
#include<Servo.h>
Servo Mysevo;

Step - 2
In void setup() function, declare the Servo pin by the "attach()" function. in this
project we use the Arduino digital pin 3 to this purpose. Then we need to set the
pin to read the pushbutton, as "INPUT"
Myservo.attach(3)'
pinMode(2,INPUT);

Setup part is completed.


Step - 3
In the void loop() function we need to use if and else to make a diction. When
the push-button is pressed the output of the push-button be logic LOW. This
push-button output is read by digitalRead() function. Here we use the Arduino
Uno Digital pin 2 is used to this purpose. Then write the servo to 180 degree.

25

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

if(digitalRead(2)==LOW){
Myservo.write(180);
}
Otherwise Servo position keep as 0 degree.
else{
Myservo.write(0);
}
The coding part is completed. Double check for errors and upload the code to
Arduino Uno.
Now we need to make the circuit. Here we are using PCB mound type push-
button. So solder the push-button and resistor on the Dot PCB.

Circuit diagram:

CODE
Control Servo Motor with Arduino and push-buttonArduino
//sketch created by Akshay Joseph follow me on Instagra: five_volt_player

include<Servo.h>
Servo Myservo;
int pos=0;
void setup()
{

26

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

pinMode(2,INPUT);
Myservo.attach(3);
}

void loop()
{
if(digitalRead(2)==LOW){
Myservo.write(180);
}
else

Myservo.write(0);

Outcomes:

Student will be able to understand how to Control Servo Motor with push-
button using Arduino uno.

Applications:

Servomotor used in camera zooms, lift doors, or tools we may have at home.
Servo motors are also used in industrial applications, robotics, in-line
manufacturing, pharmaceutics, and food services.

27

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

Experiment No. 7

Aim: To interface Bluetooth with Arduino/Raspberry Pi and write a program to


turn LED ON/OFF when ‘1’/’0’ is received from smartphone using Bluetooth.

There are three main parts to this project. An Android smartphone, a Bluetooth
transceiver, and an Arduino.

HC 05/06 works on serial communication. The Android app is designed to send


serial data to the Arduino Bluetooth module when a button is pressed on the
app. The Arduino Bluetooth module at the other end receives the data and sends
it to the Arduino through the TX pin of the Bluetooth module (connected to RX
pin of Arduino). The code uploaded to the Arduino checks the received data and
compares it. If the received data is 1, the LED turns ON. The LED turns OFF
when the received data is 0. You can open the serial monitor and watch the
received data while connecting.

28

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

Connecting the Arduino Bluetooth Hardware

This circuit is simple and small. There are only four connections to be made
between the Arduino and Bluetooth module!

Arduino Pins | Bluetooth Pins


RX (Pin 0) ———> TX
TX (Pin 1) ———> RX
5V ———> VCC
GND ———> GND

Connect an LED positive to pin 13 of the Arduino through a resistance (valued


between 220Ω–1KΩ). Connect its negative to GND, and you're done with the
circuit!

29

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

You can connect the Bluetooth module to the Arduino using a set of jumper
wires and a connector.

Note: Don’t connect RX to RX and TX to TX on the Bluetooth and Arduino. You


will receive no data. Here, TX means transmit and RX means receive.

Uploading the Sketch to Arduino

char data = 0; //Variable for storing received data


void setup()
{
Serial.begin(9600); //Sets the data rate in bits per second (baud) for serial
data transmission
pinMode(13, OUTPUT); //Sets digital pin 13 as output pin
}
void loop()
{
if(Serial.available() > 0) // Send data only when you receive data:
{

30

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

data = Serial.read(); //Read the incoming data and store it into variable data
Serial.print(data); //Print Value inside data in Serial monitor
Serial.print("\n"); //New line
if(data == '1') //Checks whether value of data is equal to 1
digitalWrite(13, HIGH); //If value is 1 then LED turns ON
else if(data == '0') //Checks whether value of data is equal to 0
digitalWrite(13, LOW); //If value is 0 then LED turns OFF
}

Installing the Android Application

You can download the Android application from here and the source code of the
entire project.

• Download the application from Amazon App Store or Github.


• Pair your device with the HC 05/06 Bluetooth module:

1. Turn ON the HC 05/06 Bluetooth module by powering the Arduino.


2. Scan your smartphone for available devices.3. Pair your smartphone tothe
HC 05/06 by entering default password 1234 OR 0000.
• Install the LED application on your Android device.
• Open the application.

31

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

• Press "paired devices".


• Select your Bluetooth module from the list (HC-05/06)

• After connecting successfully, press the ON button to turn the LED on


and the OFF button to turn the LED off.

32

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)


lOMoAR cPSD| 40182762

• Disconnect the button to disconnect the Bluetooth module.

Outcomes:

Student will be able to understand how to interface an Android smartphone with


an Arduino via Bluetooth to control an LED from your phone.

Applications:

This work can be taken to a higher level, like home automation using a
smartphone, smartphone-controlled robots.

33

Downloaded by ASHUTOSH KUMAR (ashutoshsnp96@gmail.com)

You might also like