Russ said he had trouble using a bare electret mic as an input device in his Arduino 201 sensors class. I hope to help by making up a couple of simple mic preamp boards. There was an initial prototype, and a short ‘production’ run with a better layout, allowing a smaller board and putting the header pins closer to the edge so they don’t obscure as much of the breadboard. I stuck a couple of the mics pulled out of the Sansa recorders on to try them out. I also played with code ’til I got a decent one-LED PWM “applause meter”.
It’s a very simple one transistor amplifier, and the output still rides on a DC offset, just like with a standalone electret mic. That was mostly so the students would have to deal with the DC offset. Overall gain is about 100. With one sample board, the analogRead() DC offset is about 320 (of 1024) and a loud noise gives a peak around 650 higher than that, so it’s a pretty good match for the Arduino’s A/D range.
I tried a couple of approaches in the code to automatically remove the DC offset and “rectify” the signal. Final result was running batches of 600 reads (about 70 ms) and keeping both the max reading and the average over that time. With that many samples effectively at random times within the audio waveform, statistically we’re pretty likely to hit close to at least one near-peak reading each run – and it seems to work pretty well in practice. Students can start with a simple version of the code ( loop() is only 9 lines). There’s also a fast attack/slow release feature in an independent, additional block of code. The code is in the W88 shared dropbox under Arduino201ScratchSpace.
While the target use case is on a breadboard, since I’m lazy and wanted to try it out on a bare Arduino, I put the 3 header pins in A0,A1, A2. I used one as the obvious analog input, and the others as digital outputs, one constantly putting out HIGH, the other LOW to provide approximately +5 and ground. Worked fine. It responds to normal conversation maybe 2 feet away from the mic with a visible brightening of the LED. A handclap shows a bright attack/release. I hope Russ finds the boards useful.