So I'm trying to read the frequency of the audio output of an old computer. I found this code http://www.instructables.com/id/Arduino-Frequency-Detection/#step1 , which can find frequency but when I use it I only get random values. I have a direct connection from the computer's audio ouput to the arduino board. Is there another way to do this or do I need to build the circuit described in the article that I posted?
or do I need to build the circuit described in the article that I posted?
What circuit ?
I'm not going to read the whole article. If there is a schematic or a pargraph describing the circuit post that.
I have a direct connection from the computer's audio ouput to the arduino board.
No EE expert but the Arduino port can only read voltages between 0..5 V (or smaller)
An audio signal is both pos and neg so that does not match
So you should build some circuit to adapt.
You can use this program to measure it (see attached)
It uses an SD card to write BIN files . It is set up to sample at 40,000 samples per second on A0 input which requires an SD card with low latency. This program is configured for the SD card chip select on pin -10 (D10). If your SD card shield uses pin 4 (D4)
you need to change it
** // Pin definitions.**
// Digital pin to indicate an error, set to -1 if not used.
// The led blinks for fatal errors. The led goes on solid for SD write
// overrun errors and logging continues.
const int8_t ERROR_LED_PIN = 3;
// SD chip select pin.
const uint8_t SD_CS_PIN = 10;
This card works well:
The program converts the BIN files to EXCEL CSV FILES. The Menu is displayed on the serial monitor.
After you hit any key to stop recording you have to select “c” to convert that file then and there , otherwise you have to remove the card and put in your computer and use the command prompt instructions in the readme file. If your sure you want to use that file make sure to hit “c” after stopping the recording. The conversion can take up to 5 or 10 minutes depending on the file size. A very short run could take less than a minute to convert. You can also dump the data to the serial monitor to view before you choose to convert it. Be sure to connect a led and 220 ohm resistor from D3 output to GND with the (-) lead of the led to ground as the ERROR indicator. If there is an error it will be displayed on the serial monitor. (like overrun error) You can choose to view the overrun error detail on the serial monitor.
The program has four commands:
c - convert file to CSV
d - dump data to Serial
e - overrun error details
r - record ADC data
All commands can be terminated by entering a character from the serial monitor.
The c command converts the current binary file to a text file. Entering a
character on the serial monitor terminates the command.
The d command converts the binary file to text and displays it on the serial
monitor. Entering a character on the serial monitor terminates the command.
The e command displays details about overruns in the current binary file.
Data overruns happen when data samples are lost due to long write latency
of the SD.
The r command will record ADC data to a binary file. It will terminate
when a character is entered on the serial monitor or the the maximum file
block count has been reached.
ANALOG05.xlsx (3.42 MB)
You need to be a bit clearer about what you mean by "the frequency". Do you mean the fundamental? The tone with the highest magnitude? An arbitrary signal contains many frequencies.
The schematic you posted adds a DC bias so that the ADC can read the signal, as long as its magnitude is not too large. If it is acceptable to run your signal through a threshold (i.e. turn it into a binary square wave) then you should feed your signal through a comparator and send the output of the comparator to the Arduino. You can then count the rising edges using interrupts on pin 2 or 3, or you can use one of the built-in hardware counters (e.g. timer 1) to count the frequency or the period of the signal. That will get you a single, accurate number for frequency but it depends on the assumption that it is OK to apply a threshold to the signal.
Perhaps you want to extract the spectrum of the signal? In that case, you need to ensure that the ADC can record the full magnitude of the signal with no clipping, and you need to run an FFT over the data. The Arduino isn't really the right hardware to do that though it has insufficient numerical performance. You probably want a 32-bit ARM like a Teensy 3 if you want to do heavy signal processing.