I want to make a sound recorder circuit with Arduino. The materials I have are Arduino Uno, mini speaker, ISD1820, SD card module, and a switch button.
My project idea is as follows: When the switch button is pressed, it will wait for 1 second, then play a warning sound from the speaker, and start recording. When I release the switch, the recording will stop and be saved as a sound file on the SD card.
I've tried many times. Right now, I can save it as a sound file, but it comes as 0kb empty. When I try with a text file, it works as expected. However, I can't get it as a sound file
Show the latest, working sketch.
Of course,
-
I wanted to make the structure comprehensive. However, here the key doesn't engage passively in any way. There's no sound warning from the speakers. Only the recording LED on the ISD1820 lights up for 10 seconds by itself. I can't receive any notification on the serial monitor.
-
The structure is simpler. I just wanted to check if I can record a sound file. A sound file is created. However, its size is 0kb.
Code 1
#include <SD.h>
#include <SPI.h>
#define SWITCH_PIN 2 // Digital pin connected to the switch
#define SPEAKER_PIN 4 // Digital pin connected to the buzzer
#define RECORD_PIN 3 // Arduino pin connected to the REC pin of ISD1820
#define SD_CS_PIN 10 // CS pin of the Micro SD card adapter
File myFile;
bool recordingStarted = false; // Recording state
bool previousState = LOW; // Previous state of the switch
unsigned long debounceTime = 0; // Timekeeper for switch debouncing
unsigned long debounceDelay = 50; // Debounce delay (in microseconds)
void setup() {
pinMode(SWITCH_PIN, INPUT);
pinMode(SPEAKER_PIN, OUTPUT);
pinMode(RECORD_PIN, OUTPUT);
digitalWrite(RECORD_PIN, LOW); // Set the recording circuit to off state at the beginning
Serial.begin(9600);
// Initialize the SD card
if (!SD.begin(SD_CS_PIN)) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("SD card initialized.");
}
void loop() {
// Read the state of the switch and apply debouncing
int switchState = digitalRead(SWITCH_PIN);
if (switchState != previousState) {
debounceTime = millis();
}
if ((millis() - debounceTime) > debounceDelay) {
// Compare the current state of the switch with its previous state
if (switchState == HIGH && previousState == LOW) {
// Play alert sound
tone(SPEAKER_PIN, 1000); // Play sound at 1000 Hz frequency
Serial.println("Alert sound is playing...");
// Start the recording process
digitalWrite(RECORD_PIN, HIGH); // Set REC pin to high
Serial.println("Recording process started...");
recordingStarted = true; // Update recording state
}
// When the switch is released and recording has started
if (switchState == LOW && previousState == HIGH && recordingStarted) {
// Finish the recording process
digitalWrite(RECORD_PIN, LOW); // Set REC pin to low
Serial.println("Recording process completed.");
// Save to SD card
saveToSDCard();
recordingStarted = false; // Reset recording state
}
// Update the previous state of the switch
previousState = switchState;
}
}
void saveToSDCard() {
// Generate the file name (Example: record_19-04-2024_12-34-56.wav)
String fileName = "record_" + getCurrentDateTime() + ".wav";
// Create the file
myFile = SD.open(fileName, FILE_WRITE);
// Write data to the file
if (myFile) {
Serial.println("Writing to file...");
myFile.println("This file is saved onto the SD card.");
myFile.close();
Serial.println("File successfully saved: " + fileName);
} else {
Serial.println("File creation failed!");
}
}
String getCurrentDateTime() {
unsigned long currentTime = millis(); // Calculate elapsed time
int seconds = currentTime / 1000 % 60; // Seconds
int minutes = (currentTime / (1000 * 60)) % 60; // Minutes
int hours = (currentTime / (1000 * 60 * 60)) % 24; // Hours
// Format the time
String dateTime = "";
dateTime += (hours < 10 ? "0" : "") + String(hours) + "-";
dateTime += (minutes < 10 ? "0" : "") + String(minutes) + "-";
dateTime += (seconds < 10 ? "0" : "") + String(seconds);
return dateTime;
}
Code 2
#include <SD.h>
#define SWITCH_PIN 2 // Digital pin connected to the switch
#define RECORD_PIN 3 // Arduino pin connected to the REC pin of ISD1820
#define SD_CS_PIN 10 // CS pin of the Micro SD card adapter
File myFile; // SD card file object
bool isRecording = false; // Flag to monitor the recording state
void setup() {
Serial.begin(9600); // Initialize serial connection
pinMode(SWITCH_PIN, INPUT_PULLUP); // Set the switch pin as input and enable internal pull-up resistor
pinMode(RECORD_PIN, OUTPUT); // Set the record pin as output
// Initialize the SD card
if (!SD.begin(SD_CS_PIN)) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("Press the switch to start recording...");
}
void loop() {
// Start recording when the switch is pressed
if (digitalRead(SWITCH_PIN) == LOW && !isRecording) {
Serial.println("Recording started...");
digitalWrite(RECORD_PIN, HIGH); // Activate the record pin
isRecording = true; // Mark recording state
}
// Stop recording when the switch is released
if (digitalRead(SWITCH_PIN) == HIGH && isRecording) {
Serial.println("Recording stopped...");
digitalWrite(RECORD_PIN, LOW); // Deactivate the record pin
isRecording = false; // Reset recording state
Serial.println("Sound file saved to the SD card!");
}
}
I find no way of accessing the data held inside the ISD1820.
I couldn’t find a way either. So, how can I record sound with Arduino? Do I need to buy another module?
Read about the MAX9814 using Arduino to store audio to SDcard.
I found this example (untested) Simple Arduino Voice Recorder for Spy Bug Voice Recording
Hello, I've built the circuit similar to the one in the video. However, I'm using Arduino Uno instead of Arduino Nano. But I'm getting the following error. How can I fix it, in your opinion?
C:\Users\Armagan\AppData\Local\Temp\.arduinoIDE-unsaved2024324-29144-1lexgwr.fyer\sketch_apr24a\sketch_apr24a.ino: In function 'void startRecording(const char*, int)':
C:\Users\Armagan\AppData\Local\Temp\.arduinoIDE-unsaved2024324-29144-1lexgwr.fyer\sketch_apr24a\sketch_apr24a.ino:51:11: error: 'class TMRpcm' has no member named 'addRecordingData'
audio.addRecordingData(val);
^~~~~~~~~~~~~~~~
C:\Users\Armagan\AppData\Local\Temp\.arduinoIDE-unsaved2024324-29144-1lexgwr.fyer\sketch_apr24a\sketch_apr24a.ino:55:9: error: 'class TMRpcm' has no member named 'stopRecording'
audio.stopRecording();
^~~~~~~~~~~~~
Multiple libraries were found for "SD.h"
Used: C:\Users\Armagan\Documents\Arduino\libraries\SD
Not used: C:\Users\Armagan\AppData\Local\Arduino15\libraries\SD
exit status 1
Compilation error: 'class TMRpcm' has no member named 'addRecordingData'
Uno and Nano will work the same.
You have more than one SD.h libraries. Remove them SD.h libraries and re-install only one.
In fact, I only have one SD card installed. I removed it and still get this error
C:\Users\Armagan\Documents\Arduino\test-ayse\test-ayse.ino: In function 'void loop()':
C:\Users\Armagan\Documents\Arduino\test-ayse\test-ayse.ino:64:9: error: 'class TMRpcm' has no member named 'startRecording'
audio.startRecording(file_name, sample_rate, mic_pin);
^~~~~~~~~~~~~~
C:\Users\Armagan\Documents\Arduino\test-ayse\test-ayse.ino:71:9: error: 'class TMRpcm' has no member named 'stopRecording'
audio.stopRecording(file_name);
^~~~~~~~~~~~~
exit status 1
Compilation error: 'class TMRpcm' has no member named 'startRecording'
Libraries.
There may be an error in the code, probably a semicolon or a misplaced or missing curly brace, because TMRpcm does have the functions that the compiler says do not exist.
How to connect in commucate to human to robot normal speaking isd1820 and sd card connection and code sir
@1233velan
Do not hijack topics.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.