Sketch Only Works When USB Is Connected

Hello,
I'm a novice Arduino user and I am stumped by a project I am working on and hoping I can get some advice.

I am building an interactive map that uses an Arduino Nano, Adafruit Neopixels, and a SparkFun Qwiic Mp3 Trigger (runs on i2c). The intended interaction is a user presses a button, the corresponding Neopixels illuminate, and audio plays. My sketch is set up so that the neopixels stay illuminated for the duration of the audio event before returning to an idle state. This is accomplished by the Arduino polling the Mp3 Trigger, which is capable of returning a TRUE or FALSE state via I2C about whether or not it is playing or not playing an audio file.

This all works great as long as the a mini USB cable is plugged into the Nano. My design prefers that everything be powered with an external 5V power supply. So that's 5V to VIN on the Nano, 5V to the Neopixels, and 5V to a 3.3v regulator for the Mp3 Trigger. All grounds are shared. If I unplug the USB cable and run everything from the 5V power supply, the Mp3 Trigger seems to not respond correctly and this causes everything to fall apart (audio won't play, Neopixels won't stay lit (perhaps because there's no communication with the player )).

If I plug the mini USB cable back in, then everything operates as expected.

I realize this could be an issue with the mp3 player itself, but I thought I would check with you guys to see if there's something obvious that I could be missing.

I'll include the code in the next because it won't fit here. Here's a video of the issue: - YouTube

Thanks

5v external supply goes to 5v/Vcc pin, not Vin (aka RAW). Vin goes through the regulator, which has ~1.5v of dropout, so you'd have 3.5v or so on the "5v" pin.

//NEOPIXEL STUFF
#include <Adafruit_NeoPixel.h>
#define PIN 2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(112, PIN, NEO_RGBW + NEO_KHZ800);
int pixelQty = 112;

//MP3 STUFF
#include <Wire.h>
byte mp3Address = 0x37; //Unshifted 7-bit default address for Qwiic MP3
int mp3vol = 28; // Volume can be 0-31, 0 is mute, 31 is max

//BUTTON STUFF
int button[] = {3, 4, 5, 6, 7, 8, 9, 10, 11};  // "3" is a dummy place holder because arrays are zero indexed.
int buttonQty = 9;
int buttonState[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};

//IDLE MUSIC TIMER
unsigned long previousMillisMusic = 0;
const long MusicInterval = 75000;

//MISC SETUP
int mode = 10; // set initial startup mode to idle
int ledPin = 13; // for status LED
int ledState = LOW;  // ledState used to set the status LED
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 250; // interval at which to blink (milliseconds)
int buttonDeBounce = 100; // delay after pressing a button to.. i.e. fake debounce






void setup() {

  Serial.begin(9600);

  // set all buttons to INPUT_PULLUP
  for (int buttonPinMode = 1; buttonPinMode < buttonQty; buttonPinMode++) {
    pinMode(button[buttonPinMode], INPUT_PULLUP);
  }

Serial.println("MP3 SELF TEST");
 
delay(1000);


 
  //MP3 SELF TEST
  if (mp3IsPresent() == false)
  {
    Serial.println("Qwiic MP3 failed to respond. Please check wiring and possibly the I2C address. Freezing...");
    while (1);
  }
 
delay(500);
 
  mp3ChangeVolume(mp3vol); //Volume can be 0 (off) to 31 (max)
  Serial.print("Hello! I see ");
  Serial.print(mp3SongCount());
  Serial.print(" mp3 files on the SD card... ");
  mp3PlayFile(1); // play idle music

delay(500);

  //INIT NEOPIXELS
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'


  pinMode(ledPin, OUTPUT);
  delay(1500); // Let's pause for a moment
  Serial.println("Let's GO!");
  delay(500);
} // end setup








void loop() {

  switch (mode) {

    case 1: // ROUTE 66
      set_route66();
      strip.show();
      Serial.print(mode);
      Serial.println(" - ROUTE 66");
      mp3PlayFile(9);
      waitForMp3();
      mp3PlayFile(1);
      mode = 9; // go back to idle
      break;

    case 2: // GEMENI GIANT
      set_gemeniGiant();
      strip.show();
      Serial.print(mode);
      Serial.println(" - GEMENI GIANT");
      mp3PlayFile(2);
      waitForMp3();
      mp3PlayFile(1);
      mode = 9; // go back to idle
      break;

    case 3: // BLUE WHALE
      buildLEDs(16);
      set_blueWhale();
      strip.show();
      Serial.print(mode);
      Serial.println(" - BLUE WHALE");
      mp3PlayFile(3);
      waitForMp3();
      mp3PlayFile(1);
      mode = 9; // go back to idle
      break;

    case 4: // RAINBOW BRIDGE
      buildLEDs(32);
      set_rainbowBridge();
      strip.show();
      Serial.print(mode);
      Serial.println(" - RAINBOW BRIDGE");
      mp3PlayFile(4);
      waitForMp3();
      mp3PlayFile(1);
      mode = 9; // go back to idle
      break;

    case 5: // CADILLAC RANCH
      buildLEDs(48);
      set_cadillacRanch();
      strip.show();
      Serial.print(mode);
      Serial.println(" - CADILLAC RANCH");
      mp3PlayFile(5);
      waitForMp3();
      mp3PlayFile(1);
      mode = 9; // go back to idle
      break;

    case 6: // BLUE SWALLOW MOTEL
      buildLEDs(64);
      set_blueSwallow();
      strip.show();
      Serial.print(mode);
      Serial.println(" - BLUE SWALLOW MOTEL");
      mp3PlayFile(6);
      waitForMp3();
      mp3PlayFile(1);
      mode = 9; // go back to idle
      break;

    case 7: //WIGWAM MOTEL
      buildLEDs(80);
      set_wigwamMotel();
      strip.show();
      Serial.print(mode);
      Serial.println(" - WIGWAM MOTEL");
      mp3PlayFile(7);
      waitForMp3();
      mp3PlayFile(1);
      mode = 9; // go back to idle
      break;

    case 8: // PACIFIC PARK
      buildLEDs(96);
      set_pacificPark();
      strip.show();
      Serial.print(mode);
      Serial.println(" - PACIFIC PARK");
      mp3PlayFile(8);
      waitForMp3();
      mp3PlayFile(1);
      mode = 9; // go back to idle
      break;

    case 9: //IDLE
      set_idle();
      strip.show();
      readButtons();
      Serial.println(mode);
      imAlive();
      idleMusic();
     
      break;

    case 10:
      Serial.println("STARTUP");
      imAlive();
      neoTest(2);
      mode = 9;
      break;

  } //end switch case

} // end main loop




void readButtons() {
  buttonState[1] = digitalRead(button[1]);
  buttonState[2] = digitalRead(button[2]);
  buttonState[3] = digitalRead(button[3]);
  buttonState[4] = digitalRead(button[4]);
  buttonState[5] = digitalRead(button[5]);
  buttonState[6] = digitalRead(button[6]);
  buttonState[7] = digitalRead(button[7]);
  buttonState[8] = digitalRead(button[8]);

  if (buttonState[1] == LOW) {
    delay(buttonDeBounce);
    mode = 1;
  }
  else if
  (buttonState[2] == LOW) {
    delay(buttonDeBounce);
    mode = 2;
  }
  else if
  (buttonState[3] == LOW) {
    delay(buttonDeBounce);
    mode = 3;
  }
  else if
  (buttonState[4] == LOW) {
    delay(buttonDeBounce);
    mode = 4;
  }
  else if
  (buttonState[5] == LOW) {
    delay(buttonDeBounce);
    mode = 5;
  }
  else if
  (buttonState[6] == LOW) {
    delay(buttonDeBounce);
    mode = 6;
  }
  else if
  (buttonState[7] == LOW) {
    delay(buttonDeBounce);
    mode = 7;
  }
  else if
  (buttonState[8] == LOW) {
    delay(buttonDeBounce);
    mode = 8;
  }
} // end function

// NEOPIXEL GEMENI GIANT
void set_gemeniGiant() {
  for (int a = 0; a < 16; a++) {
    strip.setPixelColor(a, 100, 0, 0, 0);
  }
}

// NEOPIXEL BLUE WHALE
void set_blueWhale() {
  for (int b = 16; b < 32; b++) {
    strip.setPixelColor(b, 100, 0, 0, 0);
  }
}

// NEOPIXEL RAINBOW BRIDGE
void set_rainbowBridge() {
  for (int c = 32; c < 48; c++) {
    strip.setPixelColor(c, 100, 0, 0, 0);
  }
}

// NEOPIXEL CADILLAC RANCH
void set_cadillacRanch() {
  for (int d = 48; d < 64; d++) {
    strip.setPixelColor(d, 100, 0, 0, 0);
  }
}

// NEOPIXEL BLUE SWALLOW
void set_blueSwallow() {
  for (int e = 64; e < 80; e++) {
    strip.setPixelColor(e, 100, 0, 0, 0);
  }
}

// NEOPIXEL WIGWAM MOTEL
void set_wigwamMotel() {
  for (int f = 80; f < 96; f++) {
    strip.setPixelColor(f, 100, 0, 0, 0);
  }
}

// NEOPIXEL PACIFIC PARK
void set_pacificPark() {
  for (int g = 96; g < 112; g++) {
    strip.setPixelColor(g, 100, 0, 0, 0);
  }
}

// NEOPIXEL ROUTE 66
void set_route66() {
  for (int j = 0; j < 112; j++) {
    strip.setPixelColor(j, 100, 0, 0, 0);
  }
}

// NEOPIXEL IDLE
void set_idle() {
  for (int h = 0; h < 112; h++) {
    strip.setPixelColor(h, 3, 25, 0, 0);
  }
  }


// NEOPIXEL ALL OFF
void set_allOff() {
  for (int i = 0; i < 112; i++) {
    strip.setPixelColor(i, 0, 0, 0, 0);
  }
}

// MP3 STATUS
void waitForMp3() {
  while (mp3IsPlaying() == true) {
    delay(1);
  }
}

// BLINK LED 13 WHEN IDLE
void imAlive() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
    digitalWrite(ledPin, ledState);
  }
}

//PERIODICALLY PLAY MUSIC WHEN IDLE
void idleMusic() {
  unsigned long currentMillisMusic = millis();

  if (currentMillisMusic - previousMillisMusic >= MusicInterval) {
    previousMillisMusic = currentMillisMusic;
    mp3PlayFile(1); //play music
  }
}

// START UP SELF TEST RAINBOW PATTERN
void neoTest(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256; j++) {
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}


// COLOR WHEEL FOR SELF TEST
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}



int buildLEDs(int t){
  int result;
  result = t;
  for(int u = 0; u<t; u++){
    strip.setPixelColor(u, 20,115,0,0);
    strip.show();
    delay(5);
  }
}

DrAzzy:
5v external supply goes to 5v/Vcc pin, not Vin (aka RAW). Vin goes through the regulator, which has ~1.5v of dropout, so you'd have 3.5v or so on the "5v" pin.

Thank you very much. That 100% solved the problem!