I've searched the forum for similar problems and still can't see my obvious issue. I'm working on a simple Halloween prop and I'm using an Arduino for the first time. I've tested each individual 'event' (i.e. fog machine, mp3, actuator, and LED strip) with a loop and all four have worked on continuous loop with no issue.

As soon as I combine them all together, the program runs successfully exactly one time. After that final 10 second delay, when I expect the program to start the loop again, it crashes. If it helps, right during the start of the next loop, the relay light turns on on the relay board for RELAY_1_A and sort of just flickers while the actuator hums. I usually shut it down quickly at this point. As soon as I turn the system back on, it successfully runs through another iteration until the loop hangs.

I'm happy to provide pictures or even a video of the issue if that helps. My guess is that you guys will spot my coding issue right away. Maybe some kind of memory overflow or something like that.

I know my code could be much more efficient but I'm just looking for the glaring problem that is keeping the loop from working.

#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h> 
#include <SFEMP3Shield.h>

const int RELAY_1_A = 7; //the one with the issue
const int RELAY_1_B = 8;

SdFat sd;
SFEMP3Shield MP3player;
void setup() {                
  // initialize the digital pins as an output.
  pinMode(10, OUTPUT); //Fog machine on Relay1 on 5V relay board
  pinMode(3, OUTPUT); //LED strip off breadboard MOSFET  
   pinMode(RELAY_1_A, OUTPUT); //12V relay for actuator on Relay1 on 12V relay board
   pinMode(RELAY_1_B, OUTPUT); //12V relay for actuator on Relay2 on 12V relay board

  //start the shield
  sd.begin(SD_SEL, SPI_FULL_SPEED);
  MP3player.setVolume(10, 10);

void loop() {
  MP3player.playTrack(2);  // Play MP3. Track 1 is coffin and track 2 is bird
  delay(5000);              // wait for 5 seconds
  digitalWrite(10, LOW);   // Turns ON fog machine
  digitalWrite(10, HIGH);   // Turns OFF fog machine 
  digitalWrite(3, HIGH);   // Turn the LED on (HIGH is the voltage level)

  delay(5000);              // wait for 5 seconds

  retractActuator();       //Open coffin
  delay (9000);
  stopActuator();      //Close coffin
  delay (9000);
  extendActuator();      //Close coffin
  digitalWrite(RELAY_1_B, HIGH);  //Turns off this relay during the wait period before next loop

  digitalWrite(3, LOW);    // Turn the LED off by making the voltage LOW
  delay(10000);              // wait for 20 seconds

void extendActuator() {
  //Set one relay one and the other off
  //this will move extend the actuator
  digitalWrite(RELAY_1_A, HIGH);
  digitalWrite(RELAY_1_B, LOW);

void retractActuator() { 
  //Set one relay off and the other on 
  //this will move retract the actuator 
  digitalWrite(RELAY_1_A, LOW);
  digitalWrite(RELAY_1_B, HIGH); 

void stopActuator() {
 //Set both relays off
 //this will stop the actuator in a braking
 digitalWrite(RELAY_1_A, HIGH);
 digitalWrite(RELAY_1_B, HIGH); }
  • My guess is you have a pin conflict between your MP3 shield and your relays. Looking at the MP3 library my guess is pin 7.
    – Majenko
    Commented Sep 12, 2015 at 13:05
  • 1
    Majenko thank you so much! Absolutely incredible. You solved my issue less than an hour after I posted it. You response made me look up the schematic for the Sparkfun MP3 Shield and it turns out that shield hogs tons of pins which can't be used. In fact, only 0,1,5, and 10 can be used. As soon as I switched the 2 relays to 0 and 1, everything worked perfectly. Thank you so much again! Commented Sep 12, 2015 at 14:06
  • Excellent. I'll craft that as an answer then.
    – Majenko
    Commented Sep 12, 2015 at 14:38

1 Answer 1


You are attempting to use IO pins that are already in use by the MP3 shield.

According to your subsequent research, only digital pins 0,1,5, and 10 are available for use.

You should shy away from using pins 0 and 1 since they are also connected to the computer through the USB interface and are used for uploading sketches. You will find that either you can't upload sketches with the relays connected to those pins, or the relays will "randomly" switch on and off while you're uploading a sketch.

Don't forget that the analog pins A0-A5 can also be used as digital pins, so you can quite happily drive your relays using any of those.

  • -Majenko, I hope you will appreciate this communication tip. It is much more effective to say "Remember to ..." rather than "Don't forget to ...".
    – linhartr22
    Commented Sep 17, 2015 at 19:51
  • 2
    @linhartr22 Not for a native English speaker. "Don't forget..." is far more common than "Remember...".
    – Majenko
    Commented Sep 17, 2015 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.