CS-801 Iot Lab - Manual
CS-801 Iot Lab - Manual
CS-801 Iot Lab - Manual
DEPARTMENT
OF
INFORMATION TECHNOLOGY
LAB MANUAL (CS-801)
Name:
Semester: ___________________________________
Branch: _____________________________________
1
Laboratory Manual
Internet of Things Lab (CS-801) 2023
Upon the completion of IOT Laboratory, the student will be able to:
3
Publishing/Subscribing to connect, collect data, monitor and manage assets
2
Laboratory Manual
Internet of Things Lab (CS-801) 2023
LIST OF EXPERIMENTS
S. No Name of Experiment Page No. Course
Outcome
Familiarization With Arduino/Raspberry Pi And Perform
1 Necessary Software Installation.
1
5 Study the Temperature sensor and Write Program for monitor 1,5
temperature using Arduino.
3
Laboratory Manual
Internet of Things Lab (CS-801) 2023
EXPERIMENT NO.1
OBJECTIVES: student should get the knowledge of Arduino ide and different
types of Arduino board
Arduino:
Development Environment), which is used to write and upload the computer code
Arduino provides a standard form factor that breaks the functions of the micro-
4
Laboratory Manual
Internet of Things Lab (CS-801) 2023
Development Environment), which is used to write and upload the computer code
• Arduino boards are able to read analog or digital input signals from different
sensors and turn it into an output such as activating a motor, turning LED on/off,
• You can control your board functions by sending a set of instructions to the
• Unlike most previous programmable circuit boards, Arduino does not need
an extra piece of hardware (called a programmer) in order to load a new code onto
• Finally, Arduino provides a standard form factor that breaks the functions of
• Get the latest version from the arduino.cc web site. You can choose between
the Installer (.exe) and the Zip packages. We suggest you use the first one that
5
Laboratory Manual
Internet of Things Lab (CS-801) 2023
installs directly everything you need to use the Arduino Software (IDE), including
the drivers. With the Zip package you need to install the drivers manually. The Zip
• When the download finishes, proceed with the installation and please allow
the driver installation process when you get a warning from the operating system.
6
Laboratory Manual
Internet of Things Lab (CS-801) 2023
• Choose the installation directory (we suggest to keep the default one)
7
Laboratory Manual
Internet of Things Lab (CS-801) 2023
• The process will extract and install all the required files to execute properly
• When the Arduino Software (IDE) is properly installed you can go back to
the IDE.
Arduino USB
1. Arduino Uno
This is the latest revision of the basic Arduino USB board. It connects to the
computer with a standard USB cable and contains everything else you need to
2. Arduino NG REV-C
Revision C of the Arduino NG does not have a built-in LED on pin 13 - instead
you'll see two small unused solder pads near the labels "GND" and "13".
Arduino Bluetooth
8
Laboratory Manual
Internet of Things Lab (CS-801) 2023
ATmega168, but now is supplied with the 328, and the Bluegiga WT11 bluetooth
Arduino Mega
The original Arduino Mega has an ATmega1280 and an FTDI USB-to- serial chip.
Arduino NANO
The Arduino Nano 3.0 has an ATmega328 and a two-layer PCB. The power LED
9
Laboratory Manual
Internet of Things Lab (CS-801) 2023
EXPERIMENT NO.2
OBJECTIVES: Student should get the knowledge of Arduino board and different
types of LED.
OUTCOMES: Student will be write program using Arduino ide for blink LED
HARDWARE REQUIREMENTS:
• 1X BREADBOARD
• 1X ARDUINO UNO R3
• 1X RGB LED
• 1X 330Ω RESISTOR
• 2X JUMPER WIRES BLINKING THE RGB LED
With a simple modification of the breadboard, we could attach the led to an output
pin of the Arduino. Move the red jumper wire from the ARDUINO 5v connector to
10
Laboratory Manual
Internet of Things Lab (CS-801) 2023
now load the 'blink' example sketch from lesson 1. you will notice that both the
built-in 'l' LED and the external LED should now blink.
/*
2. blink
3. turns on an led on for one second, then off for one second, repeatedly. 4.
5. this example code is in the public domain. 6. */
7.
8. // pin 13 has an led connected on most arduino boards.
9. // give it a name:
10. int led = 13;
11.
12. // the setup routine runs once when you press reset:
11
Laboratory Manual
Internet of Things Lab (CS-801) 2023
lets try using a different pin of the Arduino – say D7. Move the red jumper lead
from pin d13 to pin d7 and modify the following line near the top of the sketch:
1. int led = 13;
so that it reads:
1. int led = 7;
Upload the modified sketch to your Arduino board and the led should still be
blinking, but this time using pin D7.
12
Laboratory Manual
Internet of Things Lab (CS-801) 2023
EXPERIMENT NO.3
OUTCOMES: Student will be Write program using Arduino IDE for Blink LED
HARDWARE REQUIREMENTS:
1x Breadboard
1x Arduino Uno R3
1x RGB LED
1x 330Ω Resistor
2x Jumper Wires
13
Laboratory Manual
Internet of Things Lab (CS-801) 2023
/*
2. Blink
3. Turns on an LED on for one second, then off for one second,
repeatedly. 4.
5. This example code is in the public
domain. 6. */
7.
8. // Pin 13 has an LED connected on most Arduino boards.
9. // give it a name:
10. int
led = 13;
11.
12. // the setup routine runs once when you press reset:
13. void setup() {
14. // initialize the digital pin as an output.
15. pinMode(led, OUTPUT);
1
6
.
}
1
7
.
18. // the loop routine runs over and over again forever:
19. void loop() {
20. digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
21. delay(1000); // wait for a second
22. digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
23. delay(1000); // wait for a second
14
Laboratory Manual
Internet of Things Lab (CS-801) 2023
24.}
Lets try using a different pin of the Arduino – say D7. Move the red jumper lead
from pin D13 to pin D7 and modify the following line near the top of the sketch:
1. int led = 13;
so that it reads:
1. int led = 7;
Upload the modified sketch to your Arduino board and the LED should still be
blinking, but this time using pin D7.
15
Laboratory Manual
Internet of Things Lab (CS-801) 2023
EXPERIMENT NO.4
OBJECTIVES: student should get the knowledge of Arduino ide and RGB led
• 1X BREADBOARD
• 1X ARDUINO UNO R3
• 1X LED
• 1X 330Ω RESISTOR
• 2X JUMPER WIRES
BLINKING THE LED
With a simple modification of the breadboard, we could attach the led to an output
pin of the Arduino. Move the red jumper wire from the Arduino 5v connector to
D13, as shown below:
16
Laboratory Manual
Internet of Things Lab (CS-801) 2023
now load the 'blink' example sketch from lesson 1. You will notice that both the
built-in 'l' led and the external led should now blink.
The following test sketch will cycle through the colors red, green, blue, yellow,
purple, and aqua. These colors being some of the standard internet colors.
1. /*
2. adafruit arduino - lesson 3. rgb led
3. */
4.
5. int redPin = 11;
6. int greenPin = 10;
7. int bluePin = 9;
8.
9. //uncomment this line if using a common anode led
10.//#define common_anode
11.
12. void setup()
17
Laboratory Manual
Internet of Things Lab (CS-801) 2023
13.{
14. pinmode(redPin, output);
15. pinmode(greenPin, output);
16. pinmode(bluePin, output);
17.}
18.
19. void loop()
20.{
21. setcolor(255, 0, 0); // red
22. delay(1000);
23. setcolor(0, 255, 0); // green
24. delay(1000);
25. setcolor(0, 0, 255); // blue
26. delay(1000);
27. setcolor(255, 255, 0); // yellow
28. delay(1000);
29. setcolor(80, 0, 80); // purple
30. delay(1000);
31. setcolor(0, 255, 255); // aqua
32. delay(1000);
33.}
34.
35. void setcolor(int red, int green, int blue)
36.{
37. #ifdef common_anode
18
Laboratory Manual
Internet of Things Lab (CS-801) 2023
19
Laboratory Manual
Internet of Things Lab (CS-801) 2023
This function takes three arguments, one for the brightness of the red, green and
blue LEDS. In each case the number will be in the range 0 to 255, where 0 means
off and 255 means maximum brightness. The function then calls 'analogwrite' to
set the brightness of each led.
if you look at the 'loop' function you can see that we are setting the amount of red,
green and blue light that we want to display and then pausing for a second before
moving on to the next color.
1. void loop()
2. {
3. setcolor(255, 0, 0); // red
4. delay(1000);
5. setcolor(0, 255, 0); // green
6. delay(1000);
7. setcolor(0, 0, 255); // blue
8. delay(1000);
9. setcolor(255, 255, 0);// yellow
10. delay(1000);
11. setcolor(80, 0, 80); // purple
12. delay(1000);
13. setcolor(0, 255, 255);// aqua
14. delay(1000);
15.}
Try adding a few colors of your own to the sketch and watch the effect on
your
20
Laboratory Manual
Internet of Things Lab (CS-801) 2023
EXPERIMENT NO.5
AIM: Study the temperature sensor and write program foe monitor
temperature using Arduino.
OBJECTIVES: student should get the knowledge of temperature sensor
21
Laboratory Manual
Internet of Things Lab (CS-801) 2023
Remember that you can use anywhere between 2.7v and 5.5v as the power supply.
for this example i'm showing it with a 5v supply but note that you can use this with
a 3.3v supply just as easily. no matter what supply you use, the analog voltage
reading will range from about 0v (ground) to about 1.75v.
if you're using a 5v arduino, and connecting the sensor directly into an analog pin,
you can use these formulas to turn the 10-bit analog reading into a temperature:
VOLTAGE AT PIN IN MILLIVOLTS = (reading from adc) * (5000/1024)
this formula converts the number 0-1023 from the adc into 0-5000mv (= 5v) if
you're using a 3.3v arduino, you'll want to use this:
VOLTAGE AT PIN IN MILLIVOLTS = (reading from adc) * (3300/1024)
this formula converts the number 0-1023 from the adc into 0-3300mv (= 3.3v)
then, to convert millivolts into temperature, use this formula:
CENTIGRADE TEMPERATURE = [(analog voltage in mv) - 500] / 10
simple thermometer
22
Laboratory Manual
Internet of Things Lab (CS-801) 2023
This example code for Arduino shows a quick way to create a temperature sensor,
it simply prints to the serial port what the current temperature is in both Celsius
and Fahrenheit.
1. //TMP36 Pin Variables
2. int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is
connected to
3. //the resolution is 10 mV / degree centigrade with a
4. //500 mV offset to allow for negative temperatures 5.
6. /*
7. * setup() - this function runs once when you turn your Arduino on
8. * We initialize the serial connection with the computer 9. */
10. void setup()
11.{
12. Serial.begin(9600); //Start the serial connection with the computer
13. //to view the result open the serial monitor
14.}
15.
16. void loop() // run over and over again
17.{
18. //getting the voltage reading from the temperature sensor
19. int reading = analogRead(sensorPin); 20.
21. // converting that reading to voltage, for 3.3v arduino use 3.3
22. float voltage = reading * 5.0; 23. voltage /= 1024.0;
24.
25. // print out the voltage
23
Laboratory Manual
Internet of Things Lab (CS-801) 2023
24
Laboratory Manual
Internet of Things Lab (CS-801) 2023
EXPERIMENT NO.6
SCHEMATIC:
Follow the next schematic diagram to wire the DHT11 (or DHT22) temperature
Pin 1 5V
25
Laboratory Manual
Internet of Things Lab (CS-801) 2023
Pin 4 GND
Installing Libraries
To read from the DHT sensor, we’ll use the DHT library from Adafruit. To use this
library you also need to install the Adafruit Unified Sensor library. Follow the next
steps to install those libraries.
Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries.
The Library Manager should open.
Search for “DHT” on the Search box and install the DHT library from Adafruit.
26
Laboratory Manual
Internet of Things Lab (CS-801) 2023
Code
After installing the necessary libraries, you can upload an example code from the
library.
In your Arduino IDE, go to File > Examples > DHT Sensor library > DHTtester
The following code should load. It reads temperature and humidity, and displays
the results in the Serial Monitor.
#include "DHT.h"
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
28
Laboratory Manual
Internet of Things Lab (CS-801) 2023
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hi);
Serial.println(" *F");
Demonstration
After uploading the code to the Arduino, open the Serial Monitor at a baud rate of
9600. You should get sensor readings every two seconds. Here’s what you should
see in your Arduino IDE Serial Monitor.
29
Laboratory Manual
Internet of Things Lab (CS-801) 2023
EXPERIMENT NO.7
Hardware Required
1 × Arduino UNO
1 × USB 2.0 cable type A/B
1 × Button
1 × Relay
1 × 12V Power Adapter
1 × Breadboard
1 × Jumper Wires
/*
* Code for Relay & Motor
*/
void setup() {
Serial.begin(9600); // initialize serial
pinMode(BUTTON_PIN, INPUT_PULLUP); // set arduino pin to input pull-up
mode
pinMode(RELAY_PIN, OUTPUT); // set arduino pin to output mode
30
Laboratory Manual
Internet of Things Lab (CS-801) 2023
void loop() {
int buttonState = digitalRead(BUTTON_PIN); // read new state
if (buttonState == LOW) {
Serial.println("The button is being pressed");
digitalWrite(RELAY_PIN, HIGH); // turn on
}
else
if (buttonState == HIGH) {
Serial.println("The button is unpressed");
digitalWrite(RELAY_PIN, LOW); // turn off
}
}
31
Laboratory Manual
Internet of Things Lab (CS-801) 2023
EXPERIMENT NO.8
AIM: To interface OLED with Arduino/Raspberry Pi and write a program to print
temperature and humidity readings on it.
OBJECTIVES: student should get the knowledge of Relay & motor.
OUTCOMES: student will be developed programs using Arduino IDE and
Arduino board Relay and Motor.
Hardware Required
Introduction
The DHT22 is a basic, low-cost digital temperature and humidity sensor. It uses a
capacitive humidity sensor and a thermistor to measure the surrounding air, and
spits out a digital signal on the data pin (no analog input pins needed). It’s easy to
use, but requires careful timing to grab data. The only real downside of this sensor
is you can only get new data from it once every 2 seconds, so when using our
library, sensor readings can be up to 2 second
#include <SPI.h>
#include <Wire.h>
32
Laboratory Manual
Internet of Things Lab (CS-801) 2023
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHT.h"
#define DHTPIN 2
#define PIEZO 8
33
Laboratory Manual
Internet of Things Lab (CS-801) 2023
char inChar;
String inString;
void setup() {
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
display.clearDisplay();
dht.begin();
void loop() {
delay(2000);
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
return;
35
Laboratory Manual
Internet of Things Lab (CS-801) 2023
displayOled();
playSound();
else {
displayOled();
noTone(PIEZO);
void displayOled() {
// Read humidity
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
36
Laboratory Manual
Internet of Things Lab (CS-801) 2023
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(5, 15);
display.print("Humidity:");
display.setCursor(80, 15);
display.print(h);
display.print("%");
display.setCursor(5, 30);
display.print("Temperature:");
display.setCursor(80, 30);
display.print(t);
display.print("C");
display.setCursor(5, 45);
display.print("Heat Index:");
37
Laboratory Manual
Internet of Things Lab (CS-801) 2023
display.setCursor(80, 45);
display.print(hic);
display.print("C");
display.display();
pinMode(PIEZO, OUTPUT);
delay(pauseBetweenNotes);
noTone(PIEZO);
38
Laboratory Manual
Internet of Things Lab (CS-801) 2023
EXPERIMENT NO.9
MQTT:
39
Laboratory Manual
Internet of Things Lab (CS-801) 2023
MQTT METHODS
CONNECT
DISCONNECT
Waits for the MQTT client to finish any work it must do, and for the TCP/IP
session to disconnect.
SUBSCRIBE
UNSUBSCRIBE
Requests the server unsubscribe the client from one or more topics.
PUBLISH
Returns immediately to the application thread after passing the request to the
MQTT client.
40
Laboratory Manual
Internet of Things Lab (CS-801) 2023
EXPERIMENT NO.10
RASPBERRY PI
According to the Raspberry Pi Foundation, over 5 million Raspberry Pis have been
sold before February 2015, making it the best-selling British computer.[8] By
November 2016 they had sold 11 million units[9][10], reaching 12.5m in March
2017, making it the third best-selling "general purpose computer" ever.
To get started with Raspberry Pi, you need an operating system. NOOBS (New
Out Of Box Software) is an easy operating system install manager for the
Raspberry Pi.
41
Laboratory Manual
Internet of Things Lab (CS-801) 2023
1. GO to the https://www.raspberrypi.org/downloads/
2. Click on NOOBS, then click on the Download ZIP button under ‘NOOBS
(offline and network install)’, and select a folder to save it to.
It is best to format your SD card before copying the NOOBS files onto it. To do
this:
3. Insert your SD card into the computer or laptop’s SD card reader and make a
note of the drive letter allocated to it, e.g. G:/
42
Laboratory Manual
Internet of Things Lab (CS-801) 2023
4. In SD Formatter, select the drive letter for your SD card and format it.
1. Once your SD card has been formatted, drag all the files in the extracted
NOOBS folder and drop them onto the SD card drive.
3. When this process has finished, safely remove the SD card and insert it into
your Raspberry Pi.
FIRST BOOT
3. Your Raspberry Pi will boot, and a window will appear with a list of
different operating systems that you can install. We recommend that you use
Raspbian – tick the box next to Raspbian and click on Install.
4. Raspbian will then run through its installation process. Note that this can
take a while.
The default login for Raspbian is username pi with the password raspberry. Note
that you will not see any writing appear when you type the password. This is a
security feature in Linux.
To load the graphical user interface, type startx and press Enter.
44
Laboratory Manual