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

Puru 4 IOT

Uploaded by

kr.ankushyadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
4 views5 pages

Puru 4 IOT

Uploaded by

kr.ankushyadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 4
Student Name: Purushottam Kumar UID:22BCS10794
Branch: BE-CSE Section/Group: 608/B
th
Semester: 5 Date of Performance: 16/8/24
Subject Name: IOT Architecture and Protocol Lab
Subject Code: 22CSP-329

1. Aim: To Formulate distance of an object using an ultrasonic sensor.

2. Objective:
• Learn about Distance Calculations using Sensor
• Learn about IOT programming

3. Equipment Used:
• Breadboard
• Tinker Cad
• Ultrasonic sensor (HC-SR04)
• Arduino Uno R3
• Jumper Wires

4. Theory:

Tinkercad: https://www.tinkercad.com is an excellent tool that allows you to


simulate Arduino-based systems (and a lot more). You can (perhaps you
SHOULD) simulate all exercises and even your own designs before trying them
on real hardware. It also allows you to do programming using blocks. You can
download / copy-paste the generated code later into Arduino IDE to program the
real Arduino board, rather than having to write it from scratch. Create a new
personal account on Tinkercad website (you can also use your Google account to
log in). Then select Circuits on the left pane, and click Create new Circuit.

Arduino Board: An Arduino is a micro controller-based kit.


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

It is basically used in communications and in controlling or operating many


devices. Arduino UNO board is the most popular board in the Arduino board
family. In addition, it is the best board to get started with electronics and coding.
Some boards look a bit different from the one given below, but most Arduino’s
have majority of these components in common. Arduino Uno consists of 14 digital
input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16
MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a
reset button.

Ultrasonic Sensor: It 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.
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.

5. Procedure:
• Connect the Ultrasonic Sensor to the Arduino:
• Connect the VCC pin of the ultrasonic sensor to the 5V pin on the Arduino.
• Connect the GND pin of the ultrasonic sensor to the GND pin on the
Arduino.
• Connect the Trig pin (Pin 5 in code) of the sensor to digital pin 5 on the
Arduino.
• Connect the Echo pin (Pin 4 in code) of the sensor to digital pin 4 on the
Arduino.

• Upload the code to the Arduino UNO.


• The ultrasonic sensor will send out ultrasonic waves and measure the time
taken for the waves to return.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

• The Arduino will calculate the distance based on the time and display it on the
Serial Monitor in centimeters.

6. Code:

# define echoPin 4
# define trigPin 5

long duration;
int distance;

void setup(){
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
Serial.begin(9600);
}

void loop(){
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);

duration=pulseIn(echoPin,HIGH);
distance=duration*0.034/2;

Serial.print("Distance");
Serial.print(distance);
Serial.println(" cm");
delay(1000);
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

7. Result-
This demonstrates that the connections between the Arduino and the Ultrasonic
Sensor are correct and the Arduino code is functioning as intended.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

8. Learning Outcomes:

• Understand the working principle of an ultrasonic sensor in measuring


distance.
• Learn to interface an ultrasonic sensor with an Arduino UNO microcontroller.
• Develop skills in writing and uploading Arduino code to interact with external
sensors.
• Gain practical experience in assembling circuits on a breadboard for sensor-
based projects.
• Interpret real-time data using the Serial Monitor and apply it to analyze the
performance of the sensor.

9. Conclusion:

This experiment successfully demonstrates how to measure the distance of an


object using an ultrasonic sensor and Arduino UNO. The project provides hands-
on experience with sensor interfacing, coding, and real-time data monitoring,
making it a valuable learning activity in embedded systems and robotics.

You might also like