Design Con 2015

DIY office door castle knocker

Chris Taylor, project manager, engineering, SparkFun Electronics -October 16, 2012

We're always looking for more ways to make our office fun and strange. I don't often work with my door closed, but the majority of time when someone comes into my office, they give the door the ceremonial announcement rap to indicate their presence. I decided to have a little fun with that.

Instead of the door making the standard boring door noise, I wanted my door to sound like the castle door knockers from Young Frankenstein.


Soitenly. You take the blonde, I'll take the one in the turban.

In order to do this, I would need a few things:
  • something to detect the knock and
  • something to play the sound.

For the knock detection, I chose our Large Piezo Vibration Sensor.



This sensor is perfect because it's cheap and only requires a resistor to be used with an Arduino ADC. The sensor outputs a small AC voltage when the film moves back and forth. All I have to do to use the element is solder it in parallel with a 1M Ohm resistor, connect one lead to an ADC pin and the other lead to ground. I simply soldered a resistor in between the leads on the device, and then I soldered on wires to connect to the Arduino later.

The second major piece of the project is something to play sound. In order to play the sound, I needed to get the sound. Luckily, I was able to find an mp3 clip of the scene from Young Frankenstein here.

The mp3 was a recording of the entire scene, so I had to cut out just the sound of the door knocker using a very useful program called Audacity. It's my go-to program when I have to do any simple editing of sound files, and it's free. With Audacity, I opened the mp3, cut out everything but the knock sound and amplified the waveform as high as I could before it started clipping so that it would be as loud as possible.



Next, I exported the file as an mp3 and saved it as "track001.mp3." The reason for this particular file name will be revealed later. After that, I loaded the mp3 onto a microSD card to later be used with the MP3 Player Shield.



The MP3 Player Shield is designed to play mp3s triggered by an Arduino. It has a microSD socket to hold the mp3 files and a VS1053 audio codec to process the raw mp3s and output them as audio through a 3.5mm audio jack. The product page has an example sketch that simply plays the mp3 files on the microSD card one after the other in an endless loop. Since I want to trigger the sound only when a knock is detected, I had to make some modifications to the code.

Here is the final Arduino sketch for this tutorial if you're playing along at home.

First, I need a function that checks the Analog 0 line and returns whether or not a knock is detected. I added the readPads() function at the bottom of the existing code:

int readPads(void)
{
  if(analogRead(0) > SENSITIVITY) { return TRUE; }
  return FALSE;
}

The constant "SENSITIVITY" is defined at the top of the sketch as 3. Since the piezo sensor is pulled to ground, it will report a zero voltage until it is agitated. Setting the SENSITIVITY constant to 3 means that any time a value greater than 3 is detected, the function returns true. This makes the sensor very sensitive, but since it has to detect a knock through a thick door, I set it low just in case.

Next, I need to modify the code in the loop() function to play track001.mp3 only when a knock is detected. Since the code is already written to play multiple tracks, I had to remove more code than I had to add. The final loop function looks like this:

void loop(){
    int pad_pressed = FALSE;
    pad_pressed = readPads(); // Check for a "knock"
    if(pad_pressed == TRUE)
    {
        trackNumber = 1;
        sprintf(trackName, "track%03d.mp3", trackNumber); //Splice the new file number into this file name
        playMP3(trackName); //Go play trackXXX.mp3
    }
  }

This code first calls the readPads() function. If the function returns TRUE, it plays the first track. If the function returns FALSE, it loops and checks again. Very simple. I attached the shield to my Arduino, soldered on the piezo sensor, and sure enough, when I tap the sensor, it plays the sound.





Loading comments...

Write a Comment

To comment please Log In

FEATURED RESOURCES