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

Program File

The document provides a list of materials needed for a distance sensor project, including an Arduino Uno, ultrasonic sensor, breadboard, and various electronic components. It also includes a program code for measuring distance and controlling a motor and buzzer based on the distance detected. The program is designed to trigger an alert when an object is within 5 cm of the sensor.

Uploaded by

romanzaira4
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)
2 views3 pages

Program File

The document provides a list of materials needed for a distance sensor project, including an Arduino Uno, ultrasonic sensor, breadboard, and various electronic components. It also includes a program code for measuring distance and controlling a motor and buzzer based on the distance detected. The program is designed to trigger an alert when an object is within 5 cm of the sensor.

Uploaded by

romanzaira4
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

____________________________________________________

Materials:

Individual components

Arduino Uno (Color: Uno with USB cable):


[Link]

Ultrasonic sensor (Color: HC-SR04):


[Link]

Breadboard:
[Link]

Jumper wires (Variation: Male to Male):


[Link]

Resistor (Options: 300pcs):


[Link]

LED (variation: Red 5mm):


[Link]

Active Piezo Buzzer (Model: 10pcs 5v):


[Link]

Group of components

In categories, look for " Distance Sensor 101". You can see there, all materials. Enjoy
and God bless!

Link:[Link]
_____________________________________________________________________________

PROGRAM:

const int trigPin = 9;


const int echoPin = 10;
const int Motor = 11;
const int buzzer = 13;
long duration;
float distance;

void setup()
{
pinMode(buzzer, OUTPUT);
pinMode(Motor, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
[Link](9600);
}

void loop()
{
measureAndControl();
delay(100); // Small delay for stability
}

void measureAndControl()
{
// Send trigger pulse
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Read echo time


duration = pulseIn(echoPin, HIGH);

// Convert to cm
distance = duration * 0.0343 / 2;
// Safety check
if (distance <= 5)
{
digitalWrite(buzzer, HIGH);
digitalWrite(Motor, HIGH);
}
else
{
digitalWrite(buzzer, LOW);
digitalWrite(Motor, LOW);
}

// Display on Serial Monitor


[Link]("Distance: ");
[Link](distance, 1);
[Link](" cm");
}

You might also like