0% found this document useful (0 votes)
32 views4 pages

Knock-Activated Melody With Arduino

Buzzer activated for iot with ai

Uploaded by

idalgavearpita31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views4 pages

Knock-Activated Melody With Arduino

Buzzer activated for iot with ai

Uploaded by

idalgavearpita31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Title: - Knock Detection and Melody Generation using Piezo Sensor and Arduino

Aim/Objective: - The aim of this experiment is to detect a knock using a piezo sensor
and play a melody on a piezo buzzer when the knock exceeds a predefined threshold.

Material Required:

• Arduino Uno R3
• Piezo buzzer
• Piezo sensor or knock sensor
• Resistor (suggested: 1 MΩ for piezo sensor)
• Breadboard
• Jumper wires

Software Requirements:

1. Arduino IDE (for writing and uploading the code)

Theory:

This experiment demonstrates the use of a piezoelectric sensor to detect vibrations, such
as knocks, and trigger a melody using a piezo buzzer with Arduino.

A piezoelectric sensor generates a voltage when it experiences mechanical stress (like


a knock), which is read by the Arduino's analog pin. The system continuously monitors
the sensor output and compares it to a set threshold. When the knock's intensity
exceeds the threshold, the Arduino considers it valid and triggers the buzzer to play a
melody.

The melody is pre-programmed using the tone() function to produce different musical
notes on the buzzer. The buzzer plays each note by oscillating at specific frequencies,
generating sound.

This experiment illustrates the application of knock sensors in real-world devices like
interactive systems, alarms, and sound-responsive applications.

Circuit Diagram

• Buzzer:

o Positive terminal connected to Arduino pin 9.

o Negative terminal connected to GND.

• Piezo sensor:

o One terminal connected to analog pin A0.

o The other terminal connected to GND.


• Resistor:

o Connect a resistor (typically 1 MΩ) in parallel with the piezo sensor


between the analog pin (A0) and GND to stabilize the readings.

Code Explanation:

1. Buzzer Pin: The buzzer is connected to pin 9 and is controlled to play a melody
when a knock is detected.

2. Threshold: A threshold value of 100 is set, and any reading from the piezo sensor
that exceeds this value is considered a knock.

3. Melody: A simple melody is stored in the melody[] array, and each note is played
when a knock is detected.

4. Serial Monitor: The Arduino reads sensor values and checks for knocks. When the
knock exceeds the threshold, it plays the melody.

Procedure:

1. Step 1: Build the circuit as per the circuit diagram.

2. Step 2: Connect the Arduino to your computer.

3. Step 3: Upload the provided code to the Arduino.

4. Step 4: Open the Serial Monitor (Ctrl + Shift + M) and monitor the analog readings.

5. Step 5: Knock near the piezo sensor. If the knock exceeds the threshold value
(100), the buzzer will play a melody.
Code:
Expected Results:

When you knock near the piezo sensor, the sensor will detect the knock and display the
analog value in the Serial Monitor. If the value exceeds the threshold (100), the piezo
buzzer will play a predefined melody.

Conclusion:

In this experiment, we successfully implemented a knock detection system using a


piezo sensor and an Arduino. The piezo sensor was able to detect the vibration caused
by a knock and convert it into an analog signal. By setting a threshold value, we filtered
out minor noise or vibrations and triggered the system only for significant knocks. When
a knock was detected, the Arduino played a melody using a piezo buzzer.

This project demonstrates the practical application of using a piezo sensor for vibration
detection and how it can be integrated with Arduino to produce an interactive output
like sound. The system can be further enhanced for various uses such as creating
knock-activated devices, security alarms, or musical interfaces.

You might also like