Pages: [1]   Go Down
Author Topic: Read sound-frequency from 3.5mm jack ?  (Read 1783 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys, I want to connect an audio source that produces sine-waves in different frequencies to my arduino and output/process those frequencies.
I guess I can't do that using pulseIn since the input is an analog signal. The device will be connected with a 3.5mm headphone jack. Any suggestions?

Thanks in advance !
Logged

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Analog-digital converter?
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 216
Posts: 13672
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you need an ADC and an FFT,

check - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1286718155 - should help

or maybe - http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/ - if you can make pulses of your sinus.

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
you need an ADC and an FFT
And maybe a side-order of DDS?
Logged

Per Arduino ad Astra

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

Quote
I guess I can't do that using pulseIn since the input is an analog signal.
Yes bung it through a digital input and it will look like a digital signal at the threshold of the input pin. Better still just put it through a transistor to "square it up" and use pulsein()
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you mean just using a digital pin instead of an analog one?
how would i hook up that transistor to make it work that way?

thanks for helping
Logged

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

Quote
how would i hook up that transistor to make it work that way?
Signal to a resistor, other end to the base of a transistor.
Emitter to ground.
Collector to arduino input.
- Enable the internal pull up resistors by doing a digital write high just after you initialises the pin as input in the setup() function.
Remember pulsein will only measure the period of half the waveform.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, so if i hook up the input to a transistor and use the pulseIn fuction on the specific digital inputpin, then double the return value, i'll have the frequency?

what kind of resistor should I use? how many Ohms?
Logged

0
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2857
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you tell us more about your signal? frequency and voltage?

Here is a circuit to solve a similar problem with some specific parameters (<20kHz frequency, 0.5V-1V bipolar range):

http://ruggedcircuits.com/html/circuit__22.html

--
The Aussie Shield: breakout all 28 pins to quick-connect terminals
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 534
Posts: 26964
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How does the next ciruit in your series
http://ruggedcircuits.com/html/circuit__23.html
offset the input to 2.5?
With 10K & 30K resistors, why isn't the offset 5V*(10K/(10K+30K)) = 1.25V?
Should R3 have been 30K as well?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2857
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The positive terminal of the op-amp (pin 3) is set to 1.25V by the voltage divider R2 and R3. By negative feedback, the negative terminal (pin 2) is kept to the same voltage. Now R1 and R4 form a voltage divider:

1.25V = (Vout - Vin)*R1/(R1+R4) + Vin

When Vin is 0:

1.25V = Vout*R1/(R1+R4) = Vout*30k/(30k+30k) = 0.5Vout

so Vout = 1.25V/0.5 = 2.5V.

So it's not that the circuit offsets the input to 2.5V. It's that when the input is 0V, the output is 2.5V. When the input goes higher, the output goes below 2.5V, and when the input goes negative the output goes above 2.5V.

--
The Rugged Motor Driver: two H-bridges, more power than an L298, fully protected
Logged

Pages: [1]   Go Up
Jump to: