0% found this document useful (0 votes)
17 views3 pages

Iot 4

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

Iot 4

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

Experiment-4

Student Name: Yogita Verma UID: 23MCA20051


Branch: MCA Section/Group: 5-A
Semester: Third Date of Performance: 16/08/2024
Subject Name: Internet of Things Subject Code: 23CAH-702

1,Aim/Overview of the Practical :


Design the circuit and write a program to interface an ultrasonic sensor (SR-04) with Arduino
Uno to measure distance and print on lcd.

2.Code of the Experiment :

#include <LiquidCrystal.h> // includes the LiquidCrystal Library


LiquidCrystal lcd(1, 2, 4, 5, 6, 7);
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distanceCm, distanceInch;
void setup() {
lcd.begin(16,2);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;
lcd.setCursor(0,0);

8
lcd.print("Distance: ");
lcd.print(distanceCm);

lcd.print(" cm");
delay(10);
lcd.setCursor(0,1);
lcd.print("Distance: ");
lcd.print(distanceInch);
lcd.print(" inch");
delay(10);
}
1. Circuit Diagram:

4 .)Hardware Requirements:
 Arduino UNO R4
 16*2 LCD Display
 Breadboard
 Connectors

9
 Ultrasonic Sensor

5.)Software Requirements:
 Arduino IDE
6.)Learning outcomes (What I have learnt):
 Understanding how to use Ultrasonic sensor for measuring distances.
 Learning to control digital outputs using the digitalWrite function.
 Understanding the usage and connection of 16*2 LCD display.
 Understanding the use of the delay function to create pauses in the program, which is
crucial for controlling timing in embedded systems.

10

You might also like