Offline
Newbie
Karma: 0
Posts: 26
|
 |
« on: November 13, 2012, 02:36:37 pm » |
Hi! I want to read some frequnces, but i do not know how i can do it. For example: if freq=20 hertz, blink a LED. Any oppinions?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 313
Posts: 35493
Seattle, WA USA
|
 |
« Reply #1 on: November 13, 2012, 02:37:56 pm » |
I want to read some frequnces, but i do not know how i can do it. For example: if freq=20 hertz, blink a LED. Any oppinions? The frequency of a PWM pin is a constant.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #2 on: November 13, 2012, 02:38:54 pm » |
Sorry, an analog pin.I want to read a frquency.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15316
Measurement changes behavior
|
 |
« Reply #3 on: November 13, 2012, 02:48:02 pm » |
Sorry, an analog pin.I want to read a frquency.
Difficult and time consuming to try and measure the frequency of a analog signal with a analog input pin. Better to run the signal to a comparator op-amp circuit and measure the frequency as a digital on and off signal. What is the waveform of your signal (sinewave, square wave, random audio) ? What is it's voltage range min to max, AC or DC? Perhaps if you told us what you are trying to accomplish in the sketch rather then what method you think will work best, we can better try and help you. Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 245
Posts: 16515
Available for Design & Build services
|
 |
« Reply #4 on: November 13, 2012, 02:50:05 pm » |
Digital signal, or analog? Best bet is to get it digital - then can use the Pulsein() commands to measure the high time, measure the low time, add the two together for the period. 1/period = frequency. Or using the rising edge to create a PCINT, measure the time from PCINT to PCINT, do the same math.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #5 on: November 13, 2012, 02:53:40 pm » |
I have a microphone conected to A0. If frequency is less than 1 HZ , a led is HIGH.If frequency is bigger than 1 HZ, another led is HIGH.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15316
Measurement changes behavior
|
 |
« Reply #6 on: November 13, 2012, 03:01:23 pm » |
I have a microphone conected to A0. If frequency is less than 1 HZ , a led is HIGH.If frequency is bigger than 1 HZ, another led is HIGH.
But a microphone generates rather random audio sounds comprised of many mixed frequencies and their harmonics, not a single frequency unless you have it pointing at a signal generating a single pure frequency through a speaker. Also audio is a AC voltages and an arduino analog input pin can only measure DC positive voltage values, negative voltages if large enough can damage the input pin. I think you need to rethink your application approach. Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #7 on: November 13, 2012, 03:08:42 pm » |
I do not want to work exactly.If sound is low, blink a led. If sound is high, blink another led.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19045
I don't think you connected the grounds, Dave.
|
 |
« Reply #8 on: November 13, 2012, 03:09:56 pm » |
1Hz is an extremely low frequency to detect with any microphone you are likely able to afford.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 245
Posts: 16515
Available for Design & Build services
|
 |
« Reply #9 on: November 13, 2012, 03:13:14 pm » |
You need to detect high & low volume then? That is easier. Run your signal thru an amplifier, and low pass filter, make it more like a DC level, then measure the level with analog pin. That's easily doable.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #10 on: November 13, 2012, 03:14:31 pm » |
OK.I want to use a library, or a function wich can read a frequency. After reading i want to separe in 2 frequences with if conditional. That is all. 
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Offline
God Member
Karma: 9
Posts: 771
|
 |
« Reply #12 on: November 13, 2012, 03:19:47 pm » |
I think this should be possible if there is a single frequency or a dominant frequency, especially at low frequencies. At higher frequencies, processor speed could be an issue... And, frequency measurement can just be "flaky", even with a proper frequency counter. Often you have to manually adjust a threshold control to get a good-stable reading. Normally, you'd measure the time betwen zero-crossings (i.e When the waveform goes from positive to negative or vice-versa). Since the Arduino can't accept negative input, you'd have to bias the input (i.e. 2.5V) and use the effective zero-crossing (bias-crossing) instead of the actual zero crossing. You need to allow for noise, so you'd have to look for values slightly above and below the zero-crossing (perhaps calibrating to a percentage of the peak), and you'd have to ignore low signal levels. You should probably "isolate" your time-measurement from your frequency calculation and other code. In other words, run a tight time-measurement loop (perhaps several times to take an average) and then break the loop and process your data. If you are analyzing complex sounds with more than one frequency component (just about anything other than a test-tone,) you'll need to look into FFT/DFT (quite a bit more mathematically complex).
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 313
Posts: 35493
Seattle, WA USA
|
 |
« Reply #13 on: November 13, 2012, 03:22:40 pm » |
Can make for me an example code with this library? When is our homework due?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #14 on: November 13, 2012, 04:06:43 pm » |
I don't need the full code. I want only a line , wich read frequency... Please help.
|
|
|
|
|
Logged
|
|
|
|
|
|