Simple Audio Frequency Meter
This tutorial explains how to use the Audio Frequency Meter Library for Arduino Zero boards.
This tutorial explains how to use the Audio Frequency Meter Library for Arduino Zero boards. The code uses a method of the library to measure the frequency of a signal connented to A0 and amplified through an electronic circuit, in order to get the frequency of a generic input signal. The range currently measured by the library spans from 60 to 1500 Hz and it can be narrowed by the setBandwidth() method. The library can be installed using the arduino library manager
Hardware Required
Arduino Zero Board
10k ohm trimmer
2 100k ohm resistors
2 47k ohm resistors
100n farad capacitor
3.5mm jack
Circuit
In order to get the most dynamic range even from low level inputs, the circuit consist of a non-inverting amplifier that brings the amplitude of the signal to the full input voltage range supported by the ADC. Sampling at full resolution means a better accuracy.
The 10k trimpot allows to adjust the gain of the amplifier matching the signal level with the ADC input range. This adjustment should be made looking at the output on the Arduino Software (IDE) Serial Monitor: when the frequency reading is stable, the gain is properly set.
As an alternative, you may purchase the Electret microphone amplifier - MAX4466 with adjustable gain that was designed specifically for this purpose.
Schematic
Code
1/*2
3 Simple Frequency Meter for Arduino Zero4
5 Demonstrates how to sample an input signal and get back its frequency6
7 This example code is in the public domain8
9 https://www.arduino.cc/en/Tutorial/SimpleAudioFrequencyMeter10
11 created by Arturo Guadalupi <a.guadalupi@arduino.cc>12
13 10 Nov 201514
15*/16
17#include <AudioFrequencyMeter.h>18
19AudioFrequencyMeter meter;20
21void setup() {22
23 // put your setup code here, to run once:24
25 Serial.begin(115200);26
27 Serial.println("started");28
29 meter.setBandwidth(70.00, 1500); // Ignore frequency out of this range30
31 meter.begin(A0, 45000); // Initialize A0 at sample rate of 45kHz32}33
34void loop() {35
36 // put your main code here, to run repeatedly:37
38 float frequency = meter.getFrequency();39
40 if (frequency > 0)41
42 {43
44 Serial.print(frequency);45
46 Serial.println(" Hz");47
48 }49}
Suggest changes
The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.
License
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.