Spresense Hero 500 V2Spresense Hero 500 V2

Visual AI solutions combined with powerful sound diagnostics for real-time decision making

The Spresense microcontroller board enables edge solutions with high computing ability and low power consumption.

How to use the multiple microphone inputs of Spresense with the Arduino IDE

Spresense MultimicsSpresense Multimics

To connect microphones to the Spresense board, the Spresense extension board is needed to make the connection pins available. More information about how to connect microphones can be found here.

According to the schematic of microphone channel placement in the link above there are 4 different analog ports named A to D. To record in stereo mode it is enough to simply connect two microphones to input A and B, and then select stereo mode (AS_CHANNEL_STEREO) when initializing the recorder. The captured data will have all input from Input A in the left audio channel and that from Input B in the right one. Similarly, if all four inputs A to D are connected, use mode AS_CHANNEL_4CH when initializing the recorder and the resulting audio data will contain four channels.

For this quick demonstration of how to record from two microphones simultaneously we will need the following equipment:

  • 1 Spresense main board
  • 1 Spresense extension board
  • 2 Analog electret microphones
  • 2 resistors at 2.2 kΩ

1Step 1

Attach the Spresense main board to the extension board if you haven’t already. Detailed information on how to do this can be found here.

Connect the microphones and resistors to the extension board according to the drawing below. In this example we will use electret condenser-based microphones which require a bias voltage on the input line, and to supply this some resistors are needed:

Stereo Recording BbStereo Recording Bb

For more information about connecting analog microphones and how to add resistors to the board itself instead (which would void the warranty) please see https://developer.sony.com/develop/spresense/docs/hw_docs_en.html#_how_to_connect_analog_microphones

To test the microphones, copy the small program below into the Arduino IDE and run it on the board. Try to keep the microphones pointing in different directions so it is easy to separate them in the resulting audio.

#include <Audio.h>

AudioClass *theAudio;

void setup() {
  theAudio = AudioClass::getInstance();
  /* Setup a baseband audio path from mic input to line out */
  theAudio->setThroughMode(AudioClass::MicIn, AudioClass::None,
                           true, 160, AS_SP_DRV_MODE_LINEOUT);

void loop() {
  /* Do nothing */

Connect a stereo headset to the Spresense extension board 3.5 mm connector. If the microphones are properly connected you should hear audio from the microphones in the headset and be able to distinguish between the left and the right one.

Disconnect the headset and run the below program in the Arduino IDE instead:

(If you prefer, you can download the sketch from here: SPRESENSE_MULTIMIC_DETECTOR.INO )

#include <Audio.h>

#define READ_PACKET_SIZE 6144

AudioClass *audio;

/* Buffer to keep captured audio data */
char buffer[BUFFER_SIZE];

void setup() {
  audio = AudioClass::getInstance();
  /* Setup recorder to read from mic input*/
  audio->setRecorderMode(AS_SETRECDR_STS_INPUTDEVICE_MIC_A, 150);

void loop() {
  uint32_t temp;
  uint32_t left = 0;
  uint32_t right = 0;
  uint32_t read_size = 0;

  audio->readFrames(buffer, BUFFER_SIZE, &read_size);

  /* Audio channels are interleaved and each frame is two bytes (16 bits)
     like this: "LLRRLLRRLLRR...". Therefore we read 4 bytes at the time
     and handle them in pairs. */
  for (uint32_t i = 0; i < read_size; i += 4)
    temp  = (buffer[i + 1] << 8) | buffer[i];
    if (temp > left)
      left = temp;

    temp = (buffer[i + 3] << 8) | buffer[i + 2];
    if (temp > right)
      right = temp;

  /* Our simple analysis only keeps track of the highest peak value
     in each channel and uses this as an indicator of loudness. */
  if (right < left)
  else if (left < right)

The application captures audio data for both channels and does a very simple analysis to see which one is the loudest. When making some noise in one of the microphones you should now see the onboard LED indicator on the corresponding side of the board (LED number 0 or 3) light up.

Due to the simplicity of this application there is no filtering etc, so the LEDs might seem to blink a bit at random as the microphones pick up background noise.