Arduino Plays the Piano by Itself

by cristinepotu7171 in Circuits > Arduino

567 Views, 5 Favorites, 0 Comments

Arduino Plays the Piano by Itself

snapshot117.png
IMG_20230618_093959.jpg
Arduino Self Playing Piano!
snapshot116.png


In this tutorial I present a simple project with amazing effects on the youngest who want to "enter" the world of microcontrollers. A device that sings by itself according to a preset program with the help of 2 SG90 microservomotors.

Supplies

arduino_433f0931b21c19369bcb8993eef059a4184628bc.jpg
Z1621.jpg
Servo-Motor-Pinout.png
images (6).jpg
1k-ohm-resistor__05927.1532890549.jpg
download (2).jpg
61vtHaM2tBL.jpg

1.Arduino nano board

2.8x10k LDR

3.2XSG90 servomotors

4.loudspeaker

5.8x3,9 kohms resistors

6.breadboard and jumper wires

7.wood pieces


Schematic Diagram

SCHEMATIC.jpg

The electrical scheme is simple, there shouldn't be any kind of problems when making it. You can also build the assembly on a definitive wiring board.The analog inputs of Arduino nano A0...A7 will be connected to the board with LDR



Mechanical Construction

IMG_20230618_093917.jpg
IMG_20230618_093955.jpg
IMG_20230618_094027.jpg
IMG_20230618_094329.jpg
IMG_20230618_095116.jpg
IMG_20230618_101146.jpg
IMG_20230618_101210.jpg

The mechanical part of the device is quite important. This can be chosen by everyone according to their imagination. In relation to this aspect, due to the mechanical positions of the LDR, the analog value from the software side will be modified accordingly. We see in the software section what and how must be modified depending on the mechanical construction. I present to you some photos from the mechanical construction of the device. remember that you can choose a different construction.


The Code

calibrate.png
calibrate2.png
enter READ POSITION VALUE details.png
change the tone details..png
READ POSITION SCHEMATIC.jpg
  • The code is built in Visuino, a simple and intuitive program with which you can easily program a microcontroller. As I specified in the "Mechanical construction" chapter, the displacement positions of the servomotors differ depending on the mechanical position of the components. Thus, to calibrate the lower servo motor, a calibration code is entered with which we read the value of each of the 8 positions on "Serial" and modify it in the main code. See in the photos. Likewise, the "Compare Analog Value" value, which reads the light value from the LDR, will have to be changed depending on the lighting in the area where the device will be used. See details in the video. In my case it is set to 0.79. As a rule, the value will fall between values ​​0.5, 0.8. Set the value and test that when the photoresistor is covered, the device emits the respective tone.Find two codes with two songs attached: Happy Birthday To you and Yankee Doodle. You can also find 3 tone possibilities in the code. I chose the 3rd tone. You can choose another tone by changing the output of the "Start" component pin to the Start pin of the "Timer" component. See in the photos.



Start the Device

snapshot118.png
snapshot119.png
snapshot120.png
snapshot121.png

Upload the code to the Arduino board. If all the values ​​have been filled in correctly, the device will start to move the servomotors and play one of the two songs, depending on the chosen code. Remember that the lamp is sensitive to the variation of light intensity, you can replace the LDR with infrared receivers to counteract this aspect. Or put a plastic tube over each LDR... here imagination and creativity play a special role. You can try to compose other songs, adding the times in the "Sequence" component.

I hope you liked my project, for any questions we can chat in the comments section!