22ISE464 IoT Lab Manual
22ISE464 IoT Lab Manual
Course Outcomes: At the end of the Course, the Student will be able to:
CO/PO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1 2 3 3 2 1 2 1 1 2 - - 2
CO2 3 2 3 2 1 2 1 1 2 - - 2
CO3 2 3 2 2 1 2 1 1 2 - - 1
CO4 3 3 3 2 1 2 1 1 2 - - 2
Pre-requisite: NIL
S.
Experiment Name
No
1 To interface LED/ Buzzer with Arduino/Raspberry Pi and write a program to turn
ON LED/ Buzzer for 1 sec after every 2 seconds.
2 To interface Digital sensor (IR/LDR) with Arduino/Raspberry Pi and write a
program to turn ON LED at sensor detection.
To interface smoke sensor with Arduino/Raspberry Pi and write a program to turn
3
on alarm when smoke is detected.
4 To interface DHT11 sensor with Arduino/Raspberry Pi and write a program to print
temperature and humidity readings.
To interface TCS3200 Color Sensor with Arduino to detect the colors and display
5 the same.
To interface Bluetooth with Arduino/Raspberry Pi and write a program to turn LED
6 ON/OFF when ‘1’/’0’ is received from smart phone using Bluetooth.
Create an application that has three LEDs (Red, Green and white). The LEDs
10 should follow the cycle (All Off, Red On, GreenOn, WhiteOn) for each hand
movement (use Ultrasonic sensor).
To interface soil moisture sensor to display the quality of soil moisture values
11 using Arduino/RaspberryPI
Tests(50Marks)
Bloom’s Category
Remember -
Understand 10
Apply 10
Analyze -
Evaluate -
Create 30
SEE–Semester End Examination (50Marks)
Arduino:
Features of Arduino:
1. USB: can be used for both power and communication with the IDE
2. Barrel Jack: used for power supply
3. Voltage Regulator: regulates and stabilizes the input and output voltages
4. Crystal Oscillator: keeps track of time and regulates processor frequency
5. Reset Pin: can be used to reset the Arduino Uno
6. 3.3V pin: can be used as a 3.3V output
7. 5V pin: can be used as a 5V output
8. GND pin: can be used to ground the circuit
9. Vin pin: can be used to supply power to the board
10. Analog pins(A0-A5): can be used to read analog signals to the board
11. Microcontroller(ATMega328): the processing and logical unit of the board
12. ICSP pin: a programming header on the board also called SPI
13. Power indicator LED: indicates the power status of the board
14. RX and TX LEDs: receive(RX) and transmit(TX) LEDs, blink when sending or
receiving serial data respectively
15. Digital I/O pins: 14 pins capable of reading and outputting digital signals; 6 of these
pins are also capable of PWM
16. AREF pins: can be used to set an external reference voltage as the upper limit for the
analog pins
17. Reset button: can be used to reset the board
Read the Arduino License agreement and click the “I Agree” button.
Steps to follow
Connect the Arduino to your computer and open the Arduino IDE.
Copy and paste the code above into the IDE.
Select the correct board and serial port from the tools menu.
Upload the code to the Arduino board.
Open the serial monitor and you should see the message “Hello World!”
displayed.
Open Tools, Board, and here choose Arduino UNO as displayed in the following screenshot:
Open Tools, Port, and select the correct port (remember the last COM xx number), as
indicated in the following screenshot
void setup() {
Serial.begin(9600);
void loop() {
Serial.println("Hello World!");
delay(1000);
Now open Serial Monitor to Check the Result Now the “Hello World!” message prints on the
serial monitor every second.
Hardware Requirements:
1. 1x Breadboard
2. 1x Arduino Uno R3
3. 1x RGB LED
5.2x Jumper Wires
Procedure:
1. Connect the Arduino board to your computer using the USB cable.
2. Set the pin-mode as LED output.
3. Set the delay time for output
4. Set the digital pin-mode on.
5. Set the digital pin-mode off.
Source Code:
void setup() {
pinMode(12, OUTPUT);
void loop() {
digitalWrite(12, HIGH);
delay(5000);
digitalWrite(12, LOW);
delay(1000);
OUTPUT:
OUTPUT
LED interfacing is done successfully.
Expt 1.B: To interface buzzer with Arduino/Raspberry Pi and write a program to turn ON
and OFF periodically.
Hardware Requirements:
1. 1x Breadboard
2. 1x Arduino Uno R3
3. 1x Buzzer
4. 2x Jumper Wires
Procedure:
1. Connect the Arduino board to your computer using the USB cable.
2. Set the pin-mode as Buzzer output.
3. Set the delay time for output
4. Set the digital pin-mode on.
5. Set the digital pin-mode off.
Source Code:
void setup() {
pinMode(12, OUTPUT);
void loop() {
digitalWrite(12, HIGH);
delay(5000);
digitalWrite(12, LOW);
delay(1000);
OUTPUT:
OUTPUT
Buzzer interfacing is done successfully.
Expt 2: To interface Digital sensor (IR) with Arduino/Raspberry Pi and write a program to
turn ON LED when push button is pressed or at sensor detection.
Hardware Requirements:
Source code:
int IRPin = 3;
int led=13;
int value;
void setup(){
pinMode(IRPin, INPUT);
Serial.begin(9600);
pinMode(13,OUTPUT);
void loop(){
value = digitalRead(IRPin);
Serial.println(value);
if(digitalRead(IRPin)==1)
digitalWrite(led,HIGH);
else
digitalWrite(led,LOW);
OUTPUT:
Hardware Requirements
1. Arduino UNO
2. BreadBoard
3. Jumper
5. Piezo Buzzer
A0 Analog pins
D0 Digital pins
GND GND
VCC 5V
Program
int SensorVal = 0;
int buzzer=11;
void setup() {
Serial.begin(9600);
pinMode(Input, INPUT);
pinMode(buzzer,OUTPUT);
void loop() {
SensorVal = analogRead(Input);
Serial.println(SensorVal);
delay(500);
if(SensorVal>600)
digitalWrite(buzzer,HIGH);
else
digitalWrite(buzzer,LOW);
OUTPUT
The buzzer alarms when the smoke level increases the threshold.
Expt 4: To interface DHT11 sensor with Arduino/Raspberry Pi and write a program to print
temperature and humidity readings.
Hardware Requirements:
Procedure:
NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
4. Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
Source Code:
/*
Connect + to 5V
Connect out A0
Connect - to GND
*/
#include <dht.h>
dht DHT;
void setup()
Serial.begin(9600);
delay(500);
delay(1000);
void loop()
DHT.read11(dht_pin);
Serial.print("Humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("Temperature = ");
Serial.print(DHT.temperature);
Serial.println(" C");
#include "DHT.h"
#define DHTTYPE DHT11
DHT dht(A0, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}
OUTPUT:
OUTPUT
Expt 5: TCS3200 Color Sensor interfacing with Arduino to detect the colors.
Hardware Requirements
Arduino UNO
Jumper wires
Program
/*
Sensor Pin S0 -> Arduino Pin D8
Sensor Pin S1 -> Arduino Pin D7
Sensor Pin S2 -> Arduino Pin D6
Sensor Pin S3 -> Arduino Pin D5
Sensor Pin OUT -> Arduino Pin D4
VCC- 5V
GND- GND
*/
#define S0_PIN 8
#define S1_PIN 7
#define S2_PIN 6
#define S3_PIN 5
#define OUT_PIN 4
void setup()
{
void loop()
{
int r, g, b;
r = process_red_value();
delay(200);
g = process_green_value();
delay(200);
b = process_blue_value();
delay(200);
Serial.print("r = ");
Serial.print(r);
Serial.print(" ");
Serial.print("g = ");
Serial.print(g);
Serial.print(" ");
Serial.print("b = ");
Serial.print(b);
Serial.print(" ");
Serial.println();
if (b < 42)
{
Serial.println("Colour Blue");
}
else if (g < 63)
{
Serial.println("Colour Green");
}
else if (r < 64)
{
Serial.println("Colour Red");
}
}
int process_red_value()
{
digitalWrite(S2_PIN, LOW);
digitalWrite(S3_PIN, LOW);
int pulse_length = pulseIn(OUT_PIN, LOW);
return pulse_length;
}
int process_green_value()
{
digitalWrite(S2_PIN, HIGH);
digitalWrite(S3_PIN, HIGH);
int pulse_length = pulseIn(OUT_PIN, LOW);
return pulse_length;
}
int process_blue_value()
{
digitalWrite(S2_PIN, LOW);
digitalWrite(S3_PIN, HIGH);
int pulse_length = pulseIn(OUT_PIN, LOW);
return pulse_length;
}
Exp 6:To interface Bluetooth with Arduino/Raspberry Pi and write a program t o turn LED ON/OFF
when ‘1’/’0’ is received from smart phone using Bluetooth.
Hardware Requirements:
1. Arduino UNO
There are three main parts to this project. An Android smart phone, a Bluetooth transceiver, and an
Arduino.
SOURCE CODE:
#include <SoftwareSerial.h>
void setup() {
Bluetooth.begin(9600);
Serial.begin(9600);
pinMode(LED,OUTPUT);
void loop() {
Data=Bluetooth.read();
if(Data=='1'){
digitalWrite(LED,1);
Serial.println("LED On!");
Bluetooth.println("LED On!");
else if(Data=='0'){
digitalWrite(LED,0);
Serial.println("LED Off!");
else{;}
delay(100);
OUTPUT:
Hardware Requirements
1. Arduino UNO
2. BreadBoard
3. UltraSonic SensorHC-SR04
4. LED
5. Jumper wires
VCC 5V
Trig Pin 11
Echo Pin 12
GND GND
Program
/*
VCC: +5VDC
GND: GND
*/
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(250);
OUTPUT
Expt 8: To interface float sensor to detect water level in over head tanks and warn the
overflow using Arduino/Raspberry PI with an LED
Hardware Requirements
1. Arduino UNO
2. Float Sensor
3. LED
4. BreadBoard
5. Jumper Wires
Program
int FloatSensor=10;
int led=13;
void setup()
Serial.begin(9600);
void loop()
buttonState = digitalRead(FloatSensor);
if (buttonState == HIGH)
{digitalWrite(led, HIGH);
else
{digitalWrite(led, LOW);
delay(1000);
OUTPUT
After uploading the code successfully, we can see when water level goes up led attached will
get turn on and when water level goes down led will get turn off.
int RawMin = 0;
void setup()
analogReference(EXTERNAL);
Serial.begin(9600);
void loop()
// re-scale to fractional Gs
Serial.print("X, Y, Z :: ");
Serial.print(xRaw);
Serial.print(", ");
Serial.print(yRaw);
Serial.print(", ");
Serial.print(zRaw);
Serial.print(" :: ");
Serial.print(xAccel,0);
Serial.print("G, ");
Serial.print(yAccel,0);
Serial.print("G, ");
Serial.print(zAccel,0);
Serial.println("G");
delay(200);
long reading = 0;
analogRead(axisPin);
delay(1);
reading += analogRead(axisPin);
return reading/sampleSize;
OUTPUT
Expt 10: Create an application that has three LEDs (Red, Green and white). The LEDs
should follow the cycle (All Off, Red On, Green On, White On) for each hand
movement (use Ultrasonic sensor).
Hardware Requirements:
2. Breadboard
5. Jumper wires.
Connect the three LEDs to the Arduino board using jumper wires. Connect the anode
(positive leg) of each LED to a digital pin on the Arduino board (Red to pin 2, Green to pin 3,
White to pin 4). Connect the cathode (negative leg) of each LED to the ground pin on the
Arduino board.
Connect the ultrasonic sensor module to the Arduino board using jumper wires. Connect the
VCC pin to the 5V pin on the Arduino board, GND to the ground pin on the board, Trig to
pin 9, and Echo to pin 10.
Program
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(whitePin, OUTPUT);
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
delay(500);
delay(500);
delay(500);
delay(500);
OUTPUT
Upload the code to the Arduino board and test the application.When you clap, the ultrasonic
sensor detects the sound and triggers the LED cycle: Red on, Green on, White on, and All
off.
Note: You may need to adjust the distance threshold (currently set to 50) to suit our
environment. Also, make sure the ultrasonic sensor is positioned properly to detect your
claps.
EXPT 11: To interface soil moisture sensor to display the quality of soil moisture values
using Arduino/RaspberryPI
Hardware Requirements:
1. Arduino UNO
2. Soil Moisture Sensor., FC-28
3. Jumper Wires.
Program
delay(2000);
}
void loop()
{
outputValue= analogRead(sensorPin);
outputValue = map(outputValue,550,0,0,100);
Serial.print("Moisture Value : ");
Serial.print(outputValue);
Serial.println("%");
delay(1000);
}
OUTPUT
Exp 12: Write a program on Arduino/Raspberry Pi to upload temperature and humidity data to
cloud.
Hardware Requirements:
Procedure:
2. Connect Node MCU, Go to tools->change board to Node MCU esp8266 and port number
5. SSID and password of your WIFI connection should be given in source code
6. Compile and upload the program and verify the temperature and humidity readings in serial
monitor
SOURCE CODE:
#include <DHT.h>
#include <DHT_U.h>
#include <DHT.h>
#include <ESP8266WiFi.h>
#define DHTPIN 0
WiFiClient client;
void setup()
Serial.begin(115200);
delay(10);
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
delay(500);
Serial.print(".");
Serial.println("");
Serial.println("WiFi connected");
void loop()
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
return;
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "\r\n\r\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-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(h);
client.stop();
Serial.println("Waiting...");
delay(10000);
OUTPUT:
ADDITIONAL EXPERIMENT
Hardware Requirements
2. Arduino UNO
3. LED
4. Jumper Cables
5V – connect to 5V
Program
void setup() {
void loop(){
if (state == LOW) {
Serial.println("Motion detected!");
else {
if (state == HIGH){
Serial.println("Motion stopped!");
OUTPUT