I am working on a project and would like to connect an old fashioned landline phone to a raspberry pi. I then want to be able to dial some number on the phone and then have the raspberry pi play a prerecorded audio file based on the number dialed. I am planning on writing the program to handle calls in Java but am having difficulty turning the landline signal into something the raspberry pi can work with. I also want the raspberry pi to be able to ring the landline phone. Neither device will be connected to the outside world.
It depends how 'old' you phone is. If it's touchtone, it's somewhat easier, if decadic dial a little more challenging. you should read up on phones before starting, and this is a good reference.
You can break the problem into parts:
Power the phone. This is normally a 48 VDC line with a 680 Ohm series resistor (called the subscriber ballast If I remember correctly). So if you short the line (Red-Green) you get about 70 mA. The phone/exchange understand the state of the line by the voltage detected on the line (from the exchange end they detect the current flowing to the subscriber). You could probably get away with 24 VDC and a 320 Ohm resistor.
Ring tone. This is typically a 20 Hz AC signal at about 60 V RMS. You need this amount of signal to ring the older electromagnetic ringers which represented about 3-5 W load. The Touch tone phones still needed a high voltage ring tone, but do not draw any ringer power (they just detect the 20 Hz tone). To generate this signal you can use a small audio amplifier (if you need the higher power) and something like a 120 - 6 or 9 V transformer. Feed the amplifier into the 9 V end, and AC couple the 120 V side to the phone line. If you configure this correctly there is no reason it cannot provide both dial tone (anything from 50 Hz - 400 Hz) and ring tone.
Audio input/output. This is relatively easy and a circuit such as this provides the information you need. From memory audio is about 1.2 V RMS on the line. This phone tap schematic was used to allow a tape recorder to either record, or play music to the line depending on which connector (Mic or output was used).It's not a great circuit as you have to position the pot carefully at the high end to get enough signal output to the line. Notice however the back to back zeners to clip the ring tone voltage!!
- Dailing. If it's a touch phone then it just feeds audio tones onto the line. It it's decadic dial the phone will short the line with the dial pulses. I'm assuming here that you need this to tell the Raspberry Pi which 'virtual' phone number you are dialing. You could find these pulses in the audio channel, or look at the line voltage with an A/D.
When the phone goes off hook you should have between 8 and 15 VDC on the line (you need this to power the Dial Tone phone), On hook close to 48 VDC for a normal phone line. This will alter if you use less line voltage.
If your telephone has DTMF dialling (dual tone multi frequency) then you'll need to interface the RPi with a DTMF decoder chip like this one: -
You'll also need to send a DC loop current to power the phone. Somet5hing like 25 mA with an open circuit voltage of 12 volts will power most phones quite easily but don't try and supply a hard 12V dc to the phone because you might get smokde. Maybe 12V through a 220 ohm resistor. The phone should power at this level and you will be able to wire the DTMF decoder to the line via a capacitor and resistor arrangement something like this: -
Now, when it comes to ringing the phone's bell that's a different story. In my experience you will need an AC voltage of 30V to 50V to get the bell operating. The industry standard in the UK (as per the old BS6305 is 70 V at 20 Hz (from memory)) but, you might get it to work at 50 / 60 Hz so you might need to set up an experiment.
I would recommend you use relays to switch the AC ring voltage to the line so that the DC is removed when the bell voltage is active. This also gives you the possibility of applying cadence to the bell voltage to simulate a US or UK bell cadence.
With a 220 ohm terminating the line for speech, sidetone might be a little high but there are ways to make the impedance more like the 600 ohms typically used (more modern phones rely on a complex impedance but this would be a small refinement that probably isn't necessary).
If you phone uses an old fashioned dial (i.e. it is a pulse dialler) then counting the dialled pulses using the RPi is quite doable I would suggest.
The OP may be interested to note that there is at least one commercial offering doing exactly what they aimed to do - Steelowltech - maybe they got the inspiration from here as I am sure I saw somewhere that underneath the casing is an RPi...!
I use one of these with my raspberry pi and a relay board to monitor my sump pump.