Box with a musical lock

    Introduction




    What kind of castles did you come up with! And with a tricky key, and a combination of numbers, and with the recognition of body parts. However, I wanted to make a castle that I had not yet met. Since I am fond of playing the piano, I did not have to go far for the idea: it was decided to make a casket that opens only after “hearing” a familiar melody.

    In this post I would like to talk about the algorithm for recognizing the melody, about the control circuit and the process of creating the box.



    What happened




    Melody recognition


    As you know, what we perceive as sound can be considered as shocks of air into the eardrum. He pressed the air - he registered the nerve. What we perceive as a note can be considered as tremors with a constant period. In other words, if you tickle this nerve 130 times per second, then we will “hear” the “do” note.
    A device that recognizes notes tries to understand how many times per second the microphone was tickled and what frequency it turned out (and, therefore, a note). The transition from frequency to note is a simple thing, there is a table “frequency → note” .

    There are several different algorithms that turn microphone data into frequencies. The most famous is the Fourier transform. The principle of operation is as follows: with what force was the air pressed on the microphone at each moment in time. The output is how much what frequency was contained. His work is most easily explained by the picture:



    So it would be possible to realize the recognition of notes. At each moment in time, determine which of the frequencies is the loudest. If it matches the expected, proceed to recognize the next note or open the lock if the melody is over.

    However, we will go the other way. It is not necessary for us to know which particular notes are played. You just need to find out if the note we are currently playing is playing. Goertzel’s algorithm comes to the rescue . This algorithm is used in telephony when it is necessary to determine the tone. The bottom line is simple: the algorithm is given the desired frequency and data from the microphone, and he answers what the “volume" of the desired frequency is.

    You can take a look at the implementation of the algorithm in the NoteDetector.cpp file .

    Component Selection


    I settled on fairly standard components. Here's what came in handy:

    ATMega328P with a 16Mhz chip is the brain of the device. The choice fell on him, because it hurts just to work with him.

    Electret microphone with OPA344 amplifier - these two devices were sold as a kit on a single board on the Sparkfun website . Data from this device can be read directly from the analog input of the microcontroller. Servo Spektrum SPMAS2000L

    - This servo opens and closes the lock. I was very glad that I found such a detail. The servo is powered by 3.3V and supports the usual protocol. This is a linear drive, that is, instead of a spinning head, the drive has a slider that walks left and right by about a centimeter. On the sides are ears for fastening.
    This motor is commonly used in the world of aircraft modeling. As far as I understand, they are regulated by aileron deviations. You can read about it on the manufacturer's website .

    The TPS2020 circuit breaker is an excellent circuit breaker with very low power consumption when turned off (10 μA). He will manage the power of the servo.

    Regulator LM2936Z- a 3.3V linear regulator with a small current at the operating point (≤ 15 μA). What is needed for our device, which will be powered by a battery.

    The MAX1555 Charger is a chip that controls battery charging and blinks when the battery is full.

    Scheme


    There is nothing particularly complicated in the circuit of the device. Here you can find the full outline. And here is a simplified diagram that explains what components have to do with it:



    It turned out to be quite interesting to arrange the board so that it fits in a small box. Since I decided to do everything myself, at home, options with a multilayer board did not fit. Therefore, I had to come up with a fake multilayer board: the device consists of two levels that connect as shields for Arduino. It turned out something like this: The



    blue connections are the ones that will be on the board itself. Reds are those that will be added later, either with nameplates or wires over the board.

    Board Creation


    I decided to use the photoresistive creation method. I described it on a habr , so I will only give a couple of pictures.

    We print the scheme on a transparent film and cut out the base for the board: Board


    before tinning and making holes:


    Boards on one side:


    Boards on the other side:


    Assembled boards:


    On the other hand:


    Casket Making


    The box consists of the box itself and the walls surrounding the circuit and motor. I decided to buy an unfinished box to cover it myself with paint and varnish. I ordered the walls and accessories on the Ponoko website : you can send them a drawing in SVG, and they can cut it with a laser on thin plywood. The drawing can be found here . Here is what this drawing and its implementation looks like:


    Plus three weeks:


    After these parts were integrated into the box, it turned out like this:


    Now you can paint the box and cover it with varnish. I applied two coats of paint and two coats of varnish, so that for centuries. Perhaps there is nothing particularly complicated in this process. Unless you need to skin the tree very high quality: the places where you fished are clearly visible. Here's what happened:


    The lock mechanism looks like this:


    Result


    As a result, the circuit perfectly fit into the box:


    I took the craft to a few of my friends: the correct melody is recognized on different pianos: on electronic pianos, and on regular pianos, and on the piano. Recognition accuracy: half a ton.

    The source code of the controller, circuit and drawing of the board can be found on Google Code . I will be happy to answer any questions, listen to criticism and suggestions.


    Also popular now: