Hey all! I've been working for a while on my first Arduino project, which is a talking toy based on the DFPlayer and an Arduino Nano (clone). As I was sketching it out, I soon realized that between the two boards, the power consumption in standby would eat through a 3-4 AA/AAA battery pack in about a day, so I researched how to make the whole thing shutdown entirely after a timeout period. I found this solution on StackExchange and implemented it pretty much as it's presented there, with a 2N7000 NFET and a IRFU9024 PFET. In addition, I have two TTP233 touch button breakout boards, one that controls the latch circuit and one that goes to the Arduino to trigger the MP3 player (just want it to play a random file). The touch buttons are connected in series directly to the VCC and GND lines, being the only ones always-on. The one that controls the PFET is jumper set to connect to GND when pressed.
I worked progressively through the project, starting with jumper wires, to breadboards and, finally, a PCB testboard. This is my first electronics project ever, so my soldering is pretty bad, but I eventually managed to make it work. Sort of. I initially started with a 3 AA 1.5V battery pack, but then realised that, after all the soldering and adding the speaker, it appeared like the Arduino wasn't getting enough power, so I upgraded to 4 AAA batteries, which seems to fit all the components nicely (except the TTP233, which says no more than 5.5 V, but I figured it's safe).
The main problem is that, at every step, I would just test short timeout periods, of 10-20 seconds, and they would work ok. When I arrived at a fully soldered board, however, things started acting weird for anything more than 10 seconds, and multiple tries. Most often, as the timer expired, the boards flickered briefly and then powered back up right away. Sometimes they would shutdown after another timeout period passed, sometimes not at all (or at least not after tens of seconds, or a few minutes).
I am now trying to figure out if this is a software problem, or a hardware one. As far as hardware goes, the only thing I can think of is that the TTP233 buttons somehow interfere with the latch circuit. I didn't use a resistor between the on/off one and the PFET, for instance. This is the code I use (sorry if it's not formatted right, new here):
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 9); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
const int powerPin = 2;
const int button = 3;
int playstate = 0;
const unsigned long timeout = 60000;
unsigned long startMillis;
unsigned long currentMillis;
void setup()
{
pinMode(powerPin, OUTPUT);
digitalWrite(powerPin, HIGH);
mySoftwareSerial.begin(9600);
Serial.begin(115200);
pinMode(button, INPUT);
pinMode(13, OUTPUT);
myDFPlayer.begin(mySoftwareSerial);
myDFPlayer.setTimeOut(2000);
myDFPlayer.volume(10);
startMillis = millis();
}
void loop()
{
currentMillis = millis();
if (currentMillis - startMillis > timeout) {
digitalWrite(powerPin, LOW);
delay(5000);}
int nextplay = random(0, 14);
playstate = digitalRead(button);
if(playstate == HIGH) {
myDFPlayer.play(nextplay);
delay(3000);
}
}