Distance Detection and Alert System With Arduino

by jovanovski in Circuits > Arduino

420 Views, 6 Favorites, 0 Comments

Distance Detection and Alert System With Arduino

viber_image_2023-11-08_13-13-34-418.jpg
viber_image_2023-11-07_20-58-26-220.jpg

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

viber_image_2023-11-07_21-01-29-456.jpg
viber_image_2023-11-07_21-01-29-276.jpg
viber_image_2023-11-07_21-01-29-245.jpg
viber_image_2023-11-07_21-01-28-844.jpg
viber_image_2023-11-07_21-01-28-808.jpg

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

viber_image_2023-11-08_13-46-08-589.jpg
viber_image_2023-11-08_13-46-11-043.jpg
viber_image_2023-11-08_13-46-11-703.jpg
viber_image_2023-11-08_13-46-12-263.jpg
viber_image_2023-11-08_13-59-06-518.jpg
FKIOZNKLOOCFYJZ.jpg
viber_image_2023-11-08_13-46-09-300.jpg
viber_image_2023-11-08_13-46-06-990.jpg
Ristijan Mihajlo (1).png

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

369065229_268498159053055_8074768095260388653_n.jpg
372157896_1415271166065333_3992574318170732961_n.jpg
369181813_757019649597435_5897709914701216817_n.jpg
371399350_876248974019061_7163887306211982372_n.jpg

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 !