Piezo / Buzzer Interfacing with Arduino Board
In this article, we learn how to interface Buzzer with Arduino UNO. The buzzer is also known as a piezo buzzer. It makes sound according to the signal frequency. It can be used in a variety of alarm systems so interfacing the buzzer is important.
Components Required:
- Buzzer / Piezo Speaker
- Arduino Board
- Breadboard and Jump Wires
- 100 Ohm Resistor Optional
Circuit Diagram:
Steps To Follow:
- Open Arduino IDE.
- Click on File.
- Go to New. – A new File will open
- Remove the Pre-Written code.
- Paste the code given below:
- Check whether your UNO has been detected by the ID by going to Tools.
- Click on Port – Select the COM-Port on which Arduino UNO is detected.
Code:
const int buzzer = 9; //buzzer to arduino pin 9 void setup(){ pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output } void loop(){ tone(buzzer, 1000); // Send 1KHz sound signal... delay(1000); // ...for 1 sec noTone(buzzer); // Stop sound... delay(1000); // ...for 1sec }
Challenges:
(a) Play the Buzzer with a 2 Second on time & 2 Seconds off time.
(b) Play the Buzzer with a 5 Second on time & 2 Seconds off time.
(c) Fade out & Fade in the Buzzer with changing intensity.