0% found this document useful (0 votes)
12 views

22ISE464 IoT Lab Manual

The Internet of Things Lab Manual (22ISE464) outlines a course focused on interfacing IoT devices with platforms like Raspberry Pi and Arduino, with a total of 12 experiments designed to teach students practical skills. The manual includes course outcomes, prerequisites, and detailed procedures for each experiment, including interfacing various sensors and creating simple applications. Assessment methods include continuous internal evaluations and a semester-end examination, emphasizing the application and creation of IoT solutions.

Uploaded by

Jenita Suba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

22ISE464 IoT Lab Manual

The Internet of Things Lab Manual (22ISE464) outlines a course focused on interfacing IoT devices with platforms like Raspberry Pi and Arduino, with a total of 12 experiments designed to teach students practical skills. The manual includes course outcomes, prerequisites, and detailed procedures for each experiment, including interfacing various sensors and creating simple applications. Assessment methods include continuous internal evaluations and a semester-end examination, emphasizing the application and creation of IoT solutions.

Uploaded by

Jenita Suba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

Internet Of Things Lab Manual [22ISE464]

INTERNET OF THINGS LABORATORY

CourseCode :22ISE464 Credits :1


L:T:P:S : 0:0:1:0 CIEMarks : 50
ExamHours : 3 SEEMarks : 50

Course Outcomes: At the end of the Course, the Student will be able to:

CO1 Understand functionalities of various single board embedded platforms fundamentals


CO2 Understanding interfacing IoT devices with Raspberry PI/Arduino
CO3 Apply Raspberry PI/Arduino interfacing to create simple application
CO4 Implement interfacing of various sensors with Raspberry Pi /Arduino.
CO5 Develop automation work-flow in IoT enabled environment

Mapping of Course Outcomes to Program Outcomes:

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.

ISE dept., NHCE Page 1


Internet Of Things Lab Manual [22ISE464]

To interface ultrasonic sensor with Arduino/Raspberry Pi and write a program to


7 display the distance of the obstacle
8 To interface float sensor to detect water level in over head tanks and warn the
overflow using Arduino/Raspberry PI with an LED

To interface ADXL335 accelerometer with Arduino/RaspberryPI to detect the


9 various orientation and display it on serial monitor.

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

Write a program on Arduino/Raspberry Pi to upload temperature and humidity data


12 cloud.
to

For SEE Examination:

One experiment to be given


Examination will be conducted for 50 marks
Marks Distribution : Procedure write-up – 20%
Conduction – 60%
Viva – Voce– 20%
Change of the experiment is allowed only once and procedure write-up marks will be
considered as ‘0’

CIE-Continuous Internal Evaluation(50Marks)

Tests(50Marks)
Bloom’s Category
Remember -
Understand 10
Apply 10
Analyze -
Evaluate -
Create 30
SEE–Semester End Examination (50Marks)

Bloom’s Taxonomy Tests


Remember -
Understand 10
Apply 10
Analyze -
Evaluate -
Create 30

ISE dept., NHCE Page 2


Internet Of Things Lab Manual [22ISE464]

Introduction to Arduino platform and its installation.

Arduino:

 Arduino is an open-source electronics platform based on easy-to-use hardware and


software.
 Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a
Twitter message - and turn it into an output - activating a motor, turning on an LED,
publishing something online.
 We can send a set of instructions to the microcontroller on the Arduino board. To do so
we use the Arduino programming language and the Arduino Software (IDE), based on
Processing.
 Now, Arduino can also help you easily build IoT projects in two ways: Using traditional
Arduino boards and attaching communication breakout modules (like nRF Bluetooth,
WiFi, LoRA, GSM, etc) to them.

Features of Arduino:

 Inexpensive - Arduino boards are relatively inexpensive compared to other


microcontroller platforms.
 Cross-platform - The Arduino Software (IDE) runs on Windows, Macintosh OSX, and
Linux operating systems. Most microcontroller systems are limited to Windows.
 Simple, clear programming environment - The Arduino Software (IDE) is easy-to-use for
beginners, yet flexible enough for advanced users to take advantage of as well.
 Open source and extensible software - The Arduino software is published as open source
tools, available for extension by experienced programmers.

Arduino UNO Hardware Diagram

ISE dept., NHCE Page 3


Internet Of Things Lab Manual [22ISE464]

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

Download and install the Arduino software (Arduino IDE 1.8.5)


 Go to the Arduino website and click the download link to go to the download page.
 After downloading, locate the downloaded file on the computer and extract the folder from the
downloaded zipped file. Copy the folder to a suitable place such as your desktop.

ISE dept., NHCE Page 4


Internet Of Things Lab Manual [22ISE464]

Read the Arduino License agreement and click the “I Agree” button.

ISE dept., NHCE Page 5


Internet Of Things Lab Manual [22ISE464]

The Arduino software will start to install.

Running the Arduino IDE Software

ISE dept., NHCE Page 6


Internet Of Things Lab Manual [22ISE464]

ISE dept., NHCE Page 7


Internet Of Things Lab Manual [22ISE464]

Familiarization with Arduino set up with “Hello World” Program.

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

ISE dept., NHCE Page 8


Internet Of Things Lab Manual [22ISE464]

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.

ISE dept., NHCE Page 9


Internet Of Things Lab Manual [22ISE464]

Expt 1: A. To interface LED with Arduino/Raspberry Pi and write a program to turn ON


LED for 1 sec after every 2 seconds.

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:

//LED small pin - GND

void setup() {

pinMode(12, OUTPUT);

void loop() {

digitalWrite(12, HIGH);

delay(5000);

digitalWrite(12, LOW);

delay(1000);

OUTPUT:

ISE dept., NHCE Page 10


Internet Of Things Lab Manual [22ISE464]

OUTPUT
LED interfacing is done successfully.

ISE dept., NHCE Page 11


Internet Of Things Lab Manual [22ISE464]

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:

//LED, burzer longer pin - pin 12

void setup() {

pinMode(12, OUTPUT);

void loop() {

digitalWrite(12, HIGH);

delay(5000);

digitalWrite(12, LOW);

delay(1000);

OUTPUT:

ISE dept., NHCE Page 12


Internet Of Things Lab Manual [22ISE464]

OUTPUT
Buzzer interfacing is done successfully.

ISE dept., NHCE Page 13


Internet Of Things Lab Manual [22ISE464]

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:

1. Arduino UNO Board


2. IR/LDR
3. LED
4. breadboard

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:

ISE dept., NHCE Page 14


Internet Of Things Lab Manual [22ISE464]

ISE dept., NHCE Page 15


Internet Of Things Lab Manual [22ISE464]

Expt 3: To interface smoke sensor with Arduino/Raspberry Pi and write a program to


turn on alarm when smoke is detected.

Hardware Requirements

1. Arduino UNO

2. BreadBoard

3. Jumper

4. MQ-2 Smoke Sensor

5. Piezo Buzzer

Pin Wiring to Arduino Uno

A0 Analog pins

D0 Digital pins

GND GND

VCC 5V

ISE dept., NHCE Page 16


Internet Of Things Lab Manual [22ISE464]

Program

int Input = A0;

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

ISE dept., NHCE Page 17


Internet Of Things Lab Manual [22ISE464]

digitalWrite(buzzer,LOW);

OUTPUT

The buzzer alarms when the smoke level increases the threshold.

ISE dept., NHCE Page 18


Internet Of Things Lab Manual [22ISE464]

Expt 4: To interface DHT11 sensor with Arduino/Raspberry Pi and write a program to print
temperature and humidity readings.
Hardware Requirements:

1. Arduino UNO Board


2. DHT11 Temperature and Humidity Sensor(3 pins)
3. Jumper Wires
4. Bread Board

Procedure:

1. Connect pin 1 (on the left) of the sensor to +5V

NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1

// to 3.3V instead of 5V!

2. Connect pin 2 of the sensor to whatever your DHTPIN is

3. Connect pin 4 (on the right) of the sensor to GROUND

4. Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

ISE dept., NHCE Page 19


Internet Of Things Lab Manual [22ISE464]

Source Code:

/*

DHT11 Temperature and Humidity Sensor With Arduino

Download from DHT sensor library - Arduino Libraries

DHT sensor and Adafruit sensor library

Connect + to 5V

Connect out A0

Connect - to GND

*/

#include <dht.h>

#define dht_pin A0 // Analog Pin A0 of Arduino is connected to DHT11 out pin

dht DHT;

void setup()

Serial.begin(9600);

delay(500);

Serial.println("DHT11 Humidity & temperature Sensor\n\n");

delay(1000);

void loop()

DHT.read11(dht_pin);

Serial.print("Humidity = ");

Serial.print(DHT.humidity);

Serial.print("% ");

Serial.print("Temperature = ");

ISE dept., NHCE Page 20


Internet Of Things Lab Manual [22ISE464]

Serial.print(DHT.temperature);

Serial.println(" C");

delay(5000); //Reduce Time for Quick Reply

#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;
}

// Compute heat index in Fahrenheit (the default)


float hif = dht.computeHeatIndex(f, h);

ISE dept., NHCE Page 21


Internet Of Things Lab Manual [22ISE464]

// Compute heat index in Celsius (isFahreheit = false)


float hic = dht.computeHeatIndex(t, h, false);

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

ISE dept., NHCE Page 22


Internet Of Things Lab Manual [22ISE464]

ISE dept., NHCE Page 23


Internet Of Things Lab Manual [22ISE464]

Expt 5: TCS3200 Color Sensor interfacing with Arduino to detect the colors.

Hardware Requirements

 TCSP3200 or TCS230 color sensor

 Arduino UNO

 Jumper wires

ISE dept., NHCE Page 24


Internet Of Things Lab Manual [22ISE464]

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()
{

ISE dept., NHCE Page 25


Internet Of Things Lab Manual [22ISE464]

// Set the S0, S1, S2, S3 Pins as Output


pinMode(S0_PIN, OUTPUT);
pinMode(S1_PIN, OUTPUT);
pinMode(S2_PIN, OUTPUT);
pinMode(S3_PIN, OUTPUT);
//Set OUT_PIN as Input
pinMode(OUT_PIN, INPUT);
// Set Pulse Width scaling to 20%
digitalWrite(S0_PIN, HIGH);
digitalWrite(S1_PIN, LOW);
// Enable UART for Debugging
Serial.begin(9600);
}

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(" ");

ISE dept., NHCE Page 26


Internet Of Things Lab Manual [22ISE464]

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);

ISE dept., NHCE Page 27


Internet Of Things Lab Manual [22ISE464]

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;
}

ISE dept., NHCE Page 28


Internet Of Things Lab Manual [22ISE464]

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

2. Android Smartphone that has Bluetooth.


3. HC-05 Bluetooth Module
4. Android Studio (To develop the required Android app)
5. USB cable for programming and powering the Arduino
Procedure:

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

1. HC 05/06 works on serial communication.


2. The Android app is designed to send serial data to the Arduino Bluetooth module when a
button is pressed on the app.
3. 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).
4. The code uploaded to the Arduino checks the received data and compares it. If the received
data is 1, the LED turns ON.
5. The LED turns OFF when the received data is 0. You can open the serial monitor and watch
the received data while connecting.

SOURCE CODE:

#include <SoftwareSerial.h>

SoftwareSerial Bluetooth(10, 9); // RX, TX

int LED = 13; // the on-board LED

ISE dept., NHCE Page 29


Internet Of Things Lab Manual [22ISE464]

int Data; // the data received

void setup() {

Bluetooth.begin(9600);

Serial.begin(9600);

Serial.println("Waiting for command...");

Bluetooth.println("Send 1 to turn on the LED. Send 0 to turn Off");

pinMode(LED,OUTPUT);

void loop() {

if (Bluetooth.available()){ //wait for data received

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!");

Bluetooth.println("LED On D13 Off ! ");

else{;}

delay(100);

ISE dept., NHCE Page 30


Internet Of Things Lab Manual [22ISE464]

OUTPUT:

ISE dept., NHCE Page 31


Internet Of Things Lab Manual [22ISE464]

ISE dept., NHCE Page 32


Internet Of Things Lab Manual [22ISE464]

Expt7: To interface ultrasonic sensor with Arduino/Raspberry Pi and write a program


to display the distance of the obstacle.

Hardware Requirements

1. Arduino UNO

2. BreadBoard

3. UltraSonic SensorHC-SR04

4. LED

5. Jumper wires

Distance to an object = ((speed of sound in the air)*time)/2

Speed of sound in the air at 20ºC (68ºF) = 343m/s

ISE dept., NHCE Page 33


Internet Of Things Lab Manual [22ISE464]

Ultrasonic Sensor HC-SR04 Arduino

VCC 5V

Trig Pin 11

Echo Pin 12

GND GND

Program

/*

Ultrasonic sensor Pins:

VCC: +5VDC

Trig : Trigger (INPUT) - Pin11

Echo: Echo (OUTPUT) - Pin 12

GND: GND

*/

int trigPin = 11; // Trigger

int echoPin = 12; // Echo

ISE dept., NHCE Page 34


Internet Of Things Lab Manual [22ISE464]

long duration, cm, inches;

void setup() {

//Serial Port begin

Serial.begin (9600);

//Define inputs and outputs

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

void loop() {

// The sensor is triggered by a HIGH pulse of 10 or more microseconds.

// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

digitalWrite(trigPin, LOW);

delayMicroseconds(5);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

// Read the signal from the sensor: a HIGH pulse whose

// duration is the time (in microseconds) from the sending

// of the ping to the reception of its echo off of an object.

pinMode(echoPin, INPUT);

duration = pulseIn(echoPin, HIGH);

// Convert the time into a distance

cm = (duration/2) / 29.1; // Divide by 29.1 or multiply by 0.0343

inches = (duration/2) / 74; // Divide by 74 or multiply by 0.0135

Serial.print(inches);

Serial.print("in, ");

ISE dept., NHCE Page 35


Internet Of Things Lab Manual [22ISE464]

Serial.print(cm);

Serial.print("cm");

Serial.println();

delay(250);

OUTPUT

ISE dept., NHCE Page 36


Internet Of Things Lab Manual [22ISE464]

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

ISE dept., NHCE Page 37


Internet Of Things Lab Manual [22ISE464]

Program

int FloatSensor=10;

int led=13;

int buttonState = 1; //reads pushbutton status

void setup()

Serial.begin(9600);

pinMode(FloatSensor, INPUT_PULLUP); //Arduino Internal Resistor 10K

pinMode (led, OUTPUT);

void loop()

buttonState = digitalRead(FloatSensor);

if (buttonState == HIGH)

{digitalWrite(led, HIGH);

Serial.println( "WATER LEVEL – HIGH");}

else

{digitalWrite(led, LOW);

Serial.println( "WATER LEVEL – 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.

ISE dept., NHCE Page 38


Internet Of Things Lab Manual [22ISE464]

Expt 9: To interface ADXL335 accelerometer with Arduino/RaspberryPI to detect the


various orientation and display it on serial monitor.

ISE dept., NHCE Page 39


Internet Of Things Lab Manual [22ISE464]

const int xInput = A0;

const int yInput = A1;

const int zInput = A2;

// initialize minimum and maximum Raw Ranges for each axis

int RawMin = 0;

int RawMax = 1023;

// Take multiple samples to reduce noise

const int sampleSize = 10;

void setup()

analogReference(EXTERNAL);

Serial.begin(9600);

void loop()

//Read raw values

int xRaw = ReadAxis(xInput);

int yRaw = ReadAxis(yInput);

ISE dept., NHCE Page 40


Internet Of Things Lab Manual [22ISE464]

int zRaw = ReadAxis(zInput);

// Convert raw values to 'milli-Gs"

long xScaled = map(xRaw, RawMin, RawMax, -3000, 3000);

long yScaled = map(yRaw, RawMin, RawMax, -3000, 3000);

long zScaled = map(zRaw, RawMin, RawMax, -3000, 3000);

// re-scale to fractional Gs

float xAccel = xScaled / 1000.0;

float yAccel = yScaled / 1000.0;

float zAccel = zScaled / 1000.0;

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);

// Take samples and return the average

int ReadAxis(int axisPin)

ISE dept., NHCE Page 41


Internet Of Things Lab Manual [22ISE464]

long reading = 0;

analogRead(axisPin);

delay(1);

for (int i = 0; i<sampleSize; i++)

reading += analogRead(axisPin);

return reading/sampleSize;

OUTPUT

ISE dept., NHCE Page 42


Internet Of Things Lab Manual [22ISE464]

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:

1. Arduino Uno board

2. Breadboard

3. Three LEDs (Red, Green, and White)

4. Ultrasonic sensor module

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.

ISE dept., NHCE Page 43


Internet Of Things Lab Manual [22ISE464]

Program

const int trigPin = 9;

const int echoPin = 10;

const int redPin = 2;

const int greenPin = 3;

const int whitePin = 4;

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);

int duration = pulseIn(echoPin, HIGH);

int distance = duration * 0.034 / 2;

if (distance < 50) { // Clap detected

digitalWrite(redPin, HIGH); // Red on

ISE dept., NHCE Page 44


Internet Of Things Lab Manual [22ISE464]

digitalWrite(greenPin, LOW); // Green off

digitalWrite(whitePin, LOW); // White off

delay(500);

digitalWrite(redPin, LOW); // All off

digitalWrite(greenPin, HIGH); // Green on

digitalWrite(whitePin, LOW); // White off

delay(500);

digitalWrite(redPin, LOW); // All off

digitalWrite(greenPin, LOW); // Green off

digitalWrite(whitePin, HIGH); // White on

delay(500);

digitalWrite(redPin, LOW); // All off

digitalWrite(greenPin, LOW); // Green off

digitalWrite(whitePin, LOW); // White off

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.

ISE dept., NHCE Page 45


Internet Of Things Lab Manual [22ISE464]

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

int sensorPin = A0;


int outputValue ;
void setup()
{
Serial.begin(9600);
Serial.println("Reading Data From the Sensor ...");

ISE dept., NHCE Page 46


Internet Of Things Lab Manual [22ISE464]

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);
}

ISE dept., NHCE Page 47


Internet Of Things Lab Manual [22ISE464]

OUTPUT

ISE dept., NHCE Page 48


Internet Of Things Lab Manual [22ISE464]

Exp 12: Write a program on Arduino/Raspberry Pi to upload temperature and humidity data to
cloud.

Hardware Requirements:

1. Arduino UNO board


2. NodeMCU ESP8266 Breakout Board
3. DHT-11 temperature and humidity sensor
4. Jumper wires
5. Bread board
6. WIFI Network

Procedure:

1. Download esp8266 Zip file->go to libraries->add Zip file

2. Connect Node MCU, Go to tools->change board to Node MCU esp8266 and port number

3. Connect DHT-11 temperature and Humidity sensor to Node MCU

4. Sign up to cloud->create channels->copy API key to the source code

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

7. Go to cloud and verify the temperature and humidity values in graph.

SOURCE CODE:

#include <DHT.h>
#include <DHT_U.h>
#include <DHT.h>
#include <ESP8266WiFi.h>

String apiKey = "WAHKMAHIYUR1SEFU";


const char *ssid = "chitti";
const char *pass = "sari123#";
const char* server = "api.thingspeak.com";

#define DHTPIN 0

DHT dht(DHTPIN, DHT11);

ISE dept., NHCE Page 49


Internet Of Things Lab Manual [22ISE464]

WiFiClient client;

void setup()

Serial.begin(115200);

delay(10);

dht.begin();

Serial.println("Connecting to ");

Serial.println(ssid);

WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED)

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

Serial.println("Failed to read from DHT sensor!");

ISE dept., NHCE Page 50


Internet Of Things Lab Manual [22ISE464]

return;

if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com

String postStr = apiKey;

postStr +="&field1=";

postStr += String(t);

postStr +="&field2=";

postStr += String(h);

postStr += "\r\n\r\n";

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-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(" degrees Celcius, Humidity: ");

Serial.print(h);

ISE dept., NHCE Page 51


Internet Of Things Lab Manual [22ISE464]

Serial.println("%. Send to Thingspeak.");

client.stop();

Serial.println("Waiting...");

delay(10000);

OUTPUT:

Uploading the data in CLOUD:

ISE dept., NHCE Page 52


Internet Of Things Lab Manual [22ISE464]

Visualizing the output in Serial monitor:

ISE dept., NHCE Page 53


Internet Of Things Lab Manual [22ISE464]

ADDITIONAL EXPERIMENT

Expt 13: Understanding the connectivity of Arduino/RaspberryPI with PIR motion


sensor with an application to detect obstacle and notify user using LED/LCD.

Hardware Requirements

1. PIR Motion Sensor (HC-SR501)

2. Arduino UNO

3. LED

4. Jumper Cables

GND – connect to ground

OUT – connect to an Arduino digital pin

5V – connect to 5V

Program

int led = 13; // the pin that the LED is atteched to

int sensor = 2; // the pin that the sensor is atteched to

int state = LOW; // by default, no motion detected

ISE dept., NHCE Page 54


Internet Of Things Lab Manual [22ISE464]

int val = 0; // variable to store the sensor status (value)

void setup() {

pinMode(led, OUTPUT); // initalize LED as an output

pinMode(sensor, INPUT); // initialize sensor as an input

Serial.begin(9600); // initialize serial

void loop(){

val = digitalRead(sensor); // read sensor value

if (val == HIGH) { // check if the sensor is HIGH

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

delay(100); // delay 100 milliseconds

if (state == LOW) {

Serial.println("Motion detected!");

state = HIGH; // update variable state to HIGH

else {

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

delay(200); // delay 200 milliseconds

if (state == HIGH){

Serial.println("Motion stopped!");

state = LOW; // update variable state to LOW

ISE dept., NHCE Page 55


Internet Of Things Lab Manual [22ISE464]

OUTPUT

LED glows if the object is detected

ISE dept., NHCE Page 56

You might also like