Final IOT
Final IOT
Practical – 2
Components required :
Arduino Uno board * 1
USB cable * 1
Resistor (220Ω) * 1
LED * 1
Breadboard * 1
Jumper wires
Configuration :
Schematic Diagram
1
210180107050 COMP607-IOT
Figure :
Figure
Procedure :
Connect one end to the anode (the long pin) of the LED to the 220ohm resistor one end, the
other end of resistor connected to the Pin 9 in arduino , and the cathode (the short pin) of the
LED to GND.
When the pin 9 outputs high level, the current gets through the current limiting resistor to the
anode of the LED. And since the cathode of the LED is connected to GND, the LED will
light up.
Step 1:
Build the circuit.
Step 2:
Write Code in Arduino IDE
Code:
void setup() {
// LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); delay(1000);
// wait for (1 sec = 1000ms)
}
2
210180107050 COMP607-IOT
Step 3:digitalWrite(LED_BUILTIN, LOW); delay(2000);
// wait for (2 sec = 2000ms)
Upload the sketch to the Arduino Uno board
Click the Upload icon to upload the code to the control board.
If "Done uploading" appears at the bottom of the window, it means the sketch has been
successfully uploaded.
Conclusion :
From the above practical we demonstrated that a led can be turn off/on using arduino uno.
3
210180107050 COMP607-IOT
Practical – 3
Aim : Measuring Temperature and Humidity using Sensor DHT-11
and Arduino UNO.
Components required :
Breadboard * 1
Jumper wires
Configuration :
Figure :
4
210180107050 COMP607-IOT
Procedure :
Code :
5
210180107050 COMP607-IOT
#include <dht.h>
#define
dht_11_PIN7 dht
DHT;
void setup(){
Serial.begin(9600);
void loop(){
DHT.read11(dht_api
n);
Serial.print("Current humidity =
"); Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(5000);
Now write code in IDE. In the Arduino IDE, go to Sketch >> Include Library >>
Add ZIP file.
6
210180107050 COMP607-IOT
When you click the 'Add .ZIP library', you should get a file window that pops up.
Add the DHT_Library.zip.
NOW upload the code. When it is finished, go to the top right of the Arduino IDE
window and click the little magnifying glass button. That will open the serial
monitor, and the data of the sensor should be displaying itself and updating every 5
seconds.
7
210180107050 COMP607-IOT
Conclusion :
From the above practical we demonstrated that arduino uno can be used to measure
temperature and humidity with sensor DHT-11 at an interval of 5 seconds.
Practical – 4
Aim : Measuring object presence using IR Sensor and when present,
use buzzer for notification.
8
210180107050 COMP607-IOT
COMPONENTS:
1. Arduino UNO
2. Jumper Cables
3. Buzzer
4. Bread board
5. IR Sensor
PROCEDURE:
1. Build the circuit according to the above circuit diagram.
2. Then, open the Arduino IDE and write the following code:
int irSensor =
12; int buzzer
= 7; void
setup()
{
Serial.begin(9600);
pinMode(irSensor,
INPUT);
pinMode(buzzer,
OUTPUT);
}
void loop()
{
int value =
digitalRead(irSensor);
Serial.println("");
Serial.print("Sensor Value =
9
210180107050 COMP607-IOT
"); Serial.print(value);
if(value == 0)
{
}
else
{
}digitalWrite(buzzer, HIGH);
digitalWrite(buzzer, LOW);
delay(50);
}
OBSERVATION :
CONCLUSION:
From the above practical we can conclude that using IR sensor with arduino
UNO, presence of an object can be detected upto a particular distance from
the sensor
Practical – 5
Aim : Measuring object distance using Ultraviolet Sensor and
Arduino Uno.
Components required :
Jump Wires
BreadBoard * 1
Configuration :
10
210180107050 COMP607-IOT
Figure :
11
210180107050 COMP607-IOT
Procedure :
First, place the distance sensor on one end of the breadboard so that none of the pins are
connected as shown
Lastly, complete the circuit by connecting the Ultrasonic Sensor's ground pin to the
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.
Code :
= 9; const int
echo = 10;
OUTPUT pinMode(trigger,
OUTPUT);
INPUT pinMode(echo,
INPUT); /
communication
Serial.begin(9600);
12
210180107050 COMP607-IOT
void loop() {
LOW);
delayMicroseconds(2);
digitalWrite(trigger, HIGH);
delayMicroseconds(10)
; digitalWrite(trigger,
LOW);
distance= duration*0.034/2;
Serial.println(distance);
OUTPUT :
13
210180107050 COMP607-IOT
Conclusion :
From the above practical we demonstrated that using ultraviolet sensor with arduino uno
the distance to an object can be measured in range of 2cm to 400cm.
Practical – 6
14
210180107050 COMP607-IOT
Aim : Measuring moving object using PIR Sensor and Arduino Uno.
Components required :
PIR Sensor * 1
5V Buzzer * 1
BreadBoard * 1
Connecting Wires
Configuration :
The design of the PIR Motion Sensor using Arduino is very simple. The PIR Sensor
Module has three pins: VCC, Digital Out and GND. Connect VCC and GND to +5V and
GND respectively. Then connect the Digital Out Pin of the PIR sensor to the digital I/O
pin 8 of Arduino.
As we need to indicate the detection of motion by the sensor, connect a buzzer to Pin 11
of the Arduino.
Figure:
15
210180107050 COMP607-IOT
Procedure :
The working of this project is very simple. When the system is powered on, the Arduino
waits for the PIR Sensor to be calibrated. The calibration period is set to 10 seconds and
during this time, there should be no movements in front of the PIR Sensor.
After the calibration, the PIR Sensor will be ready to detect any movement in front of it.
If the PIR Sensor detects any movements, its Digital Out pin, which is connected to Pin 8
of Arduino will become HIGH.
Arduino will detect this HIGH Signal and activates the buzzer.
Code :
int buzzer
= 11; int
sensor = 8;
int led =
13; id
setup()
pinMode(buzzer,
16
210180107050 COMP607-IOT
OUTPUT);
pinMode(sensor,
INPUT); pinMode(led,
OUTPUT);
digitalWrite(buzzer,LO
W);
digitalWrite(sensor,LO
W);
digitalWrite(led,LOW);
while(millis()<13000)
digitalWrite(led,HIGH);
delay(50);
digitalWrite(led,LOW);
delay(50);
digitalWrite(led,HIGH);
void loop()
if(digitalRead(sensor)==HIGH)
digitalWrite(buzzer,HIGH);
delay(3000);
digitalWrite(buzzer,LOW);
while(digitalRead(sensor)==HI
GH);
17
210180107050 COMP607-IOT
}
Conclusion :
From the above practical we demonstrated that using PIR sensor with arduino the
motion of an object can be detected.
18
210180107050 COMP607-IOT
Practical – 7
Aim : Measure temperature using DHT-11 sensor and send it to
cloud ThingSpeak using NodeMCU.
Components required :
NodeMCU * 1
Breadboard * 1
Jumper wires
Configuration :
19
210180107050 COMP607-IOT
Figure :
Procedure :
2. Create a new channel by clicking on the button. Enter the basic details of the channel.
Then Scroll down and save the channel.
3. Then go to API keys copy and paste this key to a separate notepad file. You will
need it later while programming.
The program for Humidity & Temperature Monitoring using DHT11 &
Code :
#include <DHT.h> // Including library for dht
#include <ESP8266WiFi.h>
from ThingSpeak
const char *ssid = "how2electronics"; // replace with your wifi ssid and
WiFiClient
client; void
setup()
{
Serial.begin(115
200); delay(10);
dht.begin();
Serial.println("Connecting
to "); Serial.println(ssid);
WiFi.begin(ssid, pass);
{
delay(500);
21
210180107050 COMP607-IOT
Serial.print(".");
Serial.println("");
Serial.println("WiFi
connected");
void loop()
float h =
dht.readHumidity(); float t
= dht.readTemperature();
if (isnan(h) || isnan(t))
sensor!"); return;
String postStr =
apiKey; postStr
+="&field1=";
postStr +=
String(t); postStr
+="&field2=";
postStr +=
String(h); postStr
+= "\r\n\r\n";
22
210180107050 COMP607-IOT
client.print("POST /update HTTP/1.1\
n"); client.print("Host:
api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-
client.print(postStr.lengt
h()); client.print("\n\n");
client.print(postStr);
Serial.print("Temperatur
e: "); Serial.print(t);
Serial.print(h);
client.stop();
Serial.println("Waiting...");
updates delay(1000);
23
210180107050 COMP607-IOT
OUTPUT :
On every successful data upload, success message is displayed on serial monitor
24
210180107050 COMP607-IOT
Temperature :Humidity :
25
210180107050 COMP607-IOT
Conclusion :
From the above practical we demonstrated that using NodeMCU, the data (temperature
and humidity measured by DHT-11) can be send to the ThingsSpeak cloud.
Practical – 8
Aim : Controlling Led ON/OFF by giving command from mobile
phone. (Use cloud ThingSpeak)
26
210180107050 COMP607-IOT
Components required :
NodeMCU 12E * 1
LED * 1
Breadboard * 1
Jumper wires
Configuration :
Schematic Diagram
Figure :
27
210180107050 COMP607-IOT
Procedure :
After click the new channel and first write the name of the new channel .
if you want give the description then write the description. and select the Field
1 and don't forget the click on checkbox, after click on the check box scroll the
28
210180107050 COMP607-IOT
page and click on the save button.
I give the new channel name is LED then select the Field 1 and scroll the
page and click on the save channel button.
29
210180107050 COMP607-IOT
Here filed is empty because I do not upload any data on the channel. Now our goal to
blink the led via webserver.
Firmware :
Now write the code in Arduino IDE. open the Arduino IDE and select the
NodeMCU 12E board
Code :
30
210180107050 COMP607-IOT
#include<ThingSpeak.h>
#include<ESP8266WiFi.h>
#include<ESP8266WebServer.h>
unsigned long
channel_num=1070593; const
char* ssid="shravan";
const char*
WiFiClient client; // make the client of the WiFi which connect to the ThingSpeak
pinMode(D1,OUTP
UT);
digitalWrite(D1,0);
Serial.begin(115200
);
while(WiFi.status()!=WL_CONNECTED)
delay(500);
Serial.print(
".");
server.on("/",handleonconnect); // in urt type the "/" then call the handle on connect
31
210180107050 COMP607-IOT
server.begin(); // start the server
field 1 if(led==1)
digitalWrite(D1,1);
else if(led==0)
digitalWrite(D1,0);
server.send(200,"text/html",SendHTML());
Show the Thingspeak server where we create the our new channel. and copy
the channel id and pate to the our Arduino IDE.
That is my HTML code if you are an embedded engineer then do not learn the
HTML and CSS, but knowledge abut the how it work we press the any url.
https://api.thingspeak.com/update?
api_key=MOHD33LYGVXTG5UF&field1=0 thi s url is copy from the thingserver
here api_key is different in your case last one &field1=0 mean we we press this url
then send the 0 on your thingspeak server to the field1 and &field1=1 mean when we
press this url then send the 1 on your thingspeak server to the field1. but we don't
33
210180107050 COMP607-IOT
press the url using HTML code we only clink on the ON button to turn on the led and
OFF button for turn off the led.
Now go to the thingspeak server click on the API KEYS and copy the Write API
KEY and paste the HTML code code which highlighted on the upper HTML code
pic.
so for that click on sharing button and click the Share channel view with everyone.
34
210180107050 COMP607-IOT
Finally upload the code on the NodeMCU. show the serial port wifi is connect or
not if connect then give the local ip where we print on serial.
Finally this IP copy on the Chrome browser. then show the this type.
35
210180107050 COMP607-IOT
Now click on the ON button LED is ON .
Now click on the OFF button LED is OFF.
OUTPUT :
So finally LED is ON
Now show the status of the thingSpeak server.
Conclusion :
36
210180107050 COMP607-IOT
From the above practical we demonstrated that using ThingsSpeak cloud through
NodeMCU we can turn on/off the LED using commands from mobile.
Practical – 9
Aim : Controlling Led ON/OFF by giving command using Google
37
210180107050 COMP607-IOT
Assistant from mobile phone. (Use cloud Adafruit)
Components :
Breadboard * 1
ESP32 Module * 1
USB Cable * 1
LED
Account on AdaFruit IO
Account on IFTTT
Procedure :
39
210180107050 COMP607-IOT
Now click on New Feed and then create a New feed. Then it will ask
you to name your feed I am giving it LED_Control, you can give
according to you and then create and your feed is created.
40
210180107050 COMP607-IOT
Now open your new dashboard by simply clicking on it and you should be
taken to a mostly blank page. Clicking on blue + button will let you add new
UI components to the dashboard.
For this practical I just need a button, so select first option, it will ask you to select the
feed, so select the one you just made and keep the defaults for the rest of the settings.
41
210180107050 COMP607-IOT
During programming you will required your unique AIO key so for
this click on key button at right hand corner of your window on My
Key option.
After clicking on key button your Active key for this project is
generated, don’t share this key with anyone this must be confidential.
42
210180107050 COMP607-IOT
After clicking on New applet you will find a window which ask you ‘If this
then that’. The term IF THIS THEN THAT means if something happens
on the “This” then we have do something on “that”.
43
210180107050 COMP607-IOT
Click on + blue button and search for “Google Assistant”, and then select
“Say a simple phrase” from the menu of specific triggers. This will ask you
some details, fill according to you and create trigger.
44
210180107050 COMP607-IOT
Once you have created this applet, you have to create another applet for turning
the LED “OFF”. You have to follow the same steps to create another applet.
After creating both the applets go to “My Applets” and you can see both
the applets here.
45
210180107050 COMP607-IOT
46
210180107050 COMP607-IOT
After installing this library We are ready to use Adafruit IO with the ESP32.
Code :
#include <WiFi.h>
#include "Adafruit_MQTT.h"
#include
"Adafruit_MQTT_Client.h"
#define WLAN_SSID
"Ashi
sh"
#define WLAN_PASS "12345678"
#define AIO_SERVER
"io.adafruit.c
om" #define AIO_SERVERPORT
1883
#define AIO_USERNAME "DURGESH_SINGH"
#define AIO_KEY
"aio_OQrD206pQvpMfzJhKcPPXBnw79
DL" int output=2;
WiFiClient client; // Create an ESP8266 WiFiClient class to connect to the MQTT
server. Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT,
47
210180107050 COMP607-IOT
AIO_USERNAME, AIO_KEY); // Setup the MQTT client class by passing in the
WiFi client and MQTT server and login details.
Adafruit_MQTT_Subscribe LED_Control = Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME
"/feeds/LED_Control"); void
MQTT_connect();
void setup() {
Serial.begin(1152
00); delay(10);
pinMode(2,OUTP
UT);
// Connect to WiFi access point.
Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);
WiFi.begin(WLAN_SSID,
WLAN_PASS);
while (WiFi.status() !=
WL_CONNECTED) { delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi
connected");
Serial.println("IP address: "); Serial.println(WiFi.localIP());
mqtt.subscribe(&LED_Control);
}
uint32_t
x=0;
void
loop() {
MQTT_connect();
Adafruit_MQTT_Subscribe
48
210180107050 COMP607-IOT
*subscription;
while ((subscription =
mqtt.readSubscription(5000))) { if (subscription
== &LED_Control) { Serial.print(F("Got: "));
Serial.println((char *)LED_Control.lastread);
if (!strcmp((char*) LED_Control.lastread, "ON"))
{
digitalWrite(2, HIGH);
}
else
{
digitalWrite(2, LOW);
}
}
}
}
void
MQTT_connect()
{ int8_t ret;
// Stop if already
connected. if
(mqtt.connected()) {
return;
}
Serial.print("Connecting to
MQTT... "); uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5
seconds..."); mqtt.disconnect();
delay(5000); // wait 5
seconds retries--;
if (retries == 0) {
// basically die and wait for WDT to reset
me while (1);
49
210180107050 COMP607-IOT
}
}
Serial.println("MQTT Connected!");
}
OUTPUT :
After uploading of code open your serial monitor and your serial monitor should
look like this:
Now open Google assistant in your Android and give voice command like “Turn
LED on” or “Turn LED off” and it will respond you like you defined earlier and
you will observe change of LED state also.
50
210180107050 COMP607-IOT
Conclusion :
From the above practical we demonstrated that using ESP32 Module with
arduino uno we can control led on/off by giving command from google
assistant and using cloud Adafruit.
Practical – 10
Components required :
Rasperry Pi 3 Setup
Resistor Pack
Red LED * 1
Breadboard * 1
Jumper wires
Configuration :
51
210180107050 COMP607-IOT
Figure :
Procedure :
52
210180107050 COMP607-IOT
The first step in this project is to design a simple LED circuit. Then we will make the
LED circuit controllable from the Raspberry Pi by connecting the circuit to the general
purpose input/output (GPIO) pins on the Raspberry Pi.
A simple LED circuit consists of a LED and resistor. The resistor is used to limit the
current that is being drawn and is called a current limiting resistor. Without the resistor
the LED would run at too high of a voltage, resulting in too much current being drawn
which in turn would instantly burn the LED, and likely also the GPIO port on the
Raspberry Pi.
To calculate the resistor value we need to examine the specifications of the LED.
Specifically we need to find the forward voltage (VF) and the forward current (IF). A
regular red LED has a forward voltage (VF) of 1.7V and forward current of 20mA (IF).
Additionally we need to know the output voltage of the Raspberry Pi which is 3.3V.
We can then calculate the resistor size needed to limit the current to the LED’s maximum
forward current (IF) using ohm’s law like this:
RΩ=VI=3.3–VFIF=3.3–1.720mA=80Ω
Unfortunately 80 ohm is not a standard size of a resistor. To solve this we can either
combine multiple resistors, or round up to a standard size. In this case we would round
up to 100 ohm.
With the value calculated for the current limiting resistor we can now hook the LED and
resistor up to GPIO pin 8 on the Raspberry Pi. The resistor and LED needs to be in series
like the diagram below. To find the right resistor use the resistor color code – for a
100 ohm
resistor it needs to be brown-black-brown. You can use your multimeter to double check
the resistor value.
When hooking up the circuit note the polarity of the LED. You will notice that the LED
has a long and short lead. The long lead is the positive side also called the anode, the
short lead is the negative side called the cathode. The long should be connected to the
resistor and the short lead should be connected to ground via the blue jumper wire and
pin 6 on the Raspberry Pi as shown on the diagram.
With the circuit created we need to write the Python script to blink the LED. Before we
start writing the software we first need to install the Raspberry Pi GPIO Python module.
This is a library that allows us to access the GPIO port directly from Python.
To install the Python library open a terminal and execute the following
With the library installed now open your favorite Python IDE (I recommend Thonny
Python IDE more information about using it here).
53
210180107050 COMP607-IOT
To initialize the GPIO ports on the Raspberry Pi we need to first import the Python
library, the initialize the library and setup pin 8 as an output pin.
Code :
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
from time import sleep # Import the sleep function from the time
GPIO.output(8, GPIO.HIGH) #
second GPIO.output(8,
# Sleep for 1
second
from time import sleep # Import the sleep function from the time module
GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW) # Set pin 8 to be an output pin and set initial
value to low (off)
GPIO.output(8, GPIO.HIGH) #
second GPIO.output(8,
With our program finished, save it as blinking_led.py and run it either inside your IDE
or in the console with:
54
210180107050 COMP607-IOT
$ python blinking_led.py
OUTPUT :
Conclusion :
From the above practical we demonstrated that how to install Raspbian OS in Raspberry
Pi and perform basic operation like LED on/off.
55