0% found this document useful (0 votes)
4 views4 pages

Abdul_iot_4

Iot worksheet for students

Uploaded by

Abdul Kalam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Abdul_iot_4

Iot worksheet for students

Uploaded by

Abdul Kalam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DEPARTMENT OF

Experiment 4

Student Name: Abdul Kalam UID:22BCS14739


Branch: BE/CSE Section/Group: 602-A
Semester: 5 Date of Performance:8/08/2024
Subject Name: IOT Architecture Subject Code: 22CSP-329
and its Protocols Lab

1. Aim:

To Formulate distance of an object using an ultrasonic sensor

Objective
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.

Input/Equipment Used-

1. Arduino Uno R3 board


2. Ultrasonic sensor (HC-SR04)
3. 16×2 LCD I2C Display
4. Jumper Wires

Procedure-

Connect HC-SR04:
VCC to 5V.
GND to GND.
Trig to Pin 9.
Echo to Pin 10.
Connect LCD:
VCC to 5V.
GND to GND.
SDA to A4.
SCL to A5.
DEPARTMENT OF

Install Libraries: Add LiquidCrystal_I2C library in Arduino IDE.

Upload the code on Arduino IDE.

Power On: Connect Arduino to power and observe LCD display.

Measure Distance: Point sensor at the object.

Read LCD: LCD shows distance in centimeters.

Connections:
1. Connect the Echo pin of the sensor to the D2 pin of the Arduino.
2. Connect the Trig pin of the sensor to the D3 pin of the Arduino.
3. Navigate to Tools and select board and port.
4. Verify and compile the code, then upload the code to the Arduino Uno R3 board.
5. Monitor the output in the Serial monitor (Set the baud rate as 9600). To open Serial
monitor Tools>Serial Monitor or (Ctrl+Shift+M).

CODE

#define ECHO_PIN 2
#define TRIG_PIN 3

void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}
float readDistanceCM() {
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
int duration = pulseIn(ECHO_PIN, HIGH);
return duration * 0.034 / 2;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
void loop() {
float distance = readDistanceCM();

bool isNearby = distance < 100;


digitalWrite(LED_BUILTIN, isNearby);

Serial.print("Target Distance: ");


Serial.println(readDistanceCM());

delay(100);

Result

Conclusion
The project successfully demonstrates distance measurement using an ultrasonic sensor and an Arduino with an
LCD display. By connecting the HC-SR04 sensor to the Arduino and interfacing it with a 16×2 LCD via I2C, the
system measures the distance to an object. The ultrasonic sensor emits sound waves, which reflect off the object
and return, allowing the Arduino to calculate the distance based on the time of flight. The calculated distance is
then displayed on the LCD in centimeters. This setup provides a simple and effective means to measure and
display distances in real-time.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

You might also like