Input Devices

Deciding what to do

When thinking about what to measure, I thought it would be cool if I could measure the pitch of something, and I could use it as a tuner for my instruments. Then, thinking ahead to output devices week, I thought I could make a sort of karaoke machine that will tell you if you're playing the notes on the screen at the right pitch. However, this week I'm first going to figure out how to measure pitch.

Board design

Designing the board

I started working on my schematic. I decided on using the MIC MEMS analog microphone SPU0414HR5H-SB. To figure out what components I need and how to connect it, I looked at their datasheet here (see circuit on page 4). Here is the schematic of the whole systems (input and outputs), and I circled the microphone component.

Board design

Milling + Soldering

I milled the board using our Bantam milling machine, and I soldered everything. It was really good soldering practice, and I even learned how to use solder paste and hot air to solder the microphone since it was really tiny.

Finished board

Realizing I did too much

Once I had everything soldered, I went to test the board and it was not connecting. Even the LED lights from RP2040 weren't lighting up, leading me to believe that my board had died or I killed it. Since I had so many pieces, I instead decided to only mill the microphone part and connect it to an RP2040 I had for testing purposes using jumper wires. Here's a picture of the new board with just the microphone.

Finished board

Measuring and coding

So I started with trying to find the pitch of the sound using the microphone. However, this was more difficult than I thought it would be, and I looked through many tutorials and I couldn't really understand it. From what I gathered, to get the frequency of a sound I need to do fast Fourier transform to find the Fourier trasform of the data. The fourier transform tranforms a signal into a different domain, so basically I would need it to transform the sound wave signals I'm getting into a frequency. I couldn't find any good code or libraries to do this, and I didn't understand it enough to implement it myself, so I decided to pivot and just determine if a clap has happened or not.

It's very simple to determine if a clap has happened. Basically, I measure values for a certain amount of time (I picked 50 ms) and I find the max values and the min values. This tells me the high and low peaks of my sound wave, and so I can get the amplitude of the wave by taking the difference between the 2. The amplitude of a sound wave is how loud the sound is, so I'm basically getting the loudness of a sound this way. I experimented a bit and found out 200 is a good amplitude value to detect clapping, so in the code I basically check if the amplitude is greater than 200, and if it is I print "clapped!".

Diagram of what a Fourier transform does

Final product

Here is the final code. It's very short and simple. If I had more time I would figure out the Fourier transform stuff and how to better process analog data.

In the video you can see me clapping and moving farther and farther away to see how far it'll detect clapping. In the last 2 claps I'm on the other side of my room, and it couldn't detect them. If instead of using the value of 200 I use something less, I could probably detect those claps from accross the room.