How to make a music box with a melody. Music box mechanism

08.03.2019

We will talk about a device that is very simple to manufacture (even for a beginner amateur electronics engineer), but at the same time extremely interesting and useful - an electronic "music box". Also, as an example, I will show and tell about one of the possible incarnations and applications of this device - about the last gift made on its basis to my girlfriend.

History of creation

There will be many letters related to the matter rather indirectly, and if you want,

It all started a long time ago, a few years ago, when I wanted to give a girl some interesting, original and memorable birthday present. And of course with your own hands. There was very little time left before the holiday, two days, during which it was necessary to come up with something and, in fact, implement it. The day was spent thinking - hundreds of different options were spinning in my head, from all kinds of LED “flashing lights” - hearts, to various electro-mechanical crafts. But all this was not right: either too simple and beaten, or vice versa, quite complicated (and there is absolutely no time left!). Suddenly, a simple, but wonderful, as it turned out later, idea came to my mind: why not make a musical postcard? And not simple, but with a "chip", with an original melody. Moreover, we had “our own song”, under which we met and which evoked all sorts of pleasant romantic memories and experiences in us.
So the very first version of the “music box” was born, the progenitor, so to speak. Very simple, assembled hastily hinged mounting from PIC12F675, piezodynamics, photodiode, a pair of resistors, a three-volt element 2016 and packed in a postcard drawn in Photoshop. As a result, this postcard was able, when opened (and the light hit the photodiode), to register the same melody with a rectangle. That's it, simple and uncomplicated.
But the idea turned out to be extremely successful, many times more than I expected. Later I made a few more simple postcards at the request of their friends, for their soul mates. And in each case, such a gift evoked a lot of emotions both in the recipients themselves and in their parents, girlfriends and acquaintances :)
Quite a lot of time passed, everything started spinning, the project was forgotten. But it so happened that I again remembered about music box. This time it was supposed to be a gift for March 8th. At that time, I actively studied Atmel microcontrollers, in particular, played with ATtiny45, and decided to improve the music module for this. Moreover, this time there was a lot of time. That's where it all started.
looking out different information on the Internet, I came across the site of Mr. Chan, widely known in narrow circles. More specifically, on one of his designs, a miniature synthesizer, just on my favorite MK :) Some time ago I almost finished a four-channel synthesizer on PIC18, but, alas, I destroyed the achievements in my heart (which I later regretted more than once). And Chan's design was quite self-sufficient and complete. It remained to add to it only the "trigger" and go!
I finished the code a little, and the trigger mechanism was ready. But then everything turned out to be somewhat less rosy. The main problem with the design was that it sounded too quiet. No matter how I tried, with the direct drive of the speaker from the MK pins, it turned out quietly and that's it! As a result, a strong-willed decision was made to add a power amplifier. The choice fell on the LM4900, which was then available in Terraelectronics. Again, I had to make some more changes to Mr. Chan's code in order for the synthesizer to work correctly with an external amplifier - to make the power saving leg control so that the amplifier does not eat the battery when idle and reconfigure the PWM to correctly output a signal from one pin. After these changes, the prototype worked just fine. Then I drew the first version of the board (in which, as it turned out later, a jamb crept in :) and assembled the music box in a human way. Further, everything is on the beaten path - a home-made postcard, installation of the module and donation-delivery.
Of course, this device was several heads higher than the previous ones - a very realistic sound of a "real" box and polyphony made themselves felt :) The gift, like in previous times, caused a sensation a long time ago. And I also collected about a dozen of these modules for my friends.

Now about the device itself

The current version of the module, the third in a row, contains a few more changes and one interesting innovation - light and music channel, to which you can connect, for example, an LED. But first things first.
Let's start with the diagram, it's very simple:


Her heart is a microcontroller ATtiny45/85. He is engaged, in fact, in the synthesis of music, manages the light and music channel and the energy saving of the amplifier. The second most important element is the audio power amplifier TPA301D. Connected to amplifier speaker, which is outside of the module. There is also a transistor BC847, which controls the light and music channel and several passive elements - resistors and capacitors. It all feeds on 2-3 alkaline elements (for example, AAA) located in the outer battery pack(the most common, Chinese). As you can see, the circuit is really elementary.
The principle of operation of the circuit
Most of the time the device is in "sleep mode". MK falls asleep at the command of the firmware immediately after turning it on, previously “putting to sleep” the amplifier, setting it on its leg SHUTDOWN high level(by connecting a weak leg lift "PB0" to the "+" power supply inside the MK). MK wakes up on interruption from the foot "PB2/INT0". Initially, the leg is also pulled up to the “+” power supply inside the MK and it must be shorted to the ground.
From the "PB1 / OC1A" leg of the MK, the audio PWM signal, in order to filter it from the carrier, passes through the simplest second-order RC filter ( R2-C3), which must be calculated (and in our case it can simply be “estimated”) for a cutoff frequency that is much lower (ten times) than the carrier frequency. And the filtered signal, through the blocking capacitor C2, is already fed to the input of the amplifier.
MK also controls an additional, light and music channel. For this, an npn transistor is used. Q1 in key mode, the base of which is connected to the leg of the MK PB4/OC1B through a current limiting resistor R1. There can also be a limiting resistor in the collector circuit ( R3) would not be redundant. The transistor is also driven by a PWM signal. Everything is done very simply - in the best traditions of "flashing" LEDs from the "arduino" :)
For nutrition, there is a decoupling tantalum ( C1), the simplest body kit of the amplifier, which acts as a decoupling ( C4), and adjusting the gain (volume), in general, is peeped in the datasheet for the amplifier. If necessary, the KU can be calculated quite accurately using the most common method for the op-amp, the ratio of the resistance of the input resistor R4 and resistor feedback R5, since it can be useful to adjust the volume for a particular speaker or design.
Printed circuit board
Simple to disgrace, drawn in DipTrace:


This is the third version, which takes into account all the previous shortcomings.
The board is designed for surface mounting and one-sided, which greatly simplifies the process of its home production. You can apply any method: laser ironing, photo method, or even draw tracks with a marker (for an amateur, of course).
All elements - 0805 (including "zero" jumpers), tantalum - A or B, a transistor in SOT23 and an MK with an amplifier in SO-8. All "peripheral" components - a battery pack, speaker, LEDs and a button (photoresistor, reed switch) are soldered to the corresponding "circles" on the board. That's all.
Software part

A bit about sound synthesis

You can read about the synthesis method used in the device in the original by Mr. Chan. You can also google "wavetable synthesis". If you do not speak the language, then in short, the memory of the MK stores a sound sample(a single sound), the so-called. "wave table", which in our simplest case is conditionally divided into two logical parts, which in general form "envelope" - attack, the beginning of each new sound, and "sustain", shutter speed, a fragment constantly looped throughout the sound of a note. Is there some more "decay", "tune-in", the part that sounds after the note is removed. We implemented it simply by gradually fading the sound of “sustain”. The MK has a timer that causes an interruption at a certain frequency, where, in accordance with the current position of the “envelope” and the pitch of the note, desired value from sample memory. Moreover, in this way it is possible to synthesize several channels (that is, notes) at once, everything depends only on the processing power of the MK and the sampling frequency (sound quality). Then these values ​​​​are mixed and sent "to the output" (in our case - to the PWM control register). All this disgrace, as I mentioned above, is called “Wavetable synthesis” or “table-wave synthesis”.


The core of Mr. Chan's synthesis has remained virtually unchanged. I only slightly changed the PWM output method, due to the rejection of the “direct drive” of the speaker with the MK. Added a “trigger”, power saving control of the MK and amplifier, and also wrote the code for controlling the light and music channel, which works in the following way: on a special event from the score to right places“lights” the LED, and then smoothly “extinguishes” it. Well, I “ported” (strongly, of course, it is said) the code to the Studio, for convenience.
The code is written in AVR assembler and consists of several files: mbox.asm- in fact, the program itself; "notes_pitch.inc"- an indication of the correspondence of the mnemonic names of the notes used in the score, the coefficients of increment of the pointer position in the sample (that is, as a result, the pitch); wavetable.inc- sample data ("table") and decay curve "decay"; A score.inc, as you probably guessed by the name, contains the score performed work, "notes".
Initially, in "wavetable.inc" Chan himself "hammered" the sound of the box. But if necessary and desired, it can be changed to any other using an auxiliary script wav2asm.pl or just by hand.
The situation was more complicated with the score. Originally it was supposed to be written by hand, which will undoubtedly bring a lot of pleasure to human masochists, especially if the score is not at all simple.
For a person who is going to use his score and, presumably, on this occasion, at least somewhat familiar with music and musical notation, it would be easier to draw the score in any available notation editor and somehow use it. For this I wrote a special converter program, which accepts a midi file of format 0 as an input, and gives the finished file "score.inc" as an "output". It can also independently arrange LED ignition events for all notes found in the first channel, that is, if the melody is initially logically separated from the accompaniment and moved to the first channel of the MIDI file, then we will get a score that will light the LED in time with the melody, if we want and put a daw. In fact, it is perhaps one of the most beautiful options additional channel operation.
The program is also able to transpose the resulting score by one or two octaves up / down, which in certain cases can greatly facilitate the work of writing the score.
The interface of the program looks simple, understandable and unpretentious, and the Delphi sources are included in the kit:

By the way, as I was prompted at the time (for some reason I didn’t think about it at all), there are a lot of resources on the Internet where you can get ready-made midi with the desired melodies. They will only need to be slightly modified for use in my converter. And some may not even need to be modified.

What else might be needed?
Let's say you bought / got all the necessary components, made a board in one way or another, or, alternatively, simply soldered everything by surface mounting. What else will be needed? You will need a programmer. If you already have or are dealing with an AVR, then you most likely already have it. And so, suitable, for example, "USBasp" in hundreds of incarnations or any other. There is nothing supernatural here. The archive with everything-everything has an already compiled binary, which can be immediately uploaded to the controller and used if there are no intentions to edit and rebuild something.

Application

And now, as promised, I will tell and show one of the hundreds of possible applications of the module, musical rose Kawasaki.
Rose Kawasaki, one of the masterpieces of origami, is generally a separate big topic, which you can fully familiarize yourself with on the Internet.
Structurally, the thing itself is made of two parts:
First, rose, folded from a colored sheet of paper and glued to a twisted stalk with leaves (also folded from colored paper). A thick copper wire runs inside the stem (for strength) and a small neodymium magnet is hidden at the very bottom.
Second part, vase, cut and glued from thick white cardboard. Inside it is installed the module itself, a speaker (glued to a resonating volume filled with cotton wool), super-bright white wide-angle LEDs, matted with fine sandpaper and a battery pack fixed at the bottom of the vase for easy access to batteries. And, of course, the reed switch is a “trigger mechanism” that works in tandem with a magnet in the stem. It is installed in such a way that the module is activated when the rose is taken out of the vase.
Schematically, it looks like this:

Here are a couple photos of the prototype:

And video work. The composition “Tenderness” plays on the video, which I arranged for the box, and which is included in the archive as a source (typed in Sibelius) and a midi, as well as a finished generated score:

As usual, my eternal problem with normal sound in the video makes itself felt. A thousand apologies. If you are interested in listening to how the design sounds in normal quality, you can download

I came across some interesting things from AliExpress on the lifehacker website. Namely, the mechanism for the music box. And without thinking twice, I ordered this gadget for myself :)

I was very interested in this position, since from childhood I liked to watch in films how the heroes play a melody from caskets. I like the tone of such melodies, the rhythm and stuff like that.
The idea itself is extremely simple. You can make any box with your own hands and insert a mechanism there, it will turn out original gizmo. But since my hands are growing out of the wrong place, I just love to listen to this melody without external embellishments. Plays here by the way Castle in the Sky Theme Song. I don’t know where and who the author is, but I like it :)

The parcel went for about a month. Tracking stopped after crossing the border. Apparently the Chinese saved on a normal track code. Anyway.


Packed in a regular bag and thin foam. No bubbles :(


They also promised 4 screws, and there were 2 current in the package, but these are minor quibbles.
Dimensions 5 cm by 4.5 by 2 Everything is connected on one frame.


Sounds are produced by plates of different lengths that are caught by a small drum with protrusions in certain places. The Chinese have such drums for different songs and it would be interesting to rearrange them depending on the mood.


Everything is set in motion by a spring that is turned on with a special key. There is nothing more than nanotechnological here :) What would the melody play more evenly, there is a braking roller.




If you hold the mechanism in your hand, the sound is very quiet, well, everything is perfectly audible on the table.

The seller promises 500 repetitions of playback, in the future it will be seen how this mechanism behaves.

I plan to buy +19 Add to favorites Liked the review +40 +59

Our little princess, my beloved niece, is approaching her first birthday in her life. For her mom's (my little sister's) birthday in February, the kids smashed our baby's favorite musical toy, glass bowl with bears. And I didn't let it go musical mechanism out of it with the expectation that I'll come up with something. And so I decided to make a box. Girls love boxes. I am a girl myself and I know :) While our Sonechka is little, mother will collect treasures beloved by girls in the form of beads, rings and bracelets.
One of my hobbies is boxes. self made, and for a long time that I have been doing this, I have already accumulated a lot of all sorts of materials.
So. We need a cookie or candy tin. You can also buy just a tin can. You can now find any cans in needlework stores. I found cans in a tea and coffee shop. Just banks. But this time I got a can of cookies from the Spartak confectionery factory. She is big. 22 cm in diameter and 7.5 cm in height.

Metal putty, acrylic primer, acrylic varnish, PVA glue, brushes, decoupage rice card with notes (rice card can be replaced with a decoupage napkin), scissors, musical mechanism. We will also need a glue gun and a glue stick. I love working with rice pads and cards. Under the influence of glue, they do not tear or deform. And they have a nice texture. Everything else will be selected in the course of work. Sometimes at the very beginning I do not know what I will get as a result. That is, usually at the very beginning there is some theory, but very often something changes in the process of work.
But in my bank there is one significant minus. The surface of the lid is not smooth. Cookies are squeezed out on it. Therefore, I took a car putty for metal and leveled the whole thing. There is no photo of the process, since there was no one to photograph, besides, the putty stinks extremely sharply and unpleasantly. When the putty has dried, it must be sanded. I deliberately did not sand to perfect evenness and smoothness.

Then we cover our entire future box with primer in one, and preferably in two layers. The second layer is applied only after the first layer has dried thoroughly. I think it is not necessary to explain what the soil is for.

So everything dried up. It's time for our napkin. First glue the lid. Remembering the lessons of labor in primary school. We cut out a circle with a diameter equal to the diameter of the top of the lid plus the height of the lid plus a couple of centimeters, just in case. We apply glue to the lid with a brush and carefully apply our circle to the top of the lid, level it so that there are no wrinkles. Very careful not to tear. Unfortunately, there is no photo of the process, since there was no one to photograph. We leveled it on the upper part, now we take the lid in our hands and carefully, wetting it in glue, glue the card to the side walls of the lid with a brush. In the same way, it pastes over the lower part of our future box. It's easier here. You need a strip of height from the locking rim to the bottom plus the height to the bottom. I have plus 5 mm to the main length. And a circle. We put our box on the map and outline it with a pencil. Let's dry.

I was dry for several hours. The adhesive must dry completely before applying the varnish. Otherwise, the varnish will stick to your hands. I bought wood varnish from a hardware store. Special varnishes for decoupage let me down more than once. They are expensive and stick to hands. finished product. So I went and bought varnish from a hardware store. I don't like gloss, so when choosing a varnish, I settled on a varnish that has a matte surface.

So, the next step is to apply varnish. Lacquer must be applied strictly according to the instructions. In two layers. Dry each layer thoroughly.

Here you go. Dried up. Now the fun begins. At the very beginning, I forgot to make a hole for the musical mechanism, so I had to make a hole after applying the varnish. Make the hole very carefully. I neglected safety precautions and stuck a screwdriver in my finger right into the wreath. Filling the hole with peroxide and barely stopping the blood, I proceeded to attach the musical mechanism. Due to the fact that I was slightly injured, I forgot to take a photo of this process. Then it turned out that the key that a familiar watchmaker picked up for me was very large and ugly. And then, with the help of my charm, I persuaded a familiar turner to make me a small key made of brass. Here he is handsome.

So. Now let's start working on the interior decoration. First of all, you need to finish the walls, the bottom and hide the mechanism. We take cardboard and cut out the details. Somewhere long ago I dug up a very cool pressed cardboard 3 mm thick. From it I cut out the details that I will hide the mechanism. The bottom and sidewall were cut out of cardboard with a density of 300 g / m2. We cut out the same details only with an allowance from velvet. Here are the details. We take glue stick and velvet. I really like to glue the fabric to the cardboard with a glue stick. I'm buying expensive pencils firms Kohinoor or Erich Krause. But now, as luck would have it, I did not find either one or the other and again bought the most expensive glue stick from a German manufacturer in a hardware store. I took it at my own peril and risk, but it justified itself. So, we apply glue to the cardboard and apply velvet. Let dry and glue the seam allowances. Something like this.

sidewall

This is a mechanism box.

back side

bottom

Using a glue gun, we fix the velvet details inside the box. Here it is in finished form.

Next, we make a drawer for small things. Initially, I wanted to make a box that would be like a continuation of the box for the mechanism. But when I tried everything on, I realized that it was some kind of garbage and decided to make a drawer separately. I cut out a circle sector (cover) and a wall of thick cardboard. I pasted them together at a distance of 4 mm from each other so that the structure was bent. Trimmed the velvet around the edge. I sewed the edges of the velvet with a needle and thread. And secured everything inside the box. Everything seemed pale to me, and with the help of a glue gun I fixed the brown satin cord at the joints. Beads as a stopper so that the lid does not fall through.

Glue on both sides. Bends.

Sew the edges

I looked at the result and decided to add another branch. And to make it interesting (I'm making a box for a girl), instead of a lid, I made an imitation of a bag tightened with a satin cord. Everything is attached with a glue gun. Here you go. It seems to be nothing.

Here it is with the bag

Now you need to decorate the outer part of the box. I'm honest and long and in different places I was looking for the braid that I needed, but I did not find it. And so I bought what I had in order to do what would suit me. Organza ribbon, satin cord and velvet stripe. I took an organza ribbon and glued a velvet strip on it with an iron and glue tape. I glued all this beauty to the box with a glue gun. Something is missing. Pale. Then I glued the satin cord along the edge of the velvet ribbon with a glue gun. From velvet and organza ribbon, I made a bow and attached it next to the key. Thus, I hid the junction of the braid and hid the key a little.

To do this, you will need the following materials and tools

Saw in the form of a tape for the machine;
- Machine for grinding;
- Electric drill
- Cutter
- counterbore
- Music: (which you like).

Additional materials:

Toy wooden xylophone;
- The remains of a tree, preferably a fruit tree or walnut;
- Means for pasting of products from rubber and a tree;
- Threaded screws for fixing drywall;
- dowel rod;
- Corresponding to axes metal washers;
- Beeswax with orange oil.

Before drilling holes, you need to turn the surface of the cylinder into stave, to do this, draw one after the other lines around the entire circumference, and 4 lines perpendicularly. Install the drum in the frame to make it easier to determine the center axle.

Here you will need a sheet of plywood. Make gears with computer program, print, stick them to the wood material and cut them out with a saw on the machine. If the material is made of fibers of alternating directions, then this will provide good strength.

2. Make hammers
Hammers will also require wood material, the length of which should match the xylophone.
It is necessary to make guides. To do this, use the link under the photo to the Inkscape file, print it and stick it on the guides. For cams, take 3 mm birch plywood, for hammers and axles, cherry trimmings 1 cm wide.

Attention! Hidden text will be available after registration or authorization on the site.

3. Other details
You'll need a base to support the instrument, and keep the notes clear with a hammer drum so they don't bounce. To drive, make a lever handle.

4. Ready musical

Well, why else would I want to buy a music box? Then I saw a review, there I saw a mechanism - the puzzle came together and here it is on my table in a pretty box.

On Aliexpress, you could buy a ready-made design, but then the toad woke up and began to choke me. Give more than 3 c.u. for a music box? If only it will be made of gold with diamonds ( ok, fianites)...

It was decided to buy a musical mechanism and make a box on our own.

Cost at the time of purchase: $2.9

The mechanism was packed in such a way that at first I thought that the seller had made a mistake and sent me the music box already in some kind of case. But when I unwrapped the package, it turned out that the main volume was the packaging material. For what? ATTENTION: so that the cardboard box with a bow does not wrinkle.

The mechanism itself is metal - it is unlikely that something will happen to it, even if you step on it. Even the protruding part of the handle is very durable.

Everything is extremely simple. We take the mechanism, select or make the box ourselves, install the mechanism into the box with bolts ... STOP! Where are the promised bolts?

I remembered about the bolts a week later, when I climbed again to look at the description of the seller's goods. He has a mechanism in the photographs with 3 bolts for fastening, but it came to me without them. Where are my bolts???


I had to sculpt double sided tape to the bottom of the box. And since my husband had a period called: " What else can be glued with two-phase glue?", then the mechanism was planted on it for reliability. Is there a lot of glue left? It doesn't matter ... now we will seal the box tightly!

On my question: " Why did you seal the box?"There was no answer, the husband just shrugged his shoulders and smiled. I had to sigh languidly, shake my head and try out the mechanism in action in the new case from the old Raketa watch.

I had to make a hole in the box for the handle. The Chinese Dremel easily coped with this task ( feedback will be). But why the husband needed to make a second hole - again remained a mystery. The sound was exactly the same without it.

DESCRIPTION.

The mechanism and body are metal except for the plastic gears and the inner drum. The knob rotates in both directions, but the sound only gives the correct direction.

Mechanism size 4.4 x 3.4 x 2 cm + rotating handle.


The handle has a movable tip for easy rotation.

The seller sent the order in random order and out of 6 melodies I got the 002B drum with music - "The Finale of Swan Lake".

There is a possibility that you can ask the seller to send a specific drum, but for this you need to know all their numbers and sounds. I was satisfied with the choice of the seller.

The sound will be loud if the mechanism is installed on a hard surface. In the box, the sound is doubled. If the music box is turned in the kitchen, then it will be heard even in the room.

The melody is pleasant, the spelling noticed only one thing at the end, but maybe it should be so. The faster you turn the knob, the faster the melody plays and vice versa: the slower you turn, the slower the drum rotates.


FOR A CHILD.

I bought the mechanism for various reasons:

  1. I wanted to.
  2. Child development.

What can develop the music box mechanism in a child:

  • Logic and ingenuity - where and how to rotate so that the melody sounds.
  • Rumor - pleasant melodies with the right notes.
  • Sense of beauty - Swan Lake and the music from it is a classic.
  • Fine motor skills - the handle is small and you need to hold it firmly with your fingers.
  • Sense of beat (rhythm) - rotating faster or slower sets the pace.
  • Fantasy, imagination - if you make the body together.

CONCLUSION.

I was satisfied with the mechanism and the child liked the music box. The money spent is not worth it. There was an idea to make a music box in the design style pasta and cereals, coffee beans, quilling or appliqués...

When I calmed down my raging fantasy, I realized that the child would not let the design live long and the most reasonable version of the music box would be just a tightly sealed square watch box.

I wish you happy shopping!

AliExpress is a wholesale online hypermarket. The subtleties of Ali, his pros and cons, our endless orders (accessories, microcircuits, appliances, toys, for myself, etc.) in a photo report from a shopaholic.

Pay for purchases on Ali



Similar articles