Distance Detection and Alert System With Arduino
Distance Detection and Alert System With Arduino
by jovanovski
This project represents a fascinating convergence of technology, utilizing an ultrasonic sensor, a stepper motor, and a
buzzer to create a system that responds dynamically to its surroundings. The core functionality of this project revolves
around the precise movement of a 35-degree rotating ultrasonic sensor, equipped with the ability to measure distances
with remarkable accuracy. As the sensor sweeps its eld of view, it constantly monitors the environment, measuring the
distance between itself and any objects in its path. The magic happens when this distance measurement falls within a
prede ned threshold of 30 centimeters or less, triggering the alert mechanism - a buzzer.
Supplies:
Arduino UNO R3
Arduino Cable
Ultrasonic sensor HC-SR04
Stepper Motor 28BYJ-48
Active Buzzer
Jumper wires 12x (10cm)
Bolts M3 x8
Drill bit (3 cm)
3D print these housings for the body of the system. All the 3D parts are below with the right dimensions and postition.
View in 3D Download
https://www.instructables.com/FXZ/BAAJ/LOOCFZM2/FXZBAAJLOOCFZM2.stl
View in 3D Download
https://www.instructables.com/F3D/LY05/LOOCFZM3/F3DLY05LOOCFZM3.stl
View in 3D Download
https://www.instructables.com/FWL/OE03/LOOCFZM8/FWLOE03LOOCFZM8.stl
NOTE: The stepper motor in the simulator is described as a 8pin header, because Tinkercad doesn't have Stepper Motor or Driver
compactible for this project !
#include <Stepper.h>
int stepsPerRevolution=2048;
int motSpeed=10;
Stepper myStepper(stepsPerRevolution, 8,10,9,11);
int steps = 10;
int countCCW = 1;
int countCW = 1;
int trigPin = 7;
int echoPin = 6;
int pingTravelTime;
int buzzerPin = 12;
void setup() {
myStepper.setSpeed(motSpeed);
pinMode (trigPin, OUTPUT);
pinMode (echoPin, INPUT);
Serial.begin (9600);
pinMode (buzzerPin, OUTPUT);
}
void loop() {
for (countCCW; countCCW <= 25; countCCW=countCCW+1) {
myStepper.step (steps);
digitalWrite (trigPin, LOW);
Distance Detection and Alert System With Arduino: Page 19
delayMicroseconds (10);
digitalWrite (trigPin, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin, LOW);
pingTravelTime = pulseIn (echoPin, HIGH);
Serial.println (pingTravelTime);
if (pingTravelTime < 300) {
digitalWrite (buzzerPin, HIGH);
}
else {
digitalWrite (buzzerPin, LOW);
}
}
countCCW = 0;
for (countCW; countCW <= 25; countCW=countCW+1) {
myStepper.step (-steps);
digitalWrite (trigPin, LOW);
delayMicroseconds (10);
digitalWrite (trigPin, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin, LOW);
pingTravelTime = pulseIn (echoPin, HIGH);
Serial.println (pingTravelTime);
if (pingTravelTime < 300) {
digitalWrite (buzzerPin, HIGH);
}
else {
digitalWrite (buzzerPin, LOW);
}
}
countCW = 0;
}
Step 4: Finish
The project is nished. I hope you didn't have any problems understanding and maybe crafting this project at all. Thank
you for your time !
Distance Detection and Alert System With Arduino: Page 20
The link will lead you to a video of the project working !