# Adafruit PDM Microphone Breakout

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/049/973/medium800/sensors_3492_iso_ORIG_2018_01.jpg?1515618056)

An exotic new microphone has arrived in the Adafruit shop, a **PDM MEMS Microphone**! PDM is the 'third' kind of microphone you can integrate with electronics, apart from analog or I2S. These microphones are very commonly used in products, but are rarely seen in maker projects. Still, they have some benefits so we thought we'd offer a breakout for the shop.

![](https://cdn-learn.adafruit.com/assets/assets/000/080/180/medium800/sensors_PDM_JST_angle.jpg?1567030263)

The first thing to note is that this sensor does not provide an 'analog' output like many of our electret microphone assemblies. So it's great for chips that do not have analog inputs. Secondly, the digital interface is a very simplistic **p** ulse **d** ensity **m** odulation output. It's digital but its _not_ PWM and it's _not_ I2S. You will need to make sure your chip has a PDM interface - most 32-bit processors these days do!

![](https://cdn-learn.adafruit.com/assets/assets/000/049/974/medium800/sensors_3492_quarter_ORIG_2018_01.jpg?1515618067)

PDM is a little like 1-bit PWM. You clock the mic with a 1 MHz - 3 MHz clock rate, and on the data line you'll get a square wave out that syncs with the clock. The data line with be 0 or 1 logic output, with the square wave creating a&nbsp;_density_ that when averaged will result in the analog value out.

![](https://cdn-learn.adafruit.com/assets/assets/000/049/972/medium800/sensors_Pulse_density_modulation.png?1515617720 https://en.wikipedia.org/wiki/Pulse-density_modulation#/media/File:Pulse_density_modulation.svg)

![](https://cdn-learn.adafruit.com/assets/assets/000/080/181/medium800/sensors_PDM_JST_back.jpg?1567030325)

There's a few ways to manage these mics:

- Your chip comes with a hardware peripheral and library that does all the data managing at high speed, collects samples, applies a filter and gives you an analog value (Ideal!)
- Your chip comes with a hardware peripheral that gives you values, then it is up to you to perform the decimation/filtering. (We have some example code for this on the ATSAMD21 chipset)
- Your chip does not come with a hardware peripheral but you're pretty clever and come up with a way to make it work ([See this example for the ATtiny85](https://curiouser.cheshireeng.com/2015/01/21/pdm-in-attiny85-source-code/))
- You generate the high speed clock, then add an analog filter on the data line, and read the analog value (A hack, but works!)

Either way you decide to go, make sure you have a handle on what support you get with your platform, as these chips are a little tricky!

Each order of a PDM Mic comes with one fully assembled and tested microphone, and a little header to solder on for breadboard-compatibility

![](https://cdn-learn.adafruit.com/assets/assets/000/049/975/medium800/sensors_3492_kit_ORIG_2018_01.jpg?1515618078)

Each order of a PDM Mic with JST SH comes with one fully assembled and tested microphone. This version of the mic has a 4-JST SH connector!

![](https://cdn-learn.adafruit.com/assets/assets/000/080/178/medium800/sensors_PDM_JST_top.jpg?1567030126)

The 4-pin JST connector has **3V, GND, DAT, CLK** connections that [can be used with one of our JST-SH cables to make a flexible mic arrangement](https://www.adafruit.com/?q=jst%20sh%204). [If you want a version with breakout headers, we have a version here](https://www.adafruit.com/product/3492). An on-board solder jumper lets you change the mic from Left to Right channel

![](https://cdn-learn.adafruit.com/assets/assets/000/080/179/medium800/sensors_PDM_JST_cable.jpg?1567030211)

# Adafruit PDM Microphone Breakout

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/049/976/medium800/sensors_pinouts.jpg?1515618181)

These mics are very simple!

- **3V -** This is the power input pin, this powers the chip directly. Use a quiet power supply pin if available. (The chip supports 1.8-3.3V but we have not tested it at 1.8V)
- **GND** - Power and data ground reference
- **SEL** - Left/Right select. If this pin is high, the output is on the falling edge of CLK considered the 'Right' channel. If this pin is low, the output is on the rising edge, a.k.a 'Left' channel.
- **CLK** - PDM clock in, 1 - 3 MHz square wave required
- **DAT** - PDM data out.

# Adafruit PDM Microphone Breakout

## Arduino Wiring & Test

At this time we only have example code for the SAMD21 chipset using the I2S peripheral, you'll be limited to what pins you can use and the digital filtering must be done in software but it _does_ work! We don't necessarily recommend this mic for SAMD21 - an analog microphone will work quite well with less hassle!

Warning: 

# Available I2S Pins

As we are using the I2S peripheral, not all pins can be used! For the Feather M0 / Metro M0 / Arduino Zero family, here's the available I2S pins:

Available Clock Pins:

- **PA10** a.k.a D1 or TX
- **PB11** a.k.a SCK
- **PA20** a.k.a. D6

Available Data Pins:

- **PA07** a.k.a D9
- **PA08** a.k.a D4
- **PA19** a.k.a. D12

![](https://cdn-learn.adafruit.com/assets/assets/000/049/979/medium800/sensors_pdmmic_bb.png?1515622334)

# Install Library

[Download the latest version of the **ZeroPDM**](https://github.com/adafruit/Adafruit_ZeroPDM/archive/master.zip) library from github. Install as usual!

We have a two examples, one uses the DMA capability to grab data, which means we don't have to do as much work, but there's more setup involved and [requires the ZeroDMA library](https://github.com/adafruit/Adafruit_ZeroDMA).

We recommend starting with the basic demo, which will echo audio data to **A0** (the the analog output). Connect up headphones or an oscilloscope to A0 to hear/see the audio!

![](https://cdn-learn.adafruit.com/assets/assets/000/049/980/medium800/sensors_demo.png?1515622560)

Before uploading, be sure to change the instantiator to match your pinouts:

```
// Create PDM receiver object, with Clock and Data pins used (not all pins available)
Adafruit_ZeroPDM pdm = Adafruit_ZeroPDM(1, 4);  // Metro M0 or Arduino zero
//Adafruit_ZeroPDM pdm = Adafruit_ZeroPDM(34, 35);  // CPlay express
```

# Adafruit PDM Microphone Breakout

## CircuitPython

It's easy to use the Adafruit PDM microphone breakout with CircuitPython, using the built-in [`audiobusio` module](https://circuitpython.readthedocs.io/en/latest/shared-bindings/audiobusio/ __init__.html) and [`PDMIn` class](https://circuitpython.readthedocs.io/en/latest/shared-bindings/audiobusio/PDMIn.html). It allows you to record an input audio signal from the microphone using PDM.

This page will walk you through wiring up your PDM mic, and using it to print out sound levels to the serial console and show the values on the plotter in Mu.

Info: Only mono input is currently supported.

# CircuitPython Microcontroller Wiring

The following wiring diagrams show how to connect the PDM mic to a Feather M4 Express. If you're using another board, check out the [Where's my PDMIn? section](https://learn.adafruit.com/adafruit-pdm-microphone-breakout/circuitpython#wheres-my-pdmin-4-11) at the end for valid pin combinations for your board. Some boards, like the SAMD21 and SAMD51 have fixed pins that support PDM. Others like the nRF52840 can use _any_ two pins.

The following is the header version of the PDM microphone breakout wired to a Feather M4 Express:

- **Mic 3V** to **Feather 3V**
- **Mic GND** to **Feather Gnd**
- **Mic CLK** to **Feather TX**
- **Mic DAT** to **Feather D12**

![sensors_PDM_Mic_Feather_M4_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/080/198/medium640/sensors_PDM_Mic_Feather_M4_bb.png?1567106674)

The following is the JST version of the PDM microphone breakout wired to a Feather M4 Express:

- **Mic 3V (red wire)** to **Feather 3V**
- **Mic GND (black wire)** to **Feather Gnd**
- **Mic DAT (blue wire)** to **Feather D12**
- **Mic CLK (yellow wire)** to **Feather TX**

![sensors_PDM_Mic_JST_Feather_M4_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/080/204/medium640/sensors_PDM_Mic_JST_Feather_M4_bb.png?1567111022)

If you're using Circuit Playground Express, there is a built in PDM microphone. There is [a guide page dedicated to using Circuit Playground Express and the built-in microphone](https://learn.adafruit.com/sensor-plotting-with-mu-and-circuitpython/sound). If you're using a CPX, check that out instead!

# CircuitPython Usage

As `PDMIn` is built into CircuitPython, no separate libraries are necessary for this example!

Save the following as code.py on your microcontroller board:

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/PDM_Microphone/PDM_Mic_Sound_Level_Plot/code.py

First you import `time`, `array`, `math`, `board` and `audiobusio`.

Then you have two helper functions. The first one uses math to return a mean, or average. It is used in the second helper. The second one uses math to return a [normalised RMS average](https://en.wikipedia.org/wiki/Root_mean_square). You use these functions to take multiple sound samples really quickly and average them to get a more accurate reading.

Next you set up the microphone object and your samples variable.

Then you use the mic object to start taking sound samples. You use the normalised RMS to find the average of a given set of samples, and you call that the `magnitude`. Last, you `print` the `magnitude` to the serial console.

Note that the Mu plotter looks for **tuple** values to print. Tuples in Python come in parentheses `()` with comma separators. If you have two values, a tuple would look like `(1.0, 3.14)` Since you have only one value, you need to have it print out like&nbsp;`(1.0,)` note the parentheses _around_ the number, and the _comma_ after the number. Thus the extra parentheses and comma in `print((magnitude,))`.

Once you have everything setup and running, try speaking towards the microphone, and watch the plotter immediately react! Move further away from the microphone to cause smaller changes in the plotter line. Move closer to the board to see bigger spikes!

Note that the way that the code works with averaging a given number of readings over time means that short sounds like claps can sometimes get missed. If you feel like your mic is not responding, try a longer sound like a hum or speaking words.

It's a really easy way to test your microphone and see how it reads sound changes!

![](https://cdn-learn.adafruit.com/assets/assets/000/080/206/medium800/sensors_PDM_Mic_Mu_Plotter.png?1567112054)

# Where's my `PDMIn`?

Save the following as code.py on your board, and connect to the serial console to see a list of all the valid `PDMIn` pin combinations. Note: the code will run immediately and only runs once - if you connect to the serial console and don't see anything, press ctrl+D to reload and run the code again.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/PDM_Microphone/Wheres_my_PDMIn/code.py

# Adafruit PDM Microphone Breakout

## Downloads

# Files

- [MP34DT01-M datasheet](https://cdn-learn.adafruit.com/assets/assets/000/049/977/original/MP34DT01-M.pdf)
- [Fritzing file on GitHub](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20PDM%20Mic%20with%20JST.fzpz)
- [3D Models on GitHub](https://github.com/adafruit/Adafruit_CAD_Parts/tree/main/4346%20PDM%20Mic%20Breakout)

# Schematic & Fabrication Print
![](https://cdn-learn.adafruit.com/assets/assets/000/049/982/medium800/sensors_pdm.png?1515622761)

![](https://cdn-learn.adafruit.com/assets/assets/000/049/983/medium800/sensors_print.png?1515622768)

# 3D Model
![](https://cdn-learn.adafruit.com/assets/assets/000/108/528/medium800thumb/sensors_pdm-mic-with-jst-sh.jpg?1643730951)

## PDM Mic with JST connector
![](https://cdn-learn.adafruit.com/assets/assets/000/080/176/medium800/sensors_PDM_Mic_with_JST_Sch.png?1567029851)

![](https://cdn-learn.adafruit.com/assets/assets/000/080/177/medium800/sensors_PDM_Mic_with_JST_Fab_Print.png?1567029858)


## Featured Products

### Adafruit PDM MEMS Microphone Breakout

[Adafruit PDM MEMS Microphone Breakout](https://www.adafruit.com/product/3492)
An exotic new microphone has arrived in the Adafruit shop, a **PDM MEMS Microphone**! PDM is the 'third' kind of microphone you can integrate with electronics, apart from analog or I2S. These microphones are very commonly used in products, but are rarely seen in maker...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3492)
[Related Guides to the Product](https://learn.adafruit.com/products/3492/guides)
### Adafruit PDM Microphone Breakout with JST SH Connector

[Adafruit PDM Microphone Breakout with JST SH Connector](https://www.adafruit.com/product/4346)
An exotic new microphone has arrived in the Adafruit shop, a **PDM MEMS Microphone**! PDM is the 'third' kind of microphone you can integrate with electronics, apart from analog or I2S. These microphones are very commonly used in products, but are rarely seen in maker...

In Stock
[Buy Now](https://www.adafruit.com/product/4346)
[Related Guides to the Product](https://learn.adafruit.com/products/4346/guides)

## Related Guides

- [NeoPixel Mini VU Meter](https://learn.adafruit.com/neopixel-mini-vu-meter.md)
- [Spruce Up a Costume with MONSTER M4SK Eyes and Voice](https://learn.adafruit.com/spruce-up-a-costume-with-monster-m4sk-eyes-and-voice.md)
- [Fruit Jam Video Music](https://learn.adafruit.com/fruit-jam-video-music.md)
- [Goose Game M4SK Controller](https://learn.adafruit.com/goose-game-m4sk-controller.md)
- [Feather RP2350 Audio Reactive Video Synth](https://learn.adafruit.com/feather-rp2350-audio-reactive-video-synth.md)
- [Sound Reactive LED Top Hat](https://learn.adafruit.com/sound-reactive-led-top-hat.md)
- [Velociraptor Voice and Eye Upgrade with MONSTER M4SK](https://learn.adafruit.com/hand-puppet-voice-and-eye-upgrade-with-monster-m4sk.md)
- [USB C Power Delivery Monitor](https://learn.adafruit.com/usb-c-benchtop-power-supply.md)
- [Adafruit LTR390 UV Sensor](https://learn.adafruit.com/adafruit-ltr390-uv-sensor.md)
- [Adafruit ADS7830 8-Channel 8-Bit ADC](https://learn.adafruit.com/adafruit-ads7830-8-channel-8-bit-adc.md)
- [Adafruit MMA8451 Accelerometer Breakout](https://learn.adafruit.com/adafruit-mma8451-accelerometer-breakout.md)
- [Adafruit Metro ESP32-S3](https://learn.adafruit.com/adafruit-metro-esp32-s3.md)
- [Adafruit SEN6x Breakout](https://learn.adafruit.com/adafruit-sen6x-breakout.md)
- [Adafruit PiCowbell CAN Bus for Pico](https://learn.adafruit.com/adafruit-picowbell-can-bus-for-pico.md)
- [Booster Cable](https://learn.adafruit.com/booster-cable.md)
