0% found this document useful (0 votes)
2 views16 pages

Arduino Ultrasonic Sensor Projects

The document provides instructions for interfacing an ultrasonic sensor with an Arduino UNO board, including programs to measure distance, control an LED based on distance, activate a buzzer, and detect objects. Each section includes a schematic diagram and code snippets for specific functionalities. The programs utilize the ultrasonic sensor to calculate distance and perform actions based on predefined conditions.

Uploaded by

peloni9318
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)
2 views16 pages

Arduino Ultrasonic Sensor Projects

The document provides instructions for interfacing an ultrasonic sensor with an Arduino UNO board, including programs to measure distance, control an LED based on distance, activate a buzzer, and detect objects. Each section includes a schematic diagram and code snippets for specific functionalities. The programs utilize the ultrasonic sensor to calculate distance and perform actions based on predefined conditions.

Uploaded by

peloni9318
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

4 A.

) Interface ultrasonic sensor with Arduino UNO board & write


the program to measure and display the distance on serial monitor.
Schematic Diagram:

Program:
const int sigPin = 4;

long duration;

int distance;

void setup() {

[Link](9600);

}
void loop() {

pinMode(sigPin, OUTPUT);

digitalWrite(sigPin, LOW);

delayMicroseconds(2);

digitalWrite(sigPin, HIGH);

delayMicroseconds(5);

digitalWrite(sigPin, LOW);

pinMode(sigPin, INPUT);

duration = pulseIn(sigPin, HIGH);

distance = duration * 0.034 / 2;

[Link]("Distance: ");

[Link](distance);

[Link](" cm");

delay(500);

}
Output – OFF
Output – ON
4 B.) Interface ultrasonic sensor with Arduino UNO board and write
the program to Turn ON the LED if distance is more than 10 cm else
turn OFF the LED.

Schematic Diagram:

Program:
const int sigPin = 4;

const int ledPin = 12;

long duration;

int distance;

void setup() {
pinMode(ledPin, OUTPUT);

[Link](9600);

void loop() {

pinMode(sigPin, OUTPUT);

digitalWrite(sigPin, LOW);
delayMicroseconds(2);

digitalWrite(sigPin, HIGH);

delayMicroseconds(5);

digitalWrite(sigPin, LOW);

pinMode(sigPin, INPUT);

duration = pulseIn(sigPin, HIGH);

distance = duration * 0.034 / 2;

[Link]("Distance: ");

[Link](distance);

[Link](" cm");

if (distance > 10 && distance != 0) {


digitalWrite(ledPin, HIGH);

} else {

digitalWrite(ledPin, LOW);

}
delay(500);

Output – OFF
Output – ON
4 C.) Interface ultrasonic sensor with Arduino UNO board and write
the program if distance is less than 10 cm else turn ON the buzzer
else turn ON the LED.
Schematic Diagram:

Program:
const int sigPin = 4;

const int ledPin = 12;

long duration;

int distance;

void setup() {
pinMode(ledPin, OUTPUT);

[Link](9600);

void loop() {

pinMode(sigPin, OUTPUT);

digitalWrite(sigPin, LOW);
delayMicroseconds(2);

digitalWrite(sigPin, HIGH);

delayMicroseconds(5);

digitalWrite(sigPin, LOW);

pinMode(sigPin, INPUT);

duration = pulseIn(sigPin, HIGH);

distance = duration * 0.034 / 2;

[Link]("Distance: ");

[Link](distance);

[Link](" cm");

if (distance < 10 && distance != 0) {


digitalWrite(ledPin, HIGH);

} else {

digitalWrite(ledPin, LOW);

}
delay(500);

Output – OFF
Output – ON
4 D.) Interface ultrasonic sensor with Arduino UNO board & write
the program to detect the object and display message ’Object
Detected’
Schematic Diagram:
Program:
const int sigPin = 4;

long duration;

int distance;

void setup() {

[Link](9600);

void loop() {

pinMode(sigPin, OUTPUT);

digitalWrite(sigPin, LOW);

delayMicroseconds(2);

digitalWrite(sigPin, HIGH);

delayMicroseconds(5);

digitalWrite(sigPin, LOW);

pinMode(sigPin, INPUT);

duration = pulseIn(sigPin, HIGH);

distance = duration * 0.034 / 2;

if (distance > 0) {

[Link]("Object Detected");
}

delay(500);

}
Output – OFF
Output – ON

You might also like