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

IOT - 2.1 Abhi

The student conducted an experiment to measure the distance of an object using an ultrasonic sensor. The experiment involved connecting an ultrasonic sensor's echo pin to digital pin D2 and trig pin to digital pin D3 of an Arduino Uno board. The code uses pulseIn() to measure the time taken for the ultrasonic pulse to reflect back and then calculates the distance using this time. The distance measurement is printed on the serial monitor every 100ms. The student learned about ultrasonic sensors, how to interface them with Arduino, and code to measure distance using ultrasonic sensors.

Uploaded by

kartik soni
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)
18 views4 pages

IOT - 2.1 Abhi

The student conducted an experiment to measure the distance of an object using an ultrasonic sensor. The experiment involved connecting an ultrasonic sensor's echo pin to digital pin D2 and trig pin to digital pin D3 of an Arduino Uno board. The code uses pulseIn() to measure the time taken for the ultrasonic pulse to reflect back and then calculates the distance using this time. The distance measurement is printed on the serial monitor every 100ms. The student learned about ultrasonic sensors, how to interface them with Arduino, and code to measure distance using ultrasonic sensors.

Uploaded by

kartik soni
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

Experiment 2.

Student Name: Abhishek Bisht UID: 21BCS2997


Branch: CSE Section/Group: 627-A
Semester: 5th Date: 19/09/2023
Subject Name: IOT Lab Subject Code: 21CSP-344

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

Objective: To implement Ultrasonic sensor

Hardware and Softwares : Tinker Cad

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.
• 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 echoPin \
2 // attach pin D2 Arduino to pin Echo of HC-SR04
#define trigPin \
3 // attach pin D3 Arduino to pin Trig of HC-SR04
long duration; // Variable to store time taken to the pulse
// to reach receiver
int distance; // Variable to store distance calculated using
// formula
void setup()
{
pinMode(trigPin,
OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
// Serial Communication is starting with 9600 of
// baudrate speed
Serial.begin(9600);
// The text to be printed in serial monitor
Serial.println(
"Distance measurement using Arduino Uno.");
delay(500);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2); // wait for 2 ms to avoid
// collision in serial monitor
digitalWrite(
trigPin,
HIGH); // turn on the Trigger to generate pulse
delayMicroseconds(
10); // keep the trigger "ON" for 10 ms to generate
// pulse for 10 ms.
digitalWrite(trigPin,
LOW); // Turn off the pulse trigger to stop
// pulse generation
// If pulse reached the receiver echoPin
// become high Then pulseIn() returns the
// time taken by the pulse to reach the
// receiver
duration = pulseIn(echoPin, HIGH);
distance
= duration * 0.0344 / 2; // Expression to calculate
// distance using time
Serial.print("Distance: ");
Serial.print(
distance); // Print the output in serial monitor
Serial.println(" cm");
delay(100);
}
OUTPUT
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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy