Saturday, October 1, 2011


I started work on this project quite some time ago and have been working on it on and off. It was meant to be a puzzle / game sort of thing, but i have recently discovered that is is perfect for practical jokes too!

I had been thinking about doing a project involving sound files, so when I came across an old rotary phone at a garage sale the pieces started to come together. The concept of freakyphone came together after much thought, and took on many different forms before I ended up with the final concept. First I thought about making a Mass effect like conversation system based around a murder investigation. You would then play the role of a detective tasked with solving the case. You would have to talk to witnesses and interrogate suspects. If you found the killer you would win the game.
However this would require me to come up with a big and compelling story tree involving several characters and a lot of sound recordings (not to mention compelling voice acting).
In the end I ended up with something somewhat simpler yet funny and interesting.

Freakyphone is an old rotary phone that plays all sorts of funny movie quotes, internet memes, music etc. when the phone rings, and you pick it up, it will play a random file from an SD card.
The very first time you answer a “call” the phone will present itself, and explain the rules of the game. Among all the funny soundfiles on the SD card are 6 clues leading to the name of a historic person. If you enter this persons last name using the letters on the phones rotary dial, the phone will play a special WIN sound for you. So all you really have to do, is to be patient and pay attention to whatever the phone says.

The build
The brains of the phone is an ardino duemilanove and a sound shield from adafruit. I wanted to preserve the old school look and feel of the rotary phone so I planned to replace the huge AC solenoid bell with a DC one. However this proved to be unbelievably troublesome. 

Above is a picture of the old AC driven solenoid bell. It is built (like the rest of the phone) to survive a nuclear war if necessary. Back in those days it seems everything was build to last for generations.

In the end I used a electronic buzzer instead of a bell. I used a lot of time trying to mod an old DC doorbell to fit, but it was just not very practical. I also tried to make my own smaller bell system using the solenoid hammer system from the DC bell with a custom machined bell plate. However it proved to be a huge waste of time, as there was simply not room enough for a proper bell solution, while still leaving enough room for the electronics.

Interfacing the dial system with the microcontroller proved to be easier than I had thought. The dial has 3 wires, one of them is common GND or Vcc, the second one is for signaling when the dial is in its home position, and the last one is pulsing on and off when the dial is on its way to its home position. If you dial 8 and let go, the pulse line will pulse 8 times. So all that is needed, is to count the pulses when the “dial in home position” signal is not true. Almost like it was made for interfacing with a microcontroller... ;-)

This picture is taken early on in the build during the initial testing. You can see the 3 wires coming from the dial connected to the microcontroller.

Initially I intended to replace the old style speaker in the earpiece with a more modern speaker to achieve better sound quality. I looked around for a new speaker of the right size and found that a leftover one from [one of my previous projects] was a perfect fit.
However replacing the speaker caused some annoying problems. because the new speaker was smaller and thinner than the original, it was creating echos inside the speaker compartment of the earpiece causing terrible sound quality. The volume was also a bit low since the backside of the speaker was not sealed off from the front side. This causes the sound waves produced by the backside of the speaker membrane to cancel out the sound waves from the front side, resulting in lower volume. And finally I was not happy with how the reduced weight of the new speaker caused the earpiece to feel out of balance in your hand. In the end I decided to try the original speaker with the adafruit sound board even though the speaker was terribly out of spec. The adafruit board is designed for a 8 ohm speaker (the output from the board is only 100mW I think), the original speaker from the earpiece is 32 ohms! To my big surprise it worked brilliantly! The volume was much higher, and the sound quality was not bad at all. It is clear however that this kind of speaker was designed primarily for speech. When playing complex music, the sound isn’t as rich as it could have been, but it is fair enough. And then when the sound being played actually is speech, it sounds sweet as hell!

For power I used an old power supply from a broken external USB disk drive. It outputs both +5VDC and +12VDC (both regulated). 5 volts for the arduino and 12 volts to beef up the buzzer.
Since I originally intended to install a real solenoid bell, I had installed a N-channel mosfet to drive it. Now the mosfet is really just used for level shifting for the buzzer. Huge overkill, but what the heck. Also take a look at the picture below, these old phones comes complete with mounts for mosfets ;-).

The programming

even though I am not the most experienced microcontroller programmer in the world, the program for the arduino came together without much hassle. The most troublesome part was figuring out how to use the library for the sound shield, but after peeking in some example code I was able to work the quirks.

Sourcing the sound files
The adafruit sound shield that I am using has some limitations. It is important that the files on the SD card are placed in one unbroken data block. If you delete a file and add another, the files may no longer be placed like that, so if you want to be sure everything is placed right you have to format the SD card and add all the files again. It only supports FAT 16, and it is very picky about the kind of sound files on the SD card. It will only play totally uncompressed WAV files as it has no mp3 decoder chip. For best sound adafruit recormends to use 22KHz, 12bit uncompressed audio.

These limitations meant that i had to convert all my files to 22KHz 12 bit mono audio. However i could not find any decent program that would allow me to convert to 12 bits so my files are actually 16 bits. Is seems to work okay though.
I got most of the audio for the project by stripping it of various youtube videos using this site: Is returns the soundtrack of the video in mp3 format. I have not made much use of any batch conversion software, as many of the original files needed editing as well. For editing i used a nice program called Free Audio Editor 2010. Editing all the files has by far been the most time consuming part of this project, but all things considered it was really not that bad. In total, including the clues, the phone holds 152 different sound files.

Since Freakyphone is to be given to a friend of mine for him to solve, it was very important to test it thoroughly, as I would not always be around to fix any problems that might arise. I once made a box that recuired a 6 digit code to be entered before the box would unlock and spill its secrets. Unfortunately the box opened prematurely due to a defective microswitch. (luckily my friend had the decency to report the problem). Determent that something like this should not happen to freakyphone, I tested it intensely before handing it over to my friend. I left the phone on for several days in a row, (even through the night) exposing the system to everything I could think of.
I have learned that if you ever notice something about a system that acts odd or unreliable, it will most likely not only cause confusion, but eventually one day bring the entire system to its knees.

I wanted to get a rough idea about how many calls on average it would require to hear all 6 clues. Not quite sure how to calculate a statistically reliable answer, I decided to write a small program that would create a random number using the same pseudo-random function used in the freakyphone program. The program would then count how many program cycles (random numbers) it would take to eventually having hit the numbers 1 though 6. (the 6 clues). After running the program several times and averaging the outputs the result came out to be about 310, which I was very happy with.

When I was almost done with the project I found [this] mp3 sound shield on sparkfun. They must have announced it just after I started the build (*typical*). If I ever decide to build another of these phones, I will most probably use one of those instead of the adafruit one.

Take a look at freakyphone in action:

Friday, January 28, 2011

The mail notifier

In order to ease the work for the local postmen in Denmark where I live, the goverment decided that apartment complexes should install mailboxes on the ground level, so the postmen would not have to run up and down stairs many thousind times a day. This is a good deal for the postmen, however it also means that I have to check my mailbox daily if I want to be up to date with the mail I receive. The dilemma is this: I could go and check my mailbox daily, but if my mailbox is empty that would be a waste of time and just plan irritating. On the other hand if I only check my mail say every 3 days then I might miss something urgent that needs my attention.

So I decided to build a small system that could notify me whenever someone had dropped something in my mailbox. To ease the build I brought a cheep wireless doorbell for its wireless capabilities. The plan was simple. Mount the transmitter part on the inside of the mailbox and extend the pushbutton with some wires and a microswitch to detect when the lid is open. The “new mail” notification would then be handled by means of a blinking LED on the doorbell receiver unit placed in my apartment.
To remember if the mailbox lid had been opened I made a electronic flip-flop that was set when the lid is opened and reset when a small reset pushbutton was pressed.

This is the logic schematic for the little addon bord I made for the doorbell unit.

This is how it looked when testing out the circuit on my breadboard:

the LED shown here was just for testing, the one installed in the end is a 4 mm selfblinking one. The IC I am using is a quad NOR-gate TTL type. (74HCT02N)

I didn't bother to make sure that the same gate would always win the power on race, I just took the power on and off a couple of times to see which one of them that came first most of the time. After all I will only have this problem when the circuit is re-powered after a battery change, and then there is always the chance that it will power up the right way. If not it is just a matter of pressing the reset button.

After a bit of reverse engineering I found a suitable “set” signal to tab into on the doorbell main board. This signal is only high as long as the doorbell's pushbutton is pressed. Strangely enough the signal was only 3V and I had been expecting about 4.5V since the doorbell unit uses 3 AA batteries. It turned out that two of the batteries was dedicated for driving the electronics while the last one were to drive only the speaker. A bad design if you ask me, it must have drained the batteries very unevenly. On the bright side I could throw a battery away and still have working electronics. Since the IC I am using is TTL type the relatively low 3V supply should still be sufficient to drive my electronics properly.
Here is a picture of the electronics with my finished addon board attached:
 In the top left corner you can see the backside of the reset button and the LED.

With the receiver unit done I moved on to the transmitter part of the doorbell system. None of the electronics in the transmitter part had to be altered, it was just a matter of adding a microswitch contact in parallel with the one already on the board:
I glued a wooden spacer to the switch to make it fit in the mailbox:

When the lid is closed the switch is pressed so the function becomes inverted. In order to de-invert it, the switch is wired up as normally closed. This way I get a high signal when the lid is opened.

With everything reassembled it was time for testing, which I thought would be ever so easy. Hell no! For some reason it would not work reliably on distances more than just a few meters... The problem obviously had something to do with electrical noise, which is really a bitch to do any faultfinding on. I tried routing the wires from my addon board as far away from the antenna as possible but nothing worked. Finally I made a tiny hole in the receiver and fed the antenna through to the outside of the casing, which worked brilliantly. My guess is that either my addonboard must have acted like an antenna for a noise source on the receiver board or that the addonboard itself have made some kind on noise. However I dont see how the simple components of my own board could ever make any kind if HF noise. Anyways now I know exactly when I have to empty my mailbox, no more running emptyhanded!