If your young child has a keen interest in musical toys, do something like that.
It took me about 3 days. Having everything you need + my achievements, you can cope in a couple of hours.
Theremin with an ultrasonic sensor has been wandering around the Internet for a long time. There is even a variation with an optical sensor .
All of them have drawbacks: with high sensitivity to changes in the position of the hand it is difficult to get into a note - worse than on the violin, with the “quantization of space” there are breakdowns, squelching, etc.
I solved these problems + there was an interesting effect that sets the rhythm.
As the "brain" I used the Chinese Arduino Nano. The case is a box of DVD discs (and where else?). Everything is assembled as a prototype.
You can use ordinary instead of piezodynamics. The sound will be much louder. You can do this if you have strong nerves.
The piezo speaker is attached with a glue gun to the body - this way we get a slight sound amplification. We attach the sonar in the same way.
I would like to draw your attention to the quality of the wires for the HC-SR04 sonar. They must have good contact, otherwise it will constantly fail.
I had to “file” the connecting wires. Ideally, there should be soldering.
The switch is held by its own stops. The main thing is to carefully cut a hole to the size of its body.
I added some porous polyethylene to keep the battery from loose.
Device diagram
The toy reproduces the C major scale of the first octave (+ up to the second octave) at intervals of 9 cm per note. The interval can be adjusted.
// . . .
#define MIN_SM 1
// . .
#define SM_PER_NOTE 9
// /
#define GAMMA_PIN PC2
It is possible to switch to C minor.
In my craft, the hardware fret switch is not implemented. You can easily do it by connecting PC2 to ground.
The radiation pattern of the HC-SR04 has the shape shown in the figure below. The device works not only directly above the sensor. Therefore, it is better to use it away from walls and other "obstacles". For example, on the floor in the center of the room.
Toys work video
The toy works well from a single 18650 cell (4.2V max instead of 5V).
You can download the project in Proteus and the source code (+ BONUS) in AtmelStudio for repetition and further development from my github.
An undoubted positive effect of the toy will be the fact that the child does not just press the button and listens to the composition, but moves his hands and body, creates, develops coordination and hearing.
Who knows, maybe your future Paganini is growing.