int buzzer = 11; // Buzzer connected to pin 11
void setup() {
// No pinMode needed, tone() handles it automatically
}
void loop() {
// Tone(pin, frequency in Hz, duration in ms)
tone(buzzer, 440, 500); // Play note A4 (440 Hz) for 500 ms
delay(700); // Wait 700 ms before next tone
tone(buzzer, 880, 500); // Play note A5 (880 Hz) for 500 ms
delay(700); // Wait 700 ms before repeating
}
Instruction Details
Wiring: Connect passive buzzer positive to Digital Pin 8, negative to GND.
Library: Not required (built-in tone() function).
Upload Code: Tools → Board → Arduino Uno. Tools → Port → select your COM port. Click Upload button.
View Output: Buzzer plays police siren melody. Add 100Ω resistor in series if volume is too loud.
How to Use
Connect the required components as per the Pin Configuration above
Open Arduino IDE and create a new sketch
Copy and paste the code above
Select your Arduino board and COM port from Tools menu
Click the Upload button to upload the code to your Arduino
Open Serial Monitor (if applicable) to see the output