Skip to content

Project 2.2.1: SMART SOUND ALERT SYSTEM

Description This project shows how to use an ultrasonic sensor and a buzzer with an Arduino Uno to create a smart sound alert system. When an object comes close to the sensor, the buzzer produces a sound alert.
Use case This project can be used as a simple security or obstacle detection system that alerts users when an object is nearby.

Components (Things You will need)

| Arduino Uno | | Traffic Light Module | Bread Board | Arduino USB Cable | Ultrasonic Sensor | Jumper wires | | --------------------------------------------------- | ------------------------------------------------------ | ----------------------------------------------------------- | --------------------------------------------------------- | ------------------------------------------------------ | ------------------------------------------------------ |

Building the circuit

Things Needed:

  • 1 Arduino Uno
  • 1 Arduino USB cable
  • 1 Buzzer
  • 1 Breadboard
  • 6 Jumper wires

Mounting the component on the breadboard

Things needed:

  • 1 Buzzer
  • 1 Ultrasonic Distance Sensor
  • 1 Breadboard

Step 1: T Place the ultrasonic sensor on the breadboard.

Ultrasonic sensor fixed on breadboard.

Step 2: Connect the Echo pin of the ultrasonic sensor to pin 2 on the Arduino Uno.

Buzzer fixed on breadboard.

NOTE: Take note of where each of the pins are placed on the bread board.

WIRING THE CIRCUIT

Things Needed:

  • 2 Red male-male-to-male jumper wires
  • 2 White male-to-male jumper wires
  • 2 Green male-to-male jumper wires
  • 2 Yellow male-to-male jumper wires

Step 3: Connect the Trig pin of the ultrasonic sensor to pin 3 on the Arduino Uno.

Red wire fixed on breadboard.

Step 2: Connect the VCC pin of the ultrasonic sensor to the 5V pin on the Arduino Uno.

Green wire fixed on breadboard.

Step 3: Connect the GND pin of the ultrasonic sensor to GND on the Arduino Uno.

Blue wire fixed on breadboard.

Step 4: Place the buzzer on the breadboard. The longer pin is positive while the shorter pin is negative.

Blue wire fixed on breadboard.

Step 5: Connect the positive pin of the buzzer to pin 4 on the Arduino Uno.

Red wire fixed on breadboard.

Step 6: Connect the negative pin of the buzzer to GND on the Arduino Uno.

white wire fixed on breadboard.

PROGRAMMING

Step 1: Open your Arduino IDE. See how to set up here: Getting Started.

Step 2: Type const int Echo = 2; as shown in the picture below.

code 1.

Step 3: Type int Trig = 3; as shown in the picture below.

code 2.

Step 4: Type int B = 4; as shown in the picture below.

code 3.

Step 5: Type

``` cpp
long duration;
int distance;
``` 
as shown in the picture below.

code 4.

Step 6: Type const int dist_threshold = 20; as shown in the picture below.

code 3.

Step 7: After the (void setup ()) within the curly brackets type

``` cpp
pinMode (Echo, INTPUT); 
pinMode (Trig, OUTPUT); 
Serial.begin (9600);
pinMode (B, OUTPUT);
```

code 4.

Step 8: After the (void loop ()) within the curly brackets type

``` cpp
digitalWrite (Trig, LOW); 
delay (200);
digitalWrite (Trig, HIGH); 
delay (100);
digitalWrite (Trig, LOW); 
duration = pulseIn (Echo, HIGH);
distance = duration * 0.034/2;
```

code 4.

Step 9: Type Function

``` cpp
if (distance < dist_threshold)
{
    digitalWrite (B, HIGH); 
    delay (200);
    digitalWrite (B, LOW); 
    Serial.print (distance);
    Serial.println (“cm”);
    delay (100);
    distance = duration * 0.034/2;
}
```

code 4.

Step 10: Save your code. See the Getting Started section

Step 11: Select the arduino board and port See the Getting Started section:Selecting Arduino Board Type and Uploading your code.

Step 12: Upload your code. See the Getting Started section:Selecting Arduino Board Type and Uploading your code

## OBSERVATION The Serial Monitor displays distance values continuously. When an object comes closer than 20 centimetres, the buzzer produces a sound alert.

CONCLUSION

This project helps learners understand how to combine sensors and output devices using Arduino. It introduces distance measurement, object detection, and alarm systems in electronics and programming.