The 970-HA-JOKES Payphone Project

Pages
Contributors: Nate
Favorited Favorite 7

Number Detection

As mentioned above, the keypad has a DTMF encoder IC built-in so I needed a way to decode the DTMF tones in order to detect what number was being dialed. There was a variety of ways of doing this including a dedicated DTMF decoder, but why not use the Arduino itself?

DTMF testing with Arduino

From the AMI S2559E/F IC datasheet we know where the power, ground, and audio out pins are located. Powering the IC with 5V and sending the audio signal into an Arduino pin was easy enough. An inline 1uF capacitor was used to block any DC current. But how to convert the frequency into a number? Enter Goertzel. I’ll let Jacob Brosenthal, the creator of the Goertzel Arduino Library explain:

The Goertzel algorithm is long standing so see http://en.wikipedia.org/wiki/Goertzel_algorithm for a full description. It is often used in DTMF tone detection as an alternative to the Fast Fourier Transform because it is quick with low overhead because it is only searching for a single frequency rather than showing the occurrence of all frequencies.

We know the keypad is going to generate only the following 8 frequencies:

  • 697
  • 770
  • 852
  • 941
  • 1209
  • 1336
  • 1477
  • 1633

Payphone keypad frequencies

Image credit: Texas Instruments - ‘Practical Audio Experiments using the TMS320C5505 USB Stick’

We can set up two loops called ‘row’ and ‘column’. For example, if we detect 852 and 1477Hz we know the user is pressing the ‘9’ button. There are some additional settings including the number of samples to take and the threshold that we must cross to indicate the presence of the frequency. For the purposes of the payphone project, these two settings (N and threshold) were stored in EEPROM and I used the very sophisticated approach of ‘try it till it works’ to establish the best values.

With Goertzel and the settings in place, the internal Arduino now knew what number was being pressed. From there, I used a state machine to establish if the user was dialing an allowed series of numbers (ie 9 - 1 - 1) or a disallowed series of numbers (ie 6 - 0 -... would force the user into the ‘Please deposit a coin’ path).

What numbers should be allowed without requiring a coin payment?

Toll Free Numbers

Shamwow sales guy

In the USA, most people born before 1999 know what a '1-800' number is. For those who don't: a number that started with 1-800 was a 'toll free' number; a phone number where the calling fees are charged to the business who has the number. For example, 1-800-736-0308 is the phone number to purchase a ShamWow. It's not 'long distance' (where charges are applied to your phone bill), it's toll free. This concept has mostly disappeared like TV Guides and merry go rounds. With cell phones there is no such thing as long distance so the necessity for toll free numbers has declined dramatically. However, toll free numbers were hugely popular in the 1980s and 1990s. As such, the phone companies had to add 1-888 as an additional toll free area code.

Pop quiz: is 822 a toll free area code? How about 844?

I didn't realize it until this project but there are a lot of toll free area codes. 800, 833, 844, 855, 866, 877, and 888 are toll free. So the Payphone Project passes any of these numbers through without the necessity of a coin.

911

My wife and I agreed that, jokes aside, if we’re going to put a phone on the street, it has to have working 911. Thankfully, there are services like CallCentric that, for $1.95 a month, will connect a number from Google voice to a physical location and enable 911 forwarding. If someone dials 911 from the Payphone Project, it immediately gets routed to the nearest call center with the phone's address information.

867-5309

While Tommy Tutone’s popularity peaked a bit before my time, I still have this number etched into my brain (yay popular culture).

SPDT relay for man-in-the-middle call control

This relay is a single pull, double throw (SPDT) relay. This allows us to interrupt the phone line, effectively ‘hanging up’ the phone even though the user still has the phone in their hand.

If the user keys in 867-5309 we disconnect the phone from VOIP (turning off the call control relay mentioned above) and then connect the handset to our MP3 player, and begin playing our desired easter egg.

0

Lady Fun Video

What to do when a user needs an operator? I considered forwarding the user to 1-855-LADYFUN (which is a whole, amazingly deep alternate reality game, that you must absolutely check out) but that was a bit too meta. Instead, I thought it would be more fun just to expose the poor user to an infinite loop of Strong Bad’s Hold Music. This is the operator easter egg:

303-284-0979

This is SparkFun’s main number in the ‘real world’. So of course you’re going to get Rick whether you put a coin in or not. Here’s our short clip:

Please Deposit A Coin

If the user enters a number that requires a coin, they are disconnected from VOIP and we play our final ‘easter egg’. It’s the classic ‘This call requires a coin deposit’ operator prompt combined with Aloe Blacc’s I Need a Dollar. You can hear the combined clip below: