Hello Arduino Community,
I hope everyone is doing well. I'm currently facing an issue with integrating Blynk and an MP3 player on my Arduino project, and I could really use some assistance.
Here's the setup: I have an Arduino Uno board connected to a SIM800 GSM modem for internet connectivity. I'm using the Blynk platform for remote control of the Arduino, and I've also incorporated an MP3 player module (specifically the MP3_TF module) for playing audio tracks based on user commands.
The problem arises when I try to trigger the MP3 player to play a track via a Blynk button. While everything works fine individually (the MP3 player plays tracks when directly triggered from the Arduino sketch, and Blynk controls the Arduino effectively), there seems to be a conflict when I attempt to trigger the MP3 player from a Blynk button press.
Here's a brief overview of my setup:
- Arduino Uno connected to a SIM800 GSM modem for internet connectivity.
- Blynk app controlling the Arduino's GPIO pins.
- MP3_TF module connected to the Arduino for audio playback.
I've tried debugging the issue, and it seems that when the Blynk button triggers the MP3 player function, it causes the code to freeze or hang, preventing further execution.
It all works up to the point of playing the sound, which it does and then it just can't move past that point.
Here's the code:
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
/* Fill in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPL5lhTVjbnb"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "W_Zv9MSFxztFJXj9D1SupiCBNARaypfh"
// Select your modem:
#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
// SETUP THE MP3
#include "mp3tf16p.h"
MP3Player mp3(8, 9); // Ensure these pins do not conflict with other hardware
// Your GPRS credentials
char apn[] = "everywhere";
char user[] = "eesecure";
char pass[] = "secure";
// Hardware Serial on Uno, Nano (define SerialAT Serial1)
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
// Define pin_relay1
#define pin_relay1 10
int state_relay1 = 0;
#define virtual_pin1 V1
BLYNK_WRITE(virtual_pin1) {
state_relay1 = param.asInt();
digitalWrite(pin_relay1, state_relay1);
if (state_relay1 == 1) {
// If relay is turned on
Serial.println("Relay ON");
// Add more debug statements
Serial.println("About to play MP3");
mp3.playTrackNumber(2, 25);
delay(10);
pinMode(pin_relay1, OUTPUT);
digitalWrite(pin_relay1, LOW);
Serial.println("MP3 playback initiated"); // To check if the code has frozen
} else {
// If relay is turned off
Serial.println("Relay OFF");
}
}
TinyGsm modem(SerialAT);
void setup() {
// Debug console
Serial.begin(9600);
// Initialize MP3 player
Serial.println("Initializing MP3 Player...");
mp3.initialize();
Serial.println("MP3 Player Initialized");
mp3.playTrackNumber(2, 25);
delay(10);
pinMode(pin_relay1, OUTPUT);
digitalWrite(pin_relay1, LOW);
// Set GSM module baud rate
SerialAT.begin(9600);
delay(3000);
// Restart modem
Serial.println("Initializing modem...");
modem.restart();
// Blynk connection
Blynk.begin(BLYNK_AUTH_TOKEN, modem, apn, user, pass);
}
void loop() {
Blynk.run();
}