I need to make a device that will play a wav file when a button is pushed, then go into deep sleep.
I would like to run it off of a couple coin cell batteries, and have it last for at least 4-6 weeks on standby, preferably much longer on standby. I figure I'll use a stand-alone 328. I would be using a 3.3v regulator. I could go w/enable or without, whatever makes more sense to maximize battery life.
There will be 12 different buttons to activate different sounds, arranged in a matrix array.
The mode of operation: turn unit main power switch on (this really never turns back off), 328 sees no button pressed, goes to deep sleep. When a button is pressed, 328 wakes up and plays .wav according to the button pressed then goes back to deep sleep.
Is there a way to put the matrix pins HIGH while in deep sleep and then use an interrupt pin on the 328 to trigger it to wake up when a button is pressed? I will have plenty of extra I/O pins to work with, so that should not be an issue.
The sound doesn't need to be too loud, but I want to get a small PCB mount speaker to play the sound, so I'm thinking I may need an audio amp? Standard LM386 maybe?
And for reading the SD card, I want to keep that super simple, so if I run everything 3.3v I won't need a level converter, so I can just wire it directly,correct? Like this: example
Maybe it's an option, using the DFPlayer Mini, you can use a transistor to turn the power on and off.
About reducing power consumption, the best option when using buttons is to completely turn off the power controller, you can use a transistor. When you press the button, the signal should go to the transistor and the Arduino. Then Arduino uses a pin to keep the transistor working, and you can release the button, and Arduino will stay on. After Arduino does what it should, the pin turns off the transistor so that the Arduino stops consuming completely. I already used some PNP (BC328) diodes and transistors in conjunction with a PIC12F629, and the battery charge lasted a long time.
Rat_Patrol:
The mode of operation: turn unit main power switch on (this really never turns back off), 328 sees no button pressed, goes to deep sleep. When a button is pressed, 328 wakes up and plays .wav according to the button pressed then goes back to deep sleep.
^ Setting components to sleep is an acceptable solution
I put together this video showing 5 different push button soft power latching circuits for the Arduino (works for other controllers too).
Soft Power Latching Circuits
I bread boarded each one to show how it functions and I go through the schematic to show you how they work. Each circuit has its advantages and disadvantages.
Hopefully this can be a great resource for people looking to integrate something like this into their projects.
Have the '328 in deep sleep and take over the keypad pins as an interrupt. Is there a slick way to use the keypad to wake the '328?
Find some DTDP cheap tactile switches and then have 2nd pole of every switch be battery power and go to the EN on the voltage regulator, then have the '328 take over keeping that pin high, play the sound, then put that pin low to drop power off. Burning the '328 w/o bootloader should give a fast enough boot to seem instantaneous, and I've used this method on a lot of projects. Except I've never been able to find cheap DTDP tactile switches.
Either way would work, method #2 would be better on power.
Is there a cheap way I'm not thinking of that would allow battery power to flow through the keypad keys, but then the '328 takes over those pins when not in use as to use standard tactile switches?
After downloading the Keypad2 library, it works mostly fine. If you hold down a keypad button, it will go to sleep, but not wake on that button. It will wake on press of another button though. Odd quirk, but it will do.
I was able to tie in my key switch case options for all the buttons.
When a keypad button is pressed, the '328 wakes up, switches the pins back to normal keypad mode, recognizes the key pressed, does whatever its supposed to do, finished the loop, at beginning of next loop if no button is pressed, it goes to sleep. Rinse/repeat. For the sake of userability, I added a delay after a keypad action, which effectively prevents getting stuck in sleep cycle from holding a button down (unless you hold the button down deliberately).
The SD card reader modules arrive in the mail today, will wire those up, and that should about complete the that little problem.
I just finished a remote using a 3.3V 8 MHz Pro Mini, with regulator and power LED removed, powered directly by an 18650. I used pin change interrupts on the keypad row pins, which are INPUT_PULLUP, and the column pins are OUTPUT, LOW. If any key is pressed, the interrupt wakes up the processor, and the column pins are switched to keypad mode for reading the keypress. When in power_down sleep, the current draw is something less than 0.4µA. Rather than trying to rig up the keypad to turn power on through a transistor from ANY keypress, I just leave it in power_down sleep and use any key to wake it up. There's no ON/OFF switch. If you're under half a microamp, your battery is going to last a long time.
On the other hand, I'm doing a mailbox notifier for a friend, and I'm switching the power with a transistor based on input from a magnetic reed switch. That's because a Wemos D1 Mini doesn't sleep nearly as deeply as an Arduino, and because the notifier will fire up exactly twice a day for maybe 10 seconds, and because battery replacement is not as easy, and because there's only one "key".