Hi
I am trying to record a voice pattern (Frequency) using the MKRZero's onboard SD card while a button is pressed. After recording the voice pattern I am trying to re-open the file and compare it to an incoming voice pattern that does not require the button to be pressed within a specified period, this will be done once a "CallSign" is said (this part is done on a different board and works). The main thing I am trying to accomplish right now is storing and re-opening the file. I tried using the sound sensor module, but the maximum distance is only 1 foot, I need it to be at least 5 feet, is there someway that I can increase the distance of the sound sensor module. I also tried using a PC microphone going through an OP Amp non-inverting amplifier (741). I can get signal using the sound sensor module, but the distance is too short, and I am having issues with the OP Amp configuration [ Vout=[1+(22K/22K)]x2.5V] with a gain of 2. I am applying +/- 9V to the OP Amp.
Here is my code for capturing the voice print:
Code :
/*
SPI CONNECTIONS FOR MKRZero
MOSI: pin 8
MISO: pin 10
SCK: pin 9
SS: SDCARD_SS_PIN
*/
#include <SPI.h>
#include <SD.h>
const int chipSelect = SDCARD_SS_PIN;
int loadDataCheck;
const int soundSensorPin = A6;
int sound;
int threshold = 820;
int ledPin = 7;
int pbPin = 6;
int getOut=0;
void logData(void);
void dataCheck(void);
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
digitalWrite(chipSelect, LOW);
pinMode(ledPin, OUTPUT);
pinMode(ledPin, HIGH);
pinMode(soundSensorPin, INPUT);
pinMode(pbPin, INPUT);
pinMode(pbPin, HIGH);
pinMode(soundSensorPin, HIGH);
SD.mkdir("newSample.txt");
recognitionTest;
dataCheck;
logData;
while (!Serial)
{
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
loadDataCheck = 0;
digitalWrite(ledPin, LOW);
digitalWrite(chipSelect, HIGH);
}
void loop()
{
while (getOut == 0)
{
while (digitalRead(pbPin) == LOW)
{
if (loadDataCheck) logData();
}
return;
getOut = 1;
}
}
void dataCheck(void)
{
loadDataCheck = 1;
}
void recognitionTest(void)
{
// make a string for assembling the data to log:
while (getOut == 0)
{unsigned long dataString = sound;
if(sound>threshold)
{
sound = analogRead(soundSensorPin);
Serial.println(dataString);
}
getOut=1;
}
}
void logData(void)
{ digitalWrite(chipSelect, LOW);
while (getOut == 0)
{
unsigned long dataString = sound;
dataString =analogRead(soundSensorPin);
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File myFile = SD.open("newSample.txt", FILE_WRITE);
// if the file is available, write to it:
if (myFile) {
digitalWrite(ledPin, LOW);
myFile.println(dataString);
myFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
getOut = 1;
return;
}
}
