Motion Detecting Buzzer

by NShannon22 in Circuits > Arduino

345 Views, 0 Favorites, 0 Comments

Motion Detecting Buzzer

Screenshot 2023-05-24 at 11.54.05 AM.png
Screenshot 2023-05-22 at 11.23.17 AM.png
Screenshot 2023-05-22 at 11.16.44 AM.png
Screenshot 2023-05-24 at 11.38.49 AM.png

I made a motion detecting buzzer. When the ultrasonic sensor detects motion inside a certain range, it sends a signal to the Arduino. The Arduino then sends a signal to the buzzer to play a noise. It plays the noise until the ultrasonic sensor doesn't detect anything.

Supplies

Arduino Uno R3, breadboard, Ultrasonic sensor HC-SR04, Buzzer, 9v battery and connector, and 9 male to male wires.

TinkerCad Circuit Design

Screenshot 2023-05-22 at 11.16.44 AM.png

On TinkerCad, https://www.tinkercad.com, place the following items, Arudino Uno R3, breadboard, Ultrasonic sensor HC-SR04, Buzzer, 9v battery and connector, and 9 male to male wires. Connect them as the photo shows.

Circuit Code

Screenshot 2023-05-24 at 11.38.49 AM.png

Place the code blocks in the order as shown.

This is the digital text code:

// C++ code

//

int distance = 0;


long readUltrasonicDistance(int triggerPin, int echoPin)

{

 pinMode(triggerPin, OUTPUT); // Clear the trigger

 digitalWrite(triggerPin, LOW);

 delayMicroseconds(2);

 // Sets the trigger pin to HIGH state for 10 microseconds

 digitalWrite(triggerPin, HIGH);

 delayMicroseconds(10);

 digitalWrite(triggerPin, LOW);

 pinMode(echoPin, INPUT);

 // Reads the echo pin, and returns the sound wave travel time in microseconds

 return pulseIn(echoPin, HIGH);

}


int counter;


void setup()

{

 Serial.begin(9600);

 pinMode(8, OUTPUT);

}


void loop()

{

 distance = 0;

 for (counter = 0; counter < 100000000000000; ++counter) {

  distance = 0.01723 * readUltrasonicDistance(2, A1);

  delay(20); // Wait for 20 millisecond(s)

  Serial.println(distance);

  if (distance < 150) {

   tone(8, 523, 50); // play tone 60 (C5 = 523 Hz)

  }

 }

}

Physical Circuit

Screenshot 2023-05-22 at 11.23.17 AM.png
Screenshot 2023-05-24 at 11.51.00 AM.png
Screenshot 2023-05-24 at 11.54.05 AM.png

With all the resources in hand, copy what you did on TinkerCad in real life.

Final Product

Screenshot 2023-05-24 at 12.03.39 PM.png
Screenshot 2023-05-24 at 12.16.07 PM.png

Download the Arudino IDE software at https://www.arduino.cc/en/software . Plug in the code from TinkerCad into the software. Load in the code on the right that is in text. You can get to that screen by selecting blocks and text. Confirm the code works. Plug your Arduino in, then upload the code. If you do all the steps correctly your final product will be a working motion detecting buzzer.