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:

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.




Attaching the door knocker
Now to attach it to the door. For this, I special-ordered a precisely-machined custom attachment device from my local supply shop:


Just kidding.

I powered the Arduino with 4 AA batteries in a battery holder with a barrel jack. I then used a 3.5mm audio cable extension to connect the MP3 Player Shield to my computer speakers. I attached the piezo sensor to the back side of the door, right about the height where someone would knock. The whole rig looks like this:



The final effect was pretty impressive:



Now when someone knocks on my door it sounds like they're using a giant door knocker. This project is just one example of how to integrate sound into objects using our MP3 shield and a piezo sensor. I've used this set up with drum sounds and multiple piezo sensors to make electronic drums and other percussion instruments. One could use it to turn just about anything into an instrument! Be sure to check out our force/flex/piezo sensors for more ideas.

Also see: