Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

instructables

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)

Distance Detection and Alert System With Arduino: Page 1


Distance Detection and Alert System With Arduino: Page 2
Distance Detection and Alert System With Arduino: Page 3
Step 1: Body Assembly

3D print these housings for the body of the system. All the 3D parts are below with the right dimensions and postition.

Distance Detection and Alert System With Arduino: Page 4


Distance Detection and Alert System With Arduino: Page 5
Distance Detection and Alert System With Arduino: Page 6
Distance Detection and Alert System With Arduino: Page 7
Distance Detection and Alert System With Arduino: Page 8
Distance Detection and Alert System With Arduino: Page 9
View in 3D Download
https://www.instructables.com/FH3/FHXA/LOOCFZM1/FH3FHXALOOCFZM1.stl

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

Step 2: 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 !

Distance Detection and Alert System With Arduino: Page 10


Distance Detection and Alert System With Arduino: Page 11
Distance Detection and Alert System With Arduino: Page 12
Distance Detection and Alert System With Arduino: Page 13
Distance Detection and Alert System With Arduino: Page 14
Distance Detection and Alert System With Arduino: Page 15
Distance Detection and Alert System With Arduino: Page 16
Distance Detection and Alert System With Arduino: Page 17
Distance Detection and Alert System With Arduino: Page 18
Step 3: 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);
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 !

Distance Detection and Alert System With Arduino: Page 21


Distance Detection and Alert System With Arduino: Page 22
Distance Detection and Alert System With Arduino: Page 23
Distance Detection and Alert System With Arduino: Page 24
Download
https://www.instructables.com/FZ3/BG7I/LOSMO4A2/FZ3BG7ILOSMO4A2.mp4

Distance Detection and Alert System With Arduino: Page 25

You might also like