Arduino Note Detector

Arduino Note Detector

Project Overview

This project was done for Junior Design 1 in the ECE program at Oregon State University. I worked on this project with Kyle Barton and Samuel Barton. The goal of the project was to use an Arduino Nano to take in sound through a microphone, then to use the fast fourier transform to determine which note between C4 and C5 was being played. The note would then be displayed on an array of 8 LEDs. You can check out the final report we submitted for the project here, but I'll also talk a little bit about it on this page.

Microphone Circuit

The first part of the system is the microphone input, along with its preamp circuitry. Sam worked on this part of the project. He looked at the datasheets for the microphone and the opamp, then designed the circuit so that it would have enough gain to be readable by the ADC of the Arduino. You can see the circuit below.



Microphone with Preamp Circuit

With the circuit designed, Sam built it out on some protoboard. The final product of that built circuit is shown in the image below.



Built Circuit on Protoboard


Arduino

After the signal has been taken in by the microphone and amplified by the preamp circuit, it's taken in by the ADC of the Arduino and the fast fourier transform of the signal has to be taken to figure out the frequency being played. Kyle took the lead on the Arduino coding for this project, and I helped out. The code takes the FFT, finds the maximum value, then checks it against a lookup table for the frequencies of the notes between C4 and C5. The output of this lookup table outputs to a corresponding digital pin which is connected to an LED. This output LED Array can be seen in the picture below.



Output LEDs

The difficult part about the Arduino code was that the Arduino Nano doesn't have very much memory. So we essentially had to choose between getting an accurate FFT and being able to detect the notes on the higher end of the spectrum. I spent some time on the Arduino code trying to squeeze some extra speed out of it by messing with the registers of the ADC. It ended up giving us a bit higher sampling frequency, but it still wasn't enough to get very good results. You'll see what I mean in the MATLAB section of this document.


MATLAB

One of the requirements of this project was that we had to output the microphone data through serial to MATLAB, where it would be plotted alongside its FFT plot (and the signal to noise ratio). I took the lead on this part of the project. You can see one of the plots I made for an input note of D4 (with a signal generator phone app) below.



MATLAB Plot for Input Note of D4

The input tone was a sine wave of frequency 294Hz (D4). As you can probably tell, this plot is not quite a sine wave. Somewhere between the microphone and the Arduino, the signal is badly clipped. We think it has something to do with the biasing of the circuit, but we never investigated it fully. Also, you can see that the FFT plot shows that the signal has a frequency of 312, which is pretty far off from the actual frequency. Part of the reason that this is so far off is because the resolution of the plot is about 20Hz. Because we couldn't get a high enough sampling frequency on the Arduino, we couldn't get the resolution low enough to get an entirely accurate FFT plot. Even if the resolution was low enough, there would still be some error, probably caused by the clipping of the signal.


Conclusion

The note detector ended up working well. We were able to accurately detect notes played by a guitar from 10 feet away. And though the MATLAB plots did not end up being perfect, it could easily be remedied with a slightly better microcontroller and a little bit of time spent playing with the biasing of the microphone circuit.