Hello!
I've been working on a project where an RF transmitter would send a codeword to an RF receiver -- if the codeword is correct, the Arduino Mega connected to the receiver would play a .wav audio file stored on a connected SD card module via the TMRpcm library.
So far, I have been able to get the Arduino Mega to play the audio one time (after the first instance of the correct keyword being sent), but the speaker falls quiet after this first playthrough, and the Mega no longer appears to receive/react to RF signals, nor does the audio play at all after that.
Here are the connections on the Mega:
- 3V => connected to VCC LM386 Mono Audio Amplifier and Micro SD TF Card adapter
- 5V => connected to VCC of 433M Transmitter
- PWM 11 => connected to data pin of 433M Transmitter
- PWM 5 => connected to IN pin of LM386 Mono Audio Amplifier
- All other connections for the SD card have been checked and verified to be correct, and the SD card successfully loads every time
Here is the code itself:
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
#include <SD.h>
#define SD_ChipSelectPin 53
#include <TMRpcm.h>
#include <SPI.h>
RH_ASK driver;
TMRpcm tmrpcm;
void setup()
{
tmrpcm.speakerPin = 5; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}
else
{
Serial.println("SD connected");
}
Serial.println("Connected!");
tmrpcm.setVolume(5);
}
bool playAudio = false;
void loop()
{
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
driver.waitAvailable();
if (driver.recv((uint8_t *) &buf, &buflen))
{
Serial.println((char*)buf);
if (strcmp((char*)buf, "hello there") == 0)
{
playAudio = true;
}
else
{
Serial.println("Did not receive correct keyword");
}
}
if (!tmrpcm.isPlaying() && playAudio)
{
tmrpcm.play("bell.wav") // Play audio file asynchronously
playAudio = false; // Reset flag after starting playback
}
delay(100);
}
Any help would be greatly appreciated! I've been at this for a while and can't seem to find any solutions.
This is also my first time posting on the Arduino Forum, so any tips on how to make my post(s) more approachable/digestible would also be helpful.
Thank you!!