Distance Detection and Alert System With Arduino
by jovanovski in Circuits > Arduino
502 Views, 6 Favorites, 0 Comments
Distance Detection and Alert System With Arduino
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 field 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 predefined 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)
Body Assembly
3D print these housings for the body of the system. All the 3D parts are below with the right dimensions and postition.
Connecting the Electronics and Setting Up on the Housings
Red Wires - Power Supply for the component that is connected
Black Wires - GND of the component that is connected
Green Wire - Trigger from the Ultrasonic Sensor to pin number 7
Yellow Wire - Echo from the Ultrasonic Sensor to pin number 6
Blue Wire - In1 from the Stepper Motor
Purple Wire - In 2 from the Stepper Motor
Green Wire - In 3 from the Stepper Motor
Pink Wire - In 4 from the Stepper Motor
White Wire - The positive end of the Buzzer to pin number 12
Brown Wire - The negative end of the Buzzer to GND
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 !
Code
#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);
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;
}
Finish
The project is finished. I hope you didn't have any problems understanding and maybe crafting this project at all. Thank you for your time !
The link will lead you to a video of the project working !