tutorialspinouttools
Sensors · ESP32-C3

MAX9814 on OLED: Microphone with Auto-Gain

Free ESP32 & Arduino tutorial · wiring, code & parts · gokul.builds

Overview & Wiring

What it is: The MAX9814 is an electret microphone amplifier with automatic gain control (AGC) — it boosts quiet sounds and tames loud ones so the output stays in a usable range. It's a big step up from the KY-038 for sound-reactive projects. How it works: It outputs a clean analog audio signal centred near half its supply. Like any mic, you sample fast and measure peak-to-peak to get loudness. This sketch shows a 0–100 level with a bar. Wiring: MAX9814 OUT -> GPIO0 (analog) MAX9814 VDD -> 3V3 MAX9814 GND -> GND (leave GAIN and A/R pins unconnected for default behaviour) OLED VCC=3V3, GND=GND, SDA=GPIO4, SCL=GPIO5 Libraries: only "Adafruit SSD1306" and "Adafruit GFX Library". On screen / Serial: sound level 0–100 with a bar. Talk, clap, or play music near it. Gotchas: The AGC means absolute loudness isn't linear — it's great for "how loud relative to now", not for SPL/decibel measurement. The GAIN pin can be tied to set 40/50/60 dB; floating gives the mid setting. Its output centres near VDD/2, which the peak-to-peak method handles.

Circuit Diagram

MAX9814 on OLED: Microphone with Auto-Gain wiring diagram for ESP32-C3

Parts You Need

ESP32-C3 SuperMiniBuy →
0.96" SSD1306 OLEDBuy →

Source Code (Arduino / ESP32)

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display(128, 64, &Wire, -1);

#define MIC 0                 // OUT on GPIO0 (ADC)

void setup() {
  Serial.begin(115200);
  Wire.begin(4, 5);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}

void loop() {
  int hi = 0, lo = 4095;
  unsigned long start = millis();
  while (millis() - start < 40) {              // 40 ms window
    int v = analogRead(MIC);
    if (v > hi) hi = v;
    if (v < lo) lo = v;
  }
  int pp = hi - lo;
  int level = map(constrain(pp, 0, 3500), 0, 3500, 0, 100);

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("MAX9814 Mic");
  display.setTextSize(3);
  display.setCursor(0, 18);
  display.printf("%d", level);
  display.drawRect(0, 54, 128, 8, SSD1306_WHITE);
  display.fillRect(0, 54, map(level, 0, 100, 0, 128), 8, SSD1306_WHITE);
  display.display();

  Serial.printf("Sound: %d  (pp %d)\n", level, pp);
}
Browse all tutorials ESP32-C3 pinout Calculators