I have a Nano project that works fine when powered from the usb port but I can't seem to find a battery that will work. My latest attempt is two 4000mah batteries in series connected to the vin/ground pins.
The project includes a dfplayermini mp3 player, an hw-104 amp and a hall effect sensor. when powered from the usb port it makes a sound only when the hall effect sensor is triggered. When powered from the battery is seems to be stuck in some kind of loop in setup, never getting to the main loop. it just repeatedly make a short squeak from the speakers.
code:
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
// Use pins 2 and 3 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX
static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
// Create the Player object
DFRobotDFPlayerMini player;
int hall_pin = 6;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(hall_pin, INPUT);
// Init serial port for DFPlayer Mini
softwareSerial.begin(9600);
// Start communication with DFPlayer Mini
if (player.begin(softwareSerial)) {
// Set volume to maximum (0 to 30).
player.volume(20);
}
}
void loop() {
if (!digitalRead(hall_pin)){
player.playMp3Folder(1); delay(1000);
player.playMp3Folder(2);delay(1000);
player.playMp3Folder(3); delay(1000);
}
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}
I'll work on a wiring diagram but I believe all the grounds are correctly connected since it works with the power from the USB port.
I removed the amp and used just one speaker on the mini player and it works correctly.
I'm guessing that the batteries can't supply sufficient amps to run all thee components or more likely that the 5v pin on the Nano can't supply the required amps?
Using the DAC outputs make sense. I'll make that change.
I was starting to realize that the problem was with the internal regulator and am planning on rewiring to run independently from a external regulator powered by the battery.
I realize the speakers are small. they're just for testing. I'm planning on replacing them with larger speakers when I have things working. I want to make a flying ghost Halloween prop and intend to imbed the project in the ghost's head. That's what the hall effect sensor is for, to trigger the sounds when the head starts moving.
Thanks everyone for your comments and help. I've seperated all of the components so they're powered independantly instead of all powered from the 5v pin on the nano. Also changed the inputs for the amp to use the DAC outputs on the mini player. Everything is working now.