Pages: [1] 2   Go Down
Author Topic: How to correctly interface Audio In and Out (line out or headphone) with Arduino  (Read 3227 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino is awesome
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I am building a project that detects telephone touch tones via the handset jack on my land-line telephone and then plays tones to the input of the telephone. I do not want to break the telephone nor my arduino. I am using this library (https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation) to play the tones.
It says:
Quote
WARNING

Do not connect the pin directly to some sort of audio input. The voltage is considerably higher than a standard line level voltages, and can damage sound card inputs, etc. You could use a voltage divider to bring the voltage down, but you have been warned.

You MUST have a resistor in line with the speaker, or you WILL damage your controller.

I am currently testing it with a piezo buzzer and a 10k resistor. It is just what I need and works perfectly! Except it is a little old so I had to follow the instructions here (http://forum.arduino.cc/index.php?topic=87398.msg656041#msg656041) to get it to compile correctly.

I have seen multiple posts on the forum and across the internet on how to safely connect the arduino to a line-level input.
One of them is in this image (from http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/):

At the top right is a schematic on how to do this, however is requires a 33mH inductor, which I have no clue where to find.

On the audio input side, I'm pretty sure I have it down. I am using this schematic (from https://coolarduino.wordpress.com/2011/02/10/color-organ-spectrum-analyzer-on-arduino/):

I will be using the Goertzel Algorithm (https://github.com/jacobrosenthal/Goertzel). I also found a modified version that I will try as well (http://forum.arduino.cc/index.php?topic=121540.msg1071479#msg1071479). However, the only part that confuses me is that in that same forum, someone else posted a different schematic for hooking up the audio (http://forum.arduino.cc/index.php?topic=121540.msg1092810#msg1092810):

Which circuit is better to use?

Please help! I don't want to have to resort to getting the Wave Shield by Adafruit or playing sound files with the SD Card on the Ethernet Shield.

Arduino Mega 2560 R3
Windows 8 32-bit
« Last Edit: July 16, 2013, 05:04:14 pm by DaAwesomeP » Logged

An Arduino is not a toy; it's a professional utilitarian tool.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34246
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Which circuit is better to use?
They are very much the same but the first one is the one to use.

Quote
however is requires a 33mH inductor,
It will work without this, it is just that the filter will not be as good. The value is not very critical.

Quote
which I have no clue where to find.

http://uk.farnell.com/jsp/search/browse.jsp?N=2031+203351&Ntk=gensearch&Ntt=33mH&Ntx=mode+matchallpartial
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino is awesome
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much Grumpy_Mike! smiley
« Last Edit: July 16, 2013, 05:04:41 pm by DaAwesomeP » Logged

An Arduino is not a toy; it's a professional utilitarian tool.

Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino is awesome
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So I just tested it today, and I found that the output it way too loud. I hooked up the multimeter and it showed ~1.2 volts DC. I understand that is way above the peak level of a line level input.

I experimented with adding a 10k and a 1k resistor between the capacitor/resistor and the telephone's handset input.

NOTE: I am using the top right portion of this Minus the 33mH inductor schematic:

Taken from: http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/
« Last Edit: July 16, 2013, 05:05:03 pm by DaAwesomeP » Logged

An Arduino is not a toy; it's a professional utilitarian tool.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34246
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Use a potential divider to cut down the signal.
https://en.wikipedia.org/wiki/Voltage_divider
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino is awesome
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks again, Grumpy_Mike!

The Wikipedia article confused me, but when I looked into the citations, I found this video: http://afrotechmods.com/tutorials/2011/11/28/voltage-divider-tutorial/.
I ditched the original schematic and made my own voltage divider. The volume got low enough that is was softer than the I didn't even need the capacitor!

I experimented with different resistor values with the equation in the Windows Calculator.
I got it down to this: 5v * (220 / (220 + 10,000)) = 0.02152641878669275929549902152642
The 5 volts is from the output of the Arduino.

Attached is a schematic I made in Fritzing.


* ArduinoLineOut_schem.png (167.01 KB, 2184x2001 - viewed 94 times.)
Logged

An Arduino is not a toy; it's a professional utilitarian tool.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34246
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The volume got low enough that is was softer than the I didn't even need the capacitor!
The capacitor is there to filter out the high frequency sampling noise, I would keep it in.
 
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino is awesome
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I added it in. It works fine. I attached the new schematic.

It seems that the circuits I originally mentioned aren't really working without some tweaking.  smiley-fat

The input circuit isn't working. This time, though, I'm not sure if it's the libraries I'm using or the circuit. Both the DTMF and Goertzel libraries that I found haven't produced results.

I found this: http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/. It looks like a good library, but I have no clue how to use it. It has two schematics. Which one should I use? Do I need to look into using an FFT? If so, how would I use it? I don't own the 100N capacitor, transistor, or the inverter. I would have to make yet another trip to Radio Shack.
Or should I use the left part of this schematic (I don't own the 100k resistors or the 4.7nF capacitor):

From: http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/):

Note: I would prefer to use the DTMF library if possible.


* ArduinoLineOut_schem.png (167.93 KB, 2265x1920 - viewed 59 times.)
« Last Edit: July 16, 2013, 05:05:30 pm by DaAwesomeP » Logged

An Arduino is not a toy; it's a professional utilitarian tool.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34246
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No you put the capacitor in the wrong place. It needs to be in parallel with the resistor connected to ground to act as a low pass filter.

Quote
The input circuit isn't working.
How do you know this?
The input circuit is the left hand side. If you haven't got the two 100K resistors then what do you have? I can only comment on what you have.
All the input circuit does is to allow the signal to appear as a 2.5V biased signal. The size of the input signal will determine the range of readings you can get. If you have too much signal it will clip and distort, too little and the readings will not show enough variation to do anything with.
Have you measured the signal at the analogue input with an oscilloscope?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino is awesome
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I fixed the circuit and added the capacitor in parallel. I added the 10k resistor to make it a tad bit softer. I attached the new schematic.

My current inventory:
  • Resistors:
    • 220
    • 470
    • 1k
    • 10k
  • Capacitors:
    • 2 0.01μF Ceramic (1 in use in output circuit)
    • 1 10μF Electrolytic
  • Plenty of LEDs
  • Plenty of wire
I will buy more if needed. I am a beginner and having a bigger selection I assume will be useful for later projects.

I do not have an oscilloscope (they are quite expensive), but I do have a multimeter (AC and DC volts, Diode check, Resistance meter, and Continuity Check). If I really need an oscilloscope, I found this: http://www.instructables.com/id/Arduino-Oscilloscope-poor-mans-Oscilloscope/. Is it worth it?

I did find that the output from the telephone is about 1.7 to 1.9 volts. Could I just plug it into the arduino directly?


* ArduinoLineOut_schem.png (173.98 KB, 2265x1920 - viewed 71 times.)
« Last Edit: July 16, 2013, 05:06:30 pm by DaAwesomeP » Logged

An Arduino is not a toy; it's a professional utilitarian tool.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34246
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I did find that the output from the telephone is about 1.7 to 1.9 volts.
How did you find that?
Is it 1.7V DC, peak, peak to peak or RMS.
In the UK phones work with 40V.

Quote
Is it worth it?
Yes it is better than nothing. Meters will tell you little about these sorts of signals.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino is awesome
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I have two telephones hooked together with telephone cable. I am using a 9v battery to power them. I have effectively made an intercom. On the handset jack on one of the telephones (2.5mm or 3/32), there is input, output, and ground. I am connecting the output circuit to the input of the telephone. Ground is connected to ground on the arduino. The output of the telephone will connect to the input of the arduino. Basically, I want to plug a line-line, normal headphone output into the analog input of the arduino. The output of the arduino is what is 1.7 to 1.9 volts DC. I connected the multimeter to the output and ground of the telephone.

I just tested it again in AC. it stays at 0 and then goes up as I press buttons and talk into the other telephone. When I press a button (a tone) it goes to 0.3 volts AC. When I blow loudly into the mic, it goes up to about 0.86 which might be the peak. I am starting to understand this. It is an analog signal wave. So, it has to be AC.

I will bye the parts and build the oscilloscope later. However, I might be able to borrow one from a friend.
« Last Edit: July 16, 2013, 05:07:11 pm by DaAwesomeP » Logged

An Arduino is not a toy; it's a professional utilitarian tool.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34246
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I just tested it again in AC. it stays at 0 and then goes up as I press buttons and talk into the other telephone.
That sounds like what you would expect to see, good.

Quote
When I press a button (a tone) it goes to 0.3 volts AC.
So assuming it is 0.3V RMS then that corresponds to a peak voltage of 1.414 * 0.3 = 0.432V
That is then sitting on top of your 2.5V bias giving you a positive peak of 2.932 and a lower one of 2.068V

That means you should get a reading from your analogue input of between 600 and 424 ( it is 5 / 1024 volts per reading step )

That looks like a reasonable sort of signal to sample, are you seeing these reading swings on a tone?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino is awesome
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, so I hooked it up to A0 and loaded the AnalogReadSerial example. when nothing was being pressed, it output 99. When a number was pressed it would jump between 85 and 109.

The next time I tried it, it was at 72. When I pressed a button it would jump between 56 and 82.

Finally, I tried it with a 1K resistor in between A0 and the telephone. Both times I reset it, it was jumping from 73 and 74. When a button was pressed, it would jump around between 67 and 83.

Once again, thank you so much for helping me with this!
« Last Edit: July 16, 2013, 05:07:27 pm by DaAwesomeP » Logged

An Arduino is not a toy; it's a professional utilitarian tool.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34246
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That would suggest that you have not got the input circuit wired up like you showed in the diagram. You should get a reading of about 500 with no input signal. This is because the analogue input is being held at the half way point between the +5V and the ground at 2.5V. Take a DC voltage measurement at the analogue input and you should see it at 2.5V.
Logged

Pages: [1] 2   Go Up
Jump to: