Battery w/ Arduino Question

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.

1 Like

Pranks at work and the corresponding actions might cause you bigger problems than battery life …

Man carrying object > words from ceiling > drops item on foot > you get fired .

If messages are abusive , then it can count as harassment .

Do something more positive and useful !!

.

You received help from us on how to get this project working in your earlier post, but we heard no more from you. I assume you now do have it working?

Are 9V’s a bad idea simply because they don’t last long or are there other concerns?

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.

You're fired.

Srsly, 4 AA batteries will last forever if you can achieve true and deep sleep when the device is "off".

Have you measured the current when the device is "off"?

Have you come across, understood and followed every bit of advice found here?

The only way to find and eliminate the last few dozens of microamperes and be confident that you have done is to measure the sleeping current.

a7

1 Like

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.

I feel you. Chasing the last little bits of current is a task, and perhaps an obsession.

If there is any significant current being drawn, a 9 volt smoke alarm battery will not last very long.

The AAs might last for some good time, but if you can, just forget all about sleep and plug the thing in , boom! done.

a7

Ugh, you’re right :pensive: haha I’m thinking that’s what I might just do and simplify code also.

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?

Sounds easy. Please post your code we have a look.

I would make a random time, and play it at that time. Constrain the random time chosen to the hours of interest.

There is no need to time out the randomness using any other means like seeing 7 o'clock and delaying a random period.

There's a few other threads going right now about how to do things when.

i'll look.

a7

1 Like

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;
}

Here's on, there's another not turning up yet

Here it is

HTH

a7

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.