1. 시작
아두이노와 친해지면서 다음 센서는 뭐할까 하다가,
스피커처럼 생겼지만 사실은 마이크인 "Electret Microphone Amplifier" 를 알게 되었습니다.
특이하게 Electret 이라는 단어가 눈에 띕니다.
의미는 Electricity 와 Magnet 의 합성어라고 하네요.
* 일렉트릿
- http://100.daum.net/encyclopedia/view/b18a1451a
전계를 가했을 때 생긴유전 분극이 전계를 없앤 다음까지 잔류하는 물질로 만든 하전체.
자기에서의 영구 자석에 대응하는 것이다. 폴리프로필렌이나 마일러 등의 플라스틱으로 만들며, 소형 마이크로폰 등에 이용된다.
소형 마이크로폰에 사용된다고 하네요. 외관 모양 그대로의 기능을 가지고 있습니다.
Wikipedia 에서 설명은 다음에서 하고 있습니다.
* Electret
- https://en.wikipedia.org/wiki/Electret
2. 구매
용돈 생활인의 안식처, 알리에서 찾아 봅니다.
adafruit 에서는 6.95 USD 입니다만, 알리는 1.66 USD 입니다.
* Electret Microphone Amplifier MAX4466 Adjustable Gain Breakout Board For Arduino MAX4466 Module
제품 설명에서는 홈페이지에서는 스펙에 대해 잘 설명되어 있습니다.
- 20 ~ 20KHz
- DC 2.4 ~ 5V
Add an ear to your project with this well-designed electret microphone amplifier. This fully assembled and tested board comes with a 20-20KHz electret microphone soldered on. This breakout is best used for projects such as voice changers, audio recordingmpling,
and audio-reactive projects that use FFT.
On the back, we include a small trimmer pot to adjust the gain.
Using it is simple: connect GND to ground, VCC to 2.4-5VDC. The output pin is not designed to drive speakers or anything but the smallest in-ear headphones you'll need an audio amplifier (such as our 3.7W stereo amp) if you want to connect the amp directly to speakers. [Specification] For the amplification, we use the Maxim MAX4466, an op-amp specifically designed for this delicate task! The amplifier has excellent power supply noise rejection, so this amplifier sounds really good and isn't nearly as noisy or scratchy as other mic amp breakouts we've tried! You can set the gain from 25x to 125x. That's down to be about 200mVpp (for normal speaking volume about 6" away) which is good for attaching to something that expects 'line level' input without clipping, or up to about 1Vpp, ideal for reading from a microcontroller ADC. The output is rail-to-rail so if the sounds gets loud, the output can go up to 5Vpp! For the best performance, use the "quietest" supply available (on an For Arduino, this would be the 3.3V supply). The audio waveform will come out of the OUT pin. The output will have a DC bias of VCC/2 so when its perfectly quiet, the voltage will be a steady VCC/2 volts (it is DC coupled).
If the audio equipment you're using requires AC coupled audio,
place a 100uF capacitor between the output pin and the input of your device.
If you're connecting to an audio amplifier that has differential inputs or includes decoupling capacitors,
the 100uF cap is not required.
3. adafruit 과의 비교
원본은 adafruit 의 MAX4466 breakout 로 보입니다.
이래는 비교 입니다.
* Electret Microphone Amplifier - MAX4466 with Adjustable Gain
- https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/assembly-and-wiring
마이크 부분을 제외하고 뒷면을 보면, 숫자 표기는 달라도 저항의 값은 모두 같은 것을 사용한 것으로 보입니다.
앞부분은 평범합니다.
처음 도착시 동봉되어 있던, male pin 이 어디로 가버려
따로 구매한 핀 중에서 이쁜 색으로 나온 노란색 male pin 을 사용합니다.
Male pin 구매기는 아래를 참고하세요.
* Hardware | 2.54mm pin header 구매하기
- http://chocoball.tistory.com/entry/Hardware-254mm-pin-header
4. Layout
회로 구성은 다음과 같습니다.
MAX4466 | Arduino Nano --------------------------- VCC | 3.3V GND | GND OUT | A0 --------------------------- SSD1306 | Arduino Nano --------------------------- GND | GND VDD | 3.3V SCK | A5 SDA | A4 ---------------------------
VU meter 를 같이 이용하기 위해 SSD1306 도 같이 연결하였습니다.
5. Sketch
아래 보이는 sketch 는 adafruit 가 제공하는 기본 소스 입니다.
/**************************************** Example Sound Level Sketch for the Adafruit Microphone Amplifier ****************************************/ const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz) unsigned int sample; void setup() { Serial.begin(9600); } void loop() { unsigned long startMillis= millis(); // Start of sample window unsigned int peakToPeak = 0; // peak-to-peak level unsigned int signalMax = 0; unsigned int signalMin = 1024; // collect data for 50 mS while (millis() - startMillis < sampleWindow) { sample = analogRead(0); if (sample < 1024) // toss out spurious readings { if (sample > signalMax) { signalMax = sample; // save just the max levels } else if (sample < signalMin) { signalMin = sample; // save just the min levels } } } peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude double volts = (peakToPeak * 5.0) / 1024; // convert to volts Serial.println(volts); }
이 소스를 이용하면, 입력된 voltage 값을 Serial Monitor 를 통해 확인할 수 있습니다.
그래프로 그려보면 다음과 같습니다.
그래프가 튀는 부분은 "아~" 라고 소리를 질러 변화를 준 부분입니다.
6. VU meter 와 연동하기
아래 링크는 SSD1306 OLED 를 이용한 VU meter 연동 글입니다.
* Hardware | SSD1306 monochrome OLED 를 가지고 VU meter 를 만들어보자
Hardware | SSD1306 monochrome OLED 를 가지고 VU meter 를 만들어보자
출처: http://chocoball.tistory.com/entry/Hardware-VU-meter-using-SSD1306-monochrome-OLED [초코볼의 inside Tech]
출처: http://chocoball.tistory.com/entry/Hardware-VU-meter-using-SSD1306-monochrome-OLED [초코볼의 inside Tech]
Hardware | SSD1306 monochrome OLED 를 가지고 VU meter 를 만들어보자
출처: http://chocoball.tistory.com/entry/Hardware-VU-meter-using-SSD1306-monochrome-OLED [초코볼의 inside Tech]
출처: http://chocoball.tistory.com/entry/Hardware-VU-meter-using-SSD1306-monochrome-OLED [초코볼의 inside Tech]
Hardware | SSD1306 monochrome OLED 를 가지고 VU meter 를 만들어보자
출처: http://chocoball.tistory.com/entry/Hardware-VU-meter-using-SSD1306-monochrome-OLED [초코볼의 inside Tech]
출처: http://chocoball.tistory.com/entry/Hardware-VU-meter-using-SSD1306-monochrome-OLED [초코볼의 inside Tech]
- http://chocoball.tistory.com/entry/Hardware-VU-meter-using-SSD1306-monochrome-OLED
Pin 연결은 동일하기 때문에 그대로 사용했습니다.
/* OLEDMeter was written to utilize any 128x64 display. I have only seen marginal attempts to * animate meters and I hope this one will set a standard. Please feel free to modify and share * this code for any 128x64 LCD or OLED. OLEDMeter sketch was written for use with I2C SH1106. * This code must be modified to work with other display devices. * * Working portion of code was taken from Adafruit Example Sound Level Sketch for the * Adafruit Microphone Amplifier * https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/measuring-sound-levels * * Remaining code was written by Greg Stievenart with no claim to or any images or information * provided in this code. Freely published May 26, 2016. * * Software to convert background mask to 128x64 at: http://www.ablab.in/image2glcd-software/ * * IMPORTANT: Sound source must be grounded to the Arduino or other MCU's to work. Usually the * base sleeve contact on TRS or TRRS connector is the ground. */ #include "Wire.h" // requried to run I2C SH1106 #include "SPI.h" // requried to run I2C SH1106 #include "Adafruit_GFX.h" // https://github.com/adafruit/Adafruit-GFX-Library #include "Adafruit_SSD1306.h" // https://github.com/wonho-maker/Adafruit_SH1106 #define OLED_RESET 4 // reset required for SH1106 Adafruit_SSD1306 display(OLED_RESET); // reset required for SH1106 int analogInput = A0; // analog input for outside audio source int hMeter = 65; // horizontal center for needle animation int vMeter = 85; // vertical center for needle animation (outside of dislay limits) int rMeter = 80; // length of needle animation or arch of needle travel const int sampleWindow = 50; // sample window width in mS (50 mS = 20Hz) unsigned int sample; // VU meter background mask image static const unsigned char PROGMEM VUMeter[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x60, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x09, 0x04, 0x80, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x98, 0x08, 0x06, 0x03, 0x80, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0x10, 0x09, 0x00, 0x80, 0x21, 0x20, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0x10, 0x06, 0x03, 0x00, 0x20, 0xC0, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x71, 0x80, 0xA4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x40, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x3A, 0x40, 0x00, 0x00, 0x02, 0x01, 0x00, 0x40, 0x80, 0x07, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x42, 0x40, 0x00, 0x08, 0x02, 0x01, 0x08, 0x40, 0x80, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x79, 0x80, 0x04, 0x08, 0x02, 0x01, 0x08, 0x81, 0x10, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x02, 0x01, 0x08, 0x81, 0x11, 0x04, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x02, 0x01, 0x08, 0x81, 0x21, 0x04, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x84, 0x02, 0x04, 0x0F, 0xFF, 0xFF, 0xC3, 0xE2, 0x04, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0xC2, 0x01, 0x07, 0xF0, 0x00, 0x00, 0x3B, 0xFE, 0x08, 0x40, 0x40, 0x08, 0x00, 0x00, 0xFE, 0x00, 0x62, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xE8, 0x40, 0x80, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x21, 0x1E, 0x00, 0x04, 0x00, 0x80, 0x00, 0x7F, 0xFE, 0x80, 0x80, 0x08, 0x00, 0x00, 0x00, 0x03, 0x31, 0xE0, 0x00, 0x04, 0x00, 0x80, 0x04, 0x01, 0xFF, 0xC1, 0x00, 0x08, 0x00, 0x00, 0x00, 0x07, 0x1E, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x1F, 0xFA, 0x00, 0x08, 0x00, 0x00, 0x00, 0x07, 0xF0, 0x00, 0x40, 0x3B, 0x07, 0x60, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x34, 0x81, 0x90, 0xCC, 0xC0, 0x00, 0x3F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x03, 0x30, 0x0C, 0x82, 0x90, 0x53, 0x20, 0x00, 0x07, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x70, 0x40, 0x00, 0xC8, 0x3B, 0x02, 0x60, 0x53, 0x20, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x01, 0x80, 0x20, 0x01, 0xC8, 0x00, 0x00, 0x00, 0x4C, 0xC0, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x06, 0x00, 0x00, 0x03, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFC, 0x00, 0x00, 0x30, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x40, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xA0, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x02, 0x02, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x06, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x8C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x70, 0x19, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; void setup() { pinMode(analogInput, INPUT); // analog input for outside audio source display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // needed for SH1106 display display.clearDisplay(); // clears display from any library info displayed Serial.begin(9600); } void loop() { /*********************************************************************** Start of code taken from Adafruit Example Sound Level Sketch for the Adafruit Microphone Amplifier ************************************************************************/ unsigned long startMillis= millis(); // Start of sample window unsigned int peakToPeak = 0; // peak-to-peak level unsigned int signalMax = 0; unsigned int signalMin = 1024; // collect data for 50 mS while (millis() - startMillis < sampleWindow) { sample = analogRead(0); if (sample < 1024) { // toss out spurious readings if (sample > signalMax) { signalMax = sample; // save just the max levels } else if (sample < signalMin) { signalMin = sample; // save just the min levels } } } peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude float MeterValue = peakToPeak * 330 / 1024; // convert volts to arrow information double volts = (peakToPeak * 5.0) / 1024; // convert to volts /**************************************************** End of code taken from Adafruit Sound Level Sketch *****************************************************/ MeterValue = MeterValue - 34; // shifts needle to zero position display.clearDisplay(); // refresh display for next step display.drawBitmap(0, 0, VUMeter, 128, 64, WHITE); // draws background int a1 = (hMeter + (sin(MeterValue / 57.296) * rMeter)); // meter needle horizontal coordinate int a2 = (vMeter - (cos(MeterValue / 57.296) * rMeter)); // meter needle vertical coordinate display.drawLine(a1, a2, hMeter, vMeter, WHITE); // draws needle display.display(); Serial.println(volts); }
연결되어 VU meter 가 잘 표시되네요.
구동 동영상 입니다.
7. VCC 와 GND
처음에 VU meter 의 바늘이 널띄면서 도저희 측정할 수 있는 상태가 아니였습니다.
Pin 들의 접점이 문제인가 여러번 빼고 꼽고 했지만 개선이 이루어지지 않았습니다.
최종적으로 생각한 것은 예민한 센서이다 보니, 잡음이 원인이 아닌가 하는 것이였습니다.
위의 사진처럼 SSD1306 과 동일하게 사용하는 공통 VCC/GND 에 연결한 것을,
아래처럼 각각 arduino 의 VCC/GND 에 연결하니 해결되었습니다.
예민한 센서류는 공통 VCC/GND 에 연결하면 안되는 거군요.
이렇게 하나 배워 봅니다.
FIN
소형 마이크에는 Electret 소자가 사용된다 합니다.
Arduino 를 위한 소리 감지용 breakout 보드도 나와 줘서 필요시 잘 사용할 것 같습니다.
'Hardware' 카테고리의 다른 글
Hardware | Arduino 로 Photoresister 가지고 놀기 - 2 (0) | 2018.02.28 |
---|---|
Hardware | Digitial Compass - HMC5883L 사용기 - 1 (0) | 2018.02.19 |
Hardware | 2.54mm pin header 구매하기 (0) | 2018.02.11 |
Hardware | LED 구매하기 (0) | 2018.01.27 |
Hardware | Flight Feeder 를 신청해 보자 (15) | 2018.01.19 |