Piano Sounds Using Arduino on TinkerCad
by Mudit5246 in Circuits > Arduino
13102 Views, 4 Favorites, 0 Comments
Piano Sounds Using Arduino on TinkerCad
In this tutorial, you will learn how to use a buzzer (or piezo speaker) with Arduino. Buzzers can be found in alarm devices, computers, timers and confirmation of user input such as a mouse click or keystroke.You will also learn how to use tone() and noTone() function. Using this function you can make a piano sounds. So lets start.
What You Will Need - Hardware
For this tutorial you will need:
1.Arduino UNO or nano
2.Buzzer/piezo speaker
3.Breadboard( if you are making project in real-time)
Circuit
The circuit is really simple you to connect the negative pin of the buzzer to gnd of the Arduino and positive pin of the buzzer to digital pin 8
The Code
For more interesting projects connect with me on:
Youtube: https://www.youtube.com/channel/UCTS10_CRYJhT-vb9-...
Facebook page: https://www.facebook.com/techeor1/
Instagram: https://instagram.com/official_techeor?igshid=uc8l...
Here's the "Tone" code. How does it work? It's simple, tone(buzzer, 1000) sends a 1KHz sound signal to pin 9, delay(1000) pause the program for one second and noTone(buzzer) stops the signal sound. The loop() routine will make this run, again and again, making a short beeping sound. (you can also use tone(pin, frequency, duration) function)
int buzzer = 8; void setup() { // Defines the Buzzer pin as output pinMode(buzzer,OUTPUT); } void loop() { tone(buzzer,261); delay(200); //Turns the buzzer off noTone(buzzer); tone(buzzer,293); delay(200); noTone(buzzer); tone(buzzer,329); delay(200); noTone(buzzer); tone(buzzer,349); delay(200); tone(buzzer,201); delay(200); //Turns the buzzer off noTone(buzzer); tone(buzzer,283); delay(200); noTone(buzzer); tone(buzzer,502); delay(200); noTone(buzzer); tone(buzzer,149); delay(200); }
Well Done
You have successfully completed one more Arduino "How to" tutorial and you learned how to use: buzzer / piezo speakertone(), noTone() functions
Hope you liked this, let me know in the comments.