
Generating sound: Buzzer
Play a melody with a passive buzzer
What are we going to do?
In this activity you'll play a melody with the help of a passive buzzer. Remember the difference between putting code inside setup function or putting it inside loop function.
You can use the code from Arduino IDE -> File -> Examples -> Digital -> toneMelody but you'll need to change some parts.
UNO board
You can use any Arduino UNO original or compatible board
USB cable
Depending on your board, you'll need a microUSB cable or a miniUSB cable
Computer
You need a computer with Arduino IDE software. If you don't have it, follow this link with instructions to download and install it.
Buzzer brick
A passive buzzer with SVG connections
Let's get started
Follow these instructions carefully. You can click on some of the images to zoom in.
Always connect the components BEFORE powering the UNO board or YOU MAY DAMAGE YOUR BOARD OR COMPONENTS.
Instructions
2. Open Arduino IDE
Once you've opened the editor, open the button example from File->Examples->Digital->toneMelody
3. Change code
If you connect the buzzer to pin 8, you won't need to modify anithing. Otherwise you'll need to modify example to make it work with your circuit. IF NECESSARY, change number 8 for the correct value on all references on your code
4. Upload to the board
Use the upload button to transfer the program to your board. Once done, you should read Upload completed. That means the transfer was succesful. If it's not succesful, try disconnecting your board and connecting it again and repeating the upload process.
5. Final result
After uploading, everything should be working as planned. Otherwise, double check connections and code.
Congratulations, you've done it! You're on the right path to be a maker! 🙂
Now, what else?
Now is your turn:
- Change the code to use a variable instead of the number 8. What do you think would be a good name for this variable?
- Search the Internet and try changing the melody to a famous song or soundtrack
Pingback: Hello world with Arduino: Blink – makit
Pingback: LDR sensor – makit
Pingback: Seven segment display – makit
Pingback: Encoder and servo – makit
Pingback: PIR sensor – makit