SD Card Voice Recorder

Calling all Arduino SD card and microphone experts!
I drew inspiration from a youtube video for how to make a voice recorder with an arduino nano and microphone module. This project will be used as a guest book to record audio messages from guests for my wedding. The goal of the project is to hit a button to turn on an LED and start recording and then push the button again to turn the LED off and to stop the recording. The resulting recording will then be saved to the SD card. The issue is I am not sure how to reliably turn on the light and start/stop the recording and then save the new recordings under a new name efficiently without a long list of repeated code. The code I have been working with so far is below. It does record short blips of audio but the button press seems to be too unreliable to record or know when to record. All suggestions are appreciated!
<----------------------------------------------------------------------------------------------------------------------------------------->
#include "pcmConfig.h"
#include <pcmRF.h>
#include <TMRpcm.h>

/*
Steps:

  1. Edit pcmConfig.h
    a: On Uno or non-mega boards, #define buffSize 128. May need to increase.
    b: Uncomment #define ENABLE_RECORDING and #define BLOCK_COUNT 10000UL

  2. Usage is as below. See Advanced Features · TMRh20/TMRpcm Wiki · GitHub for
    additional informaiton.
    */

#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 4
TMRpcm audio;
int audiofile = 0;
unsigned long i = 0;
bool recmode = 0;

int Button_Pin = 2;

void setup() {
Serial.begin(115200);
pinMode(A0, INPUT);
pinMode(6, OUTPUT);
pinMode(2, INPUT_PULLUP);
attachInterrupt(0, button, LOW);
SD.begin(SD_ChipSelectPin);
audio.CSPin = SD_ChipSelectPin;

}

void loop() {

}

void button() {
while (i < 300000) {
i++;
}
i = 0;
if (recmode == 0) {
recmode = 1;
audiofile++;
digitalWrite(6, HIGH);

switch (audiofile) {
  case 1: audio.startRecording("1.wav", 16000, A0); 
  delay(2000);
  break;
  case 2: audio.startRecording("2.wav", 16000, A0); break;
  case 3: audio.startRecording("3.wav", 16000, A0); break;
  case 4: audio.startRecording("4.wav", 16000, A0); break;
  case 5: audio.startRecording("5.wav", 16000, A0); break;
  case 6: audio.startRecording("6.wav", 16000, A0); break;
  case 7: audio.startRecording("7.wav", 16000, A0); break;
  case 8: audio.startRecording("8.wav", 16000, A0); break;
  case 9: audio.startRecording("9.wav", 16000, A0); break;
  case 10: audio.startRecording("10.wav", 16000, A0); break;
}

}
else {
recmode = 0;
digitalWrite(6, LOW);
switch (audiofile) {
case 1: audio.stopRecording("1.wav");
delay(2000);
break;
case 2: audio.stopRecording("2.wav"); break;
case 3: audio.stopRecording("3.wav"); break;
case 4: audio.stopRecording("4.wav"); break;
case 5: audio.stopRecording("5.wav"); break;
case 6: audio.stopRecording("6.wav"); break;
case 7: audio.stopRecording("7.wav"); break;
case 8: audio.stopRecording("8.wav"); break;
case 9: audio.stopRecording("9.wav"); break;
case 10: audio.stopRecording("10.wav"); break;
}
}
}

If you expect to have a file of data on the SD card, you must open the file at the beginning of the recording and close the file at the end of the recording. Also, you need to have individual file names for each recording.

Yes! what is the best way to save files with new names without writing over the existing files?

That is what using different names and closing each file at the end does for you. EXACTLY like on your PC!

I don't think your "recordings" will be useful in any way.

Writing to SD will create big gaps in the already awful quality stream.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.