gilshultz:
Check your grounds. Try a different power supply, a bit bigger if possible. Try lowering the volume.
It may be caused by your code. See if you are turning on or off something at approximately this interval. It probably will be an inductive load but not guaranteed. You can try disconnecting one speaker at a time.
I'm using a pc power supply to power the project, I am powering the Dfplayer mini and Nano off of the same 5v lead.
I disconnected one speaker at a time and I seamed to stop for a bit, but then started up. I had one speaker working or at least I thought i did where the one speaker was fine, and then when I plugged in the other it would start, I then moved the connections and it is happening on both connections. using only one speaker channel does not seam to work.
I don't think its the sketch as it was not happening before I switched to the prototype board. Even when i used the pc power supply to power the project in place while it was still on the bread board.
Here is the sketch tho:
const int buttonPin2 = 4; // Home IR
const int buttonPin3 = 2; // Away IR
const int buttonPin4 = 3; // End Game Horn from Scoreboard
const int ledPin1 = 8; // Home Led
const int ledPin2 = 12; // Away Led
const int ledPin3 = 5; // Horn status "End Game LED 1"
const int ledPin4 = 6; // Horn status "End Game LED 2"
int buttonState2 = 0; // variable for reading the pushbutton status
int buttonState3 = 0; // variable for reading the pushbutton status
int buttonState4 = 0; // variable for reading the pushbutton status
#include <SoftwareSerial.h>
#include <DFMiniMp3.h>
// implement a notification class,
// its member methods will get called
//
class Mp3Notify
{
public:
static void PrintlnSourceAction(DfMp3_PlaySources source, const char* action)
{
if (source & DfMp3_PlaySources_Sd)
{
Serial.print("SD Card, ");
}
if (source & DfMp3_PlaySources_Usb)
{
Serial.print("USB Disk, ");
}
if (source & DfMp3_PlaySources_Flash)
{
Serial.print("Flash, ");
}
Serial.println(action);
}
static void OnError(uint16_t errorCode)
{
// see DfMp3_Error for code meaning
Serial.println();
Serial.print("Com Error ");
Serial.println(errorCode);
}
static void OnPlayFinished(DfMp3_PlaySources source, uint16_t track)
{
Serial.print("Play finished for #");
Serial.println(track);
}
static void OnPlaySourceOnline(DfMp3_PlaySources source)
{
PrintlnSourceAction(source, "online");
}
static void OnPlaySourceInserted(DfMp3_PlaySources source)
{
PrintlnSourceAction(source, "inserted");
}
static void OnPlaySourceRemoved(DfMp3_PlaySources source)
{
PrintlnSourceAction(source, "removed");
}
};
// instance a DFMiniMp3 object,
// defined with the above notification class and the hardware serial class
//
//DFMiniMp3<HardwareSerial, Mp3Notify> mp3(Serial1);
// Some arduino boards only have one hardware serial port, so a software serial port is needed instead.
// comment out the above definition and uncomment these lines
SoftwareSerial secondarySerial(10, 11); // RX, TX
DFMiniMp3<SoftwareSerial, Mp3Notify> mp3(secondarySerial);
void setup()
{
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT);
Serial.begin(9600);
Serial.println("initializing...");
mp3.begin();
uint16_t volume = mp3.getVolume();
Serial.print("volume ");
Serial.println(volume);
mp3.setVolume(30);
uint16_t count = mp3.getTotalTrackCount(DfMp3_PlaySource_Sd);
Serial.print("files ");
Serial.println(count);
Serial.println("starting...");
//play startup track
Serial.println("track 3");
mp3.playMp3FolderTrack(3); // sd:/mp3/0003.mp3
delay(5000);
}
void waitMilliseconds(uint16_t msWait)
{
uint32_t start = millis();
while ((millis() - start) < msWait)
{
// calling mp3.loop() periodically allows for notifications
// to be handled without interrupts
mp3.loop();
delay(1);
}
}
void loop()
{
//read the pushbutton value into a variable
int sensorVal = digitalRead(2);
//print out the value of the pushbutton
Serial.println(sensorVal);
// read the state of the pushbutton value:
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
// HOME check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState2 == LOW) {
//turn LED on:
digitalWrite(ledPin1, HIGH);
// play track 1:
Serial.println("track 1");
mp3.playMp3FolderTrack(1); // sd:/mp3/0001.mp3
delay(9000);
} else {
// turn LED off:
digitalWrite(ledPin1, LOW);
}
// AWAY check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState3 == LOW) {
// turn LED on:
digitalWrite(ledPin2, HIGH);
// play track 2:
Serial.println("track 2");
mp3.playMp3FolderTrack(2); // sd:/mp3/0002.mp3
delay(9000);
} else {
// turn LED off:
digitalWrite(ledPin2, LOW);
}
// End Game horn via. Scoreboard clock.
if (buttonState4 == HIGH) {
// turn LED on:
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
// play track 2:
Serial.println("track 4");
mp3.playMp3FolderTrack(4); // sd:/mp3/0004.mp3
delay(9000);
} else {
// turn LED off:
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
}
}