Knock-Activated Melody With Arduino
Knock-Activated Melody With 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:
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.
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:
• Piezo sensor:
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:
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:
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.