IOT Del Later

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Experiment No. - 2.

Student Name: Karan Katyal UID: 21BCS5815


Branch: BE-CSE Section/Group: 605-B
Semester: 5th Date: 11/09/2023
Subject Name: IOT Subject Code: 21CSP- 344

AIM: To measure the distance of an object using an ultrasonic sensor.

COMPONENTS REQUIRED:
You will need the following components −
1. Arduino Uno R3 board
2. Ultrasonic sensor (HC-SR04)
3. 16×2 LCD I2C Display
4. Jumper Wires

THEORY:
Ultrasonic Sensor:
An ultrasonic Sensor is a device used to measure the distance between the sensor and an object
without physical contact. This device works based on time-to-distance conversion.

Working Principle of Ultrasonic Sensor:


Ultrasonic sensors measure distance by sending and receiving the ultrasonic wave. The
ultrasonic sensor has a sender to emit the ultrasonic waves and a receiver to receive the
ultrasonic waves. The transmitted ultrasonic wave travels through the air and is reflected by
hitting the Object. Arduino calculates the time taken by the ultrasonic pulse wave to reach the
receiver from the sender. Formula: Distance = Speed * Time
In the code, the “duration” variable stores the time taken by the sound wave traveling from the
emitter to the receiver. That is double the time to reach the object, whereas the sensor returns
the total time including sender to object and object to receiver. Then, the time taken to reach the
object is half of the time taken to reach the receiver. so we can write the expression as, Distance
= Speed of Sound in Air * (Time Taken / 2) Note: Speed of sound in air = 344 m/s.

PROCEDURE:
Connect the Echo pin of the sensor to the D2 pin of the Arduino.

• Connect the Trig pin of the sensor to the D3 pin of the Arduino.
• Navigate to Tools and select board and port.
• Verify and compile the code, then upload the code to the Arduino Uno R3 board.
KARAN KATYAL 21BCS5815
• Monitor the output in the Serial monitor (Set the baud rate as 9600). To open Serial
monitor Tools>Serial Monitor or (Ctrl+Shift+M).

Follow the circuit diagram as shown in the image given above.


To interface with the LCD display, we need to install the supporting library to the Arduino IDE.

Steps to Interface LCD display:

1. Install driver library for Liquid Crystal Display.


• Navigate Tools>Library Manager (or) Enter ( Ctrl+Shift+I ) to open library
manager.
• Search for “LiquidCrystal I2C” and install the “LiquidCrystal I2C” library. 2.
Import the header file “LiquidCrystal_I2C.h” in the code.
3. Connect the SDA pin of an LCD display to the SDA pin of the Arduino Board and the SCL
pin of an LCD display to the SCL of the Arduino Board.
4. Connect VCC to 5V pin and GND to GND pin.

KARAN KATYAL 21BCS5815


SKETCH:

KARAN KATYAL 21BCS5815


RESULT:

LEARNING OUTCOMES:

• Learnt about the proximity sensor and its applications.


•Learnt how to connect proximity sensor on Arduino.
• Learnt how to connect LCD display.
• Learnt how to code in Arduino.
KARAN KATYAL 21BCS5815

You might also like