IOT Practical File Done.
IOT Practical File Done.
Hamidpur, Delhi-110036
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
How it works?
First we read the push-button state using digital Read() 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.
Circuit diagram:
4
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);
5
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.
6
Experiment No. 2
Aim: Write a program on Arduino/Raspberry Pi to retrieve temperature and humidity
data from thingspeak cloud.
• 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
7
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.
Field Number
Specify a field that you want to read from the ThingSpeak channel.
Sample time
Specify in seconds how often this block reads the ThingSpeak channel.
8
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.
9
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.
11
Step 5 − Open your first project.
Once the software starts, you have two options −
12
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.
13
Here, we have selected Arduino Uno board according to our tutorial, but
you must select the name matching the board that you are using.
14
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
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:
Applications:
16
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
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
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
void loop() {
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
19
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:
Applications:
Uses Arduino UNO: LED emergency lights for use on model / toy vehicles and
other projects.
20
Experiment No. 5
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.
Schematic:
21
/* Basic Digital Read
* http://arduino.berlios.de
*/
22
Outcomes:
Student
int ledPinwill
= 13;be able tothe
// choose understand how to interface with digital sensor and push
pin for the LED
buttons
int inPin =and
7; its installation
// choose onpin
the input Ardunio Uno.
(for a pushbutton) int val = 0;// variable for reading the pin status
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
voidback
bounce setup()
to{the status of disconnection.
pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inPin, INPUT);// declare pushbutton as input
}
void loop(){
} else {
}
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
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
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.
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);
25
if(digitalRead(2)==LOW){
Myservo.write(180);
}
Otherwise Servo position keep as 0 degree.
else{ Myservo.wr
ite(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
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
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.
28
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!
29
You can connect the Bluetooth module to the Arduino using a set of
jumper wires and a connector.
30
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
}
You can download the Android application from here and the source code of the
entire project.
31
• Press "paired devices".
• Select your Bluetooth module from the list (HC-05/06)
32
• Disconnect the button to disconnect the Bluetooth module.
Outcomes:
Applications:
This work can be taken to a higher level, like home automation using a
smartphone, smartphone-controlled robots.
33