I have an arduino uno connected to a dfplayer mini and a DS3231 RTC module. Its microSD card is loaded with 13 tracks each ~6s long and is programmed as a pranking device. I have it programmed specifically to only play a random track at a random time between 7am-9am & 2pm-4pm only on Tuesdays and Thursdays. So twice at random in those time frames for those specific days. Also, it’s programmed to go into low power mode when not in use.
My original thought was to keep it portable and run it off a 9V battery, however, I plan to place this device in the ceiling tile at work so it’s not found. Originally I thought the 9V battery would keep the arduino alive for a substantial amount of time, but now I’m reading it wouldn’t last but a few days? I can easily switch it to where it’s powered by a 5V outlet power supply, but that eliminates the portability. Is it true this device wouldn’t last on a 9V battery but just a few days, if that? That would be somewhat surprising as my 9V batteries in music equipment last much longer.
For that application, and to retain portability, I’d put in either 4XAA cells, or a decent LiPo rechargeable that can provide the required current for the length of time needed.
Once assembled measurement and testing is always part of a project requirements.
All that means is that your music equipment consumes less power than your Arduino. That said, with the small operating windows and assuming some off-time between the 6 second tracks, and you practice some of the dark arts, it may be possible to get away with a 9v. This does not alter the fact that using a 9v is always a bad idea, and a properly planned power supply is hardly less portable. I single 18650 with a 5v converter might be the place to start.
Yeah I have it working. Originally was going to have this plugged in to wall adapter but decided to go the portable route first. Sounds like I’m off to a bad start, however.
It’s harmless. We have these small stamps of a small cartoon banana we randomly stamp on paperwork, as well as business cards that have the cartoon banana and says “you got NANNER’D!” on them and for months now me and and coworker have been “nannering” coworkers and they still haven’t caught us. These tracks are just 6 second clips of banana related music (e.g. hollaback girl by Gwen Stefani the ITS BANANAS B-A-N-A-N-A-S!, plus 12 other sound bites from songs). Plus I programmed to be so sparingly hopefully they don’t get annoyed and so short of tracks they can’t track the device.
Currently using SLEEP_MODE_PWR_DOWN as part of the sleep mode code. I tested it by having built in led supposed to go off when in sleep mode. It seems to be working but haven’t put a voltmeter to it to see. If it truly works, should my 9V last at least a month? lol because if not I’m going to just do the wall plug in to 5mm Jack onto board and just hide it well.
I also had it light up and stay on if in sleep mode as well bc I tried to eliminate possibility that built in just shuts off anyways. Both ways worked so I’m assuming sleep mode is working properly. I can try 4-AA’s if that would be better.
Also, I know the dfplayer is still operating while arduino is in sleep mode bc I can hear small static in the speaker. And I’m not willing to get it a separate power source and add a transistor and do extra coding just for that. The enclosure I have is already tight and need to keep it small. I’ll give the 4-AA a try, but if all else fails I’ll just use wall plug.
So I’m running into an issue. My RTC module works, battery is good etc. but my goal is to have this sucker play a random mp3 file once randomly at anytime between 7am-9am, then another random mp3 file play randomly at any time between 2pm-4pm but only on Tuesdays, Wednesdays and Thursdays.
My code is set to if those conditions are met, that a random delay begins from 0-2 hours. Is this too long of a random delay for the RTC and Uno to handle? Shouldn’t it not be a big deal?
My goal is for this thing not to be predictable bc if it is it could easily be found. This is a prank device and need it to be random and unpredictable.
#include <Wire.h>
#include <RTClib.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
SoftwareSerial mySerial(10, 11); // RX, TX for DFPlayer Mini
DFRobotDFPlayerMini player;
RTC_DS3231 rtc;
const int trackCount = 13;
const int maxPreviousTracks = 13;
int previousTracks[maxPreviousTracks];
int currentIndex;
int playsTodayMorning = 0; // Track plays in the morning time frame
int playsTodayAfternoon = 0; // Track plays in the afternoon time frame
const int maxPlaysPerDay = 1; // Allowing only one play per time frame
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
player.begin(mySerial);
player.volume(25); // Adjusted volume to 25
// Initialize RTC
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
// Uncomment the line below if you want to set the initial time of the RTC
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// Generate a random initial state for previousTracks
for (int i = 0; i < maxPreviousTracks; i++) {
previousTracks[i] = random(1, trackCount + 1);
}
currentIndex = random(maxPreviousTracks); // Set a random starting index
}
void loop() {
DateTime now = rtc.now();
// Check if it's Tuesday, Wednesday, or Thursday and within the specified time frames
if ((now.dayOfTheWeek() == 2 || now.dayOfTheWeek() == 3 || now.dayOfTheWeek() == 4) && (
(now.hour() >= 7 && now.hour() <= 9) || (now.hour() >= 14 && now.hour() <= 16)
)) {
// Check if the maximum plays for the day is not reached for the morning time frame
if (now.hour() >= 7 && now.hour() <= 9 && playsTodayMorning < maxPlaysPerDay) {
playRandomTrack();
playsTodayMorning++;
}
// Check if the maximum plays for the day is not reached for the afternoon time frame
if (now.hour() >= 14 && now.hour() <= 16 && playsTodayAfternoon < maxPlaysPerDay) {
playRandomTrack();
playsTodayAfternoon++;
}
}
// You can add a delay or other tasks here if needed
delay(1000);
}
void playRandomTrack() {
// Introduce a random delay within the specified time frames
int randomDelay = random(0, 7200000); // 0 to 2 hours in milliseconds
delay(randomDelay);
int currentTrack;
// Ensure the same track is not played consecutively
do {
currentTrack = random(1, trackCount + 1);
} while (isTrackRepeated(currentTrack));
// Play the randomly selected track
player.playMp3Folder(currentTrack);
updatePreviousTracks(currentTrack);
}
bool isTrackRepeated(int track) {
for (int i = 0; i < maxPreviousTracks; i++) {
if (previousTracks[i] == track) {
return true;
}
}
return false;
}
void updatePreviousTracks(int track) {
previousTracks[currentIndex] = track;
currentIndex = (currentIndex + 1) % maxPreviousTracks;
}
Basically just want a random track at a random time in specific windows on specific days. Also don’t want tracks to repeat at all. I want all 13 tracks to be played. Not caring what order though.