Labs / Electronic modules

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

Author: Li Zisheng · Source: FreakStudio open documentation, v1.3 · License: CC BY 4.0 · Driver code (sensors/max9814_mic_driver): MIT License

Contents
GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)
GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

I. Module Introduction

Electret Condenser Microphone Module Based on MAX9814 Centering on the MAX9814 chip that integrates Automatic Gain Control (AGC) and low-noise bias, this module is designed with on-board non-inverting amplifier circuit, sensor interface (supporting DOUT for gain control and AIN for analog output), as well as filtering and indicator circuits. It can efficiently collect audio signals and provides three gain adjustment levels of 40dB/50dB/60dB. Suitable for scenarios such as maker audio acquisition, speech recognition and portable recording, it is a low-cost, high-quality audio front-end solution.

II. Introduction to Main Chips

This module is mainly based on MAX9814, a microphone amplifier chip featuring AGC and low-noise microphone bias circuit.

2.1 Chip Overview

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

2.2 Pin Definition

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

2.3 Functional Block Diagram

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)
GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)
GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

2.4 Performance Parameters

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)
GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)
GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)
GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)
GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)
GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

2.5 Reference Circuit

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

2.6 Chip Configuration

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)
GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

Modifying the connection mode of the A/R pins (connecting to GND, VDD or leaving unconnected) will alter the attack/release ratio of AGC; adjusting the capacitance of the CCT capacitor will change the attack time and release time of AGC. The two factors jointly affect the dynamic response characteristics of AGC for audio signal gain adjustment, such as the speed of gain variation and amplitude control, etc.

None.

2.8 PCB Routing Precautions

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

III. Instructions for Circuit Engineering and Module Usage

3.1 Circuit Source Engineering

To obtain the source code of the circuit, please follow the official account [Freak Embedded]

3.2 Module Usage Instructions

The schematic diagram of this module is shown below:

SCH_MAX9814-Based_Electret_Condenser_Microphone_Module_v1.0_2025-11-24.pdf 2.4 MB

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)
GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

This module provides gain control DOUT interface and analog output AIN interface: DOUT is connected to the MCU 's GPIO, and the gain of MAX9814 (e. g., switching between 40dB/50dB/60dB and other gain levels) can be configured by the high/low level output from the MCU;AIN is connected to the MCU ' s ADC, which is used to collect the analog audio signal output by the module.

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

The schematic diagram is explained as follows:

3.3 Application Experiment

Here, we use the GraftPort-RP2040 development board for testing, and connect the electret condenser microphone module based on MAX9814 to communicate with the main controller via the AIN interface.

Here, we first use the HY2.0-4P connection cable to connect the module to the GraftPort-RP2040 development board's AIN0 interface:

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

The module connections are shown in the following table:

Development Board Pins

Module Pins

Description

Pin 26

AIN

Microphone analog signal input pin

Pin 19

DIO

Microphone amplifier chip gain control digital pin

Here, we need to search for relevant driver packages on uPyPI: https://upypi.net/zh/

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

Enter max9814_mic_driver to search, and the following will be displayed:

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

Click to copy the local installation command:

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

Here, we can use the mip tool to import module driver library code. Below are the usage commands for the mpremote tool:

mpremote mip install github:FreakStudioCN/GraftSense-Drivers-MicroPython/sensors/max9814_mic_driver

Import the MAX9814-based electret condenser microphone module - MicroPython driver code, then copy the following main.py code into our project:

# Python env   : MicroPython v1.23.0
# -*- coding: utf-8 -*-
# @Time    : 2025/8/28
# @Author  : 缪贵成
# @File    : main.py
# @Description : MAX9814 microphone driver simple test

# ======================================== Import Modules =========================================

import time
from machine import Pin, ADC
from max9814_mic import MAX9814Mic

# ======================================== Global Variables ============================================

# ======================================== Functions ============================================

def get_formatted_time() -> str:
    """
    Get the formatted time string (HH:MM:SS).

    Returns:
        str: The formatted time string.

    Notes:
        Use time.localtime() to get the local time.
        Suitable for log printing.

    ==========================================

    Get formatted time string (HH:MM:SS).

    Returns:
        str: Formatted time string.

    Notes:
        Uses time.localtime().
        Useful for log printing.
    """
    # Get the current local time tuple
    t = time.localtime()
    # Format the output as hours, minutes, and seconds
    return "{:02d}:{:02d}:{:02d}".format(t[3], t[4], t[5])

def test_basic_reading() -> None:
    """
    Basic read test: continuously print the raw value, normalized value, and voltage.

    Raises:
        KeyboardInterrupt: Exit when interrupted by the user.

    Notes:
        GP26 (ADC0) is used by default.
        Runs in a loop for about 10 seconds.
    ==========================================

    Basic reading test: print raw, normalized, and voltage.

    Raises:
        KeyboardInterrupt: On user interrupt.

    Notes:
        Uses GP26 (ADC0).
        Runs ~10 seconds.
    """
    # Initialization configuration
    time.sleep(3)
    print("FreakStudio:max9814_mic_driver test start")
    print("=== Basic Reading Test ===")
    # GP26 = ADC0 input
    adc = ADC(26)

    # Initialize the microphone instance
    mic = MAX9814Mic(adc=adc)

    print("Microphone initialized on ADC0 (GP26)")
    # Print the module status
    print("State:", mic.get_state())
    print("Reading values for ~10 seconds...")

    try:
        # Once every 0.1 seconds, 10 seconds in total
        for i in range(100):
            # Raw ADC value
            raw_value = mic.read()
            # Normalized value (0–1)
            normalized = mic.read_normalized()
            # Voltage value (V)
            voltage = mic.read_voltage()
            print("[{}] Raw:{:5d} | Norm:{:.3f} | Volt:{:.3f}V".format(
                get_formatted_time(), raw_value, normalized, voltage
            ))
            # Delay 0.5 seconds
            time.sleep(0.5)
    except KeyboardInterrupt:
        print("\n[{}] Basic test interrupted".format(get_formatted_time()))

def test_with_gain_control() -> None:
    """
    Gain control test: switch between low-gain and high-gain modes and sample.

    Raises:
        KeyboardInterrupt: Exit when interrupted by the user.

    Notes:
        GP15 is used to control the gain.
        Low-gain mode runs first, then switches to high-gain mode.

    ==========================================

    Gain control test: switch low/high gain modes.

    Raises:
        KeyboardInterrupt: On user interrupt.

    Notes:
        GP15 controls gain pin.
        Runs low gain first, then high gain.
    """
    # Initialization configuration
    time.sleep(3)
    print("FreakStudio:max9814_mic_driver test start")
    print("=== Basic Reading Test ===")
    # GP26 = ADC0 input
    adc = ADC(26)

    # Initialize GP6 as the gain control pin
    gain_pin = Pin(6, Pin.OUT)
    mic = MAX9814Mic(adc=adc, gain_pin=gain_pin)
    try:
        # Low-gain mode
        print("=== LOW GAIN mode ===")
        mic.set_gain(False)  # Set to low gain
        print("State:", mic.get_state())
        for i in range(50):
            print("[LOW] {:5d}".format(mic.read()), end=" ")
            if (i + 1) % 5 == 0:  # New line every 5 values
                print()
            time.sleep(0.6)

        # High-gain mode
        print("\n=== HIGH GAIN mode ===")
        mic.set_gain(True)  # Set to high gain
        print("State:", mic.get_state())
        for i in range(50):
            print("[HIGH]{:5d}".format(mic.read()), end=" ")
            if (i + 1) % 5 == 0:
                print()
            time.sleep(0.6)

    except KeyboardInterrupt:
        print("\n[{}] Gain test interrupted".format(get_formatted_time()))

def test_sound_detection() -> None:
    """
    Sound detection test: determine whether there is sound in the environment based on a threshold.
    Raises:
        KeyboardInterrupt: Exit when interrupted by the user.
    Notes:
        Automatically calibrate the ambient noise baseline.
        Threshold = baseline + 5000.
        Detection results are printed in real time.

    ==========================================

    Sound detection test: detect sound above threshold.

    Raises:
        KeyboardInterrupt: On user interrupt.

    Notes:
        Calibrates baseline automatically.
        Threshold = baseline + 5000.
        Prints detection results.
    """
    # Initialization configuration
    time.sleep(3)
    print("FreakStudio:max9814_mic_driver test start")
    print("=== Basic Reading Test ===")
    # GP26 = ADC0 input
    adc = ADC(26)

    # Initialize the microphone instance
    mic = MAX9814Mic(adc=adc)
    print("Calibrating baseline noise level...")
    # Get the average ambient noise level
    baseline = mic.calibrate_baseline(samples=200)
    # Set the threshold
    threshold = baseline + 5000
    print("Baseline:", baseline)
    print("Threshold:", threshold)
    print("Make some noise near the mic! (Ctrl+C to stop)")

    try:
        # Counter, records silent cycles
        silent_count = 0
        while True:
            # Current reading
            current_value = mic.read()
            # Check whether the threshold is exceeded
            is_sound = mic.detect_sound_level(threshold=threshold, samples=10)
            if is_sound:
                # Get the peak value
                peak = mic.get_peak_reading(samples=20)
                print("[{}] SOUND! Current:{} Peak:{}".format(
                    get_formatted_time(), current_value, peak
                ))
                silent_count = 0
            else:
                silent_count += 1
                # Print the status once every 50 quiet detections
                if silent_count % 50 == 0:
                    print("[{}] Silent... Current:{} (Th:{})".format(
                        get_formatted_time(), current_value, threshold
                    ))
            time.sleep(0.6)
    except KeyboardInterrupt:
        print("\n[{}] Detection stopped".format(get_formatted_time()))

# ======================================== Custom Classes =============================================

# ======================================== Initialization configuration ===========================================

# ========================================  Main Program  ============================================

print("MAX9814 Microphone Simplified Test Suite")
print("Choose test mode by editing code:")
print("1. Basic reading test")
print("2. Gain control test")
print("3. Sound detection test")
time.sleep(5)

try:
    # Modify the function call below to select the test mode
    # test_basic_reading()
    # test_with_gain_control()
    test_sound_detection()
except Exception as e:
    print("Error:", e)

To flash the code, open a terminal and use the mpremote tool to connect to the main controller; the output is as follows:

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)

Next, we need to get close to the microphone to speak or play music, and you can see that the corresponding volume value and peak value change:

IV. Drivers

max9814_mic_driver.zip 17 KB

None.

VI. Revision History

Document Version

Date of Revision

Modifier

Revised Content

v1.0

2025-11-24

Li Zisheng

Initialize the document

The BOM sheet has not been finally checked, the driver has not been re-verified, and the 3.3 application experiment

Not yet specified.

v1.1

2025-12-29

Li Zisheng

Added application experiments and production files

v1.2

2025-12-31

Xin Ruili

Create an open version of the document based on the internal document version v1.1.

v1.3

2026-03-29

Xin Ruili

Modified the application experiment section

VII. Relevant Materials

7.1 Chip Datasheet

C41714_Audio_Power_Amplifier_MAX9814ETD+T_Datasheet_WJ105517.PDF 635 KB

max9814_cn.pdf 1.4 MB

7.2 Unique Icons for PCB Silk Screen

GraftSense: Electret Condenser Microphone Module Based on MAX9814 (Open Version)