Is this possible with arduino?

Hello,

I apologize in advance for any community gaffs or mistakes, as I have very little familiarity with this forum and arduino in general.

I am going to describe a device I would like to create, and I am hoping that someone can tell me if it is possible with arduino tech. If it is possible i will begin educating myself on how to do it. I have been trying to figure this out myself without any success, and i really don't want to invest many hours of learning how to construct arduino devices only to find out what I want to do isn't possible or practical.

I need to create a device that can have the time of day set onboard without access to a computer, then use that information to play a sound file at a decent volume at scheduled intervals. It will be turned off during the majority of the daylight hours (determined by a clock not a photocell), and be programmed to begin playing a sound at a scheduled time that can be set on the unit in the field, not preprogrammed on a computer. The sound will then play for 10-15 seconds then pause for around a minute, and repeat this pattern until turned off by the system at a time selected by the user to resume again that evening.

The device needs to run off a large battery (I have been using 12ah 12 AGM batteries) , that will allow the device to run for perhaps a week without a battery change. Previous devices i have made to do this task using photocells and manual irrigation timer show that having the device sleep during periods of inactivity is critical to getting sufficient battery life.

Is this something that can be done? I very nich appreciate any help or insight you might be able to offer. I am sure will be able to learn the syntax i need to do the programming, but i dont want to invest the time if this device isnt possible. Thank You.

of course
for getting time there are RTC modules.
for playing a sound - MP3 module
for storing file (Micro) SD card module
for setting up away from PC you my attach a DIP switch
arduino itself can be powered from 12V, but for other modules better use stepdown converter

Hello dmr400

Welcome to the best Arduino forum ever :slight_smile:

You can start with a block diagram of your project to identify the hardware to be used.

In the next step, you can run the associated tutorials and then combine the results into an overall project using control functions.

The local user interface will be the most challenging, no matter which way you want to go, an LCD + keypad will make it easier for the user, a little more challenging for the developer (you).

ThE RTC and timing / playback are fairly straightforward.

Build & program each element so they work individually, - and you understand why they work, then you can join all the pieces together,.

It will NOT work if you try to do everything at once !

+1, and it can be stopped for the time when user not there

As you progress with the hardware draw an annotated schematic. This will be handy when asking questions and getting accurate answers. A few years in the future when something needs adjusting you will be happy you have the schematic.

What is a schematic What Is a Schematic Diagram?
How to Read a Schematic - SparkFun Learn
HOW to READ a Schematic: https://www.youtube.com/watch?v=9cps7Q_IrX0&t=15s

or even

I'd suggest the easiest way to keep it simple will be to drive say 128 x 64 OLED to display the current time and start time, and then use a hardwired pushbutton or two that increment / decrement the time settings each time you press them. All pretty easy to program with simple boolean and integer logic and an OLED display library like u8g2 / u8x8.

It won't be super sophisticated but you have got enough to worry about with all the other stuff. save your time and energy for that.

..and give away half your memory for fonts and drivers ?

Is it possible with Arduino? Yes.

The word "arduino" does a lot of heavy lifting these days. It can mean a lot. If you use, e.g., the original Arduino Uno or Nano, then you can do it with a bunch of peripheral devices and some wiring.

If you use instead, an "arduino compatible" device like an M5Stack Core, you can do all that you want in a single device: it even has a built-in speaker. You would program this in pretty much the same way that you would the Uno.

It's for reasons like this that I rarely start new projects with Uno or Nano, or anything AVR-based these days. The capabilities of new silicon far outweigh what the original Arduino was.

It's not 2007 anymore. We have modern Arduinos that can do that without breaking a sweat.

Here's a sketch that plays songs from a SD card onboard an Arduino MKR Zero, pumps it out as Line Out to an audio amp, and shows the track name on the OLED display. All the OP would need is the MKR Zero, an SD card to go in it, an OLED display, a couple of pushbuttons and the audio amp.

Obviously reprogram the display to show the time instead of the track name.

It uses the grand total of 10% of program storage space and 15% of dynamic memory.

/* This sketch plays a selection of .wav files on an audio amp and speaker
* connected to the DAC on A0, using the Simple Audio Player library
* The .wav files are stored on a SD card.
* The user can select the track to be played using the BUTTON input.
* The song name is displayed on an I2C OLED dispay using the U8g2 library.
* Can use Audacity to open mp3s and use the Tracks > mix stereo down to mono function.
* Then export the resulting mono track as .wav, 88200 kHz, unsigned 8 bit PCM and save to SD.
*/


#define CHIPSELECT 4       // SD card chip select on D4
#define LED 5              // yellow LED on D5
#define BUZZER 7           // piezo buzzer on D7
#define BUTTON A4          // momentary pushbutton on A4 (N/O, grounded on press)
#define STARTTIME 30       // duration of track selection time window in sec
#define NUMSONGS 30        // number of songs on SD card
#include <SD.h>
#include <SPI.h>
#include <AudioZero.h>
#include <U8g2lib.h>
#include <Wire.h>
#include "tracklist.h"     // variable declarations and song filenames are in there.

U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // instantiate the OLED display class

void setup() {
  u8g2.begin();                   // start the OLED display    
  pinMode (BUTTON, INPUT_PULLUP); // song select button is N/O, grounded on press
  Serial.begin(9600);             // serial for error messages
  delay(2000);                    // delay to get serial monitor visible

  // setup SD-card
  Serial.print("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.println(" failed!");
    while (true)
      ;
  }
  Serial.println(" done.");
  selectTimer = millis();
  songRequest = 1;                // Songs in list are numbered 1 to NUMSONGS
}
// User is given STARTTIME seconds to press the track select button.
// The number of presses is counted and the corresponding numbered track is played.

void loop() {
  if ((millis() - selectTimer) < STARTTIME * 1000){  // User input period to allow song selection
    button = digitalRead(BUTTON);
    OSFall = (!button && OSFSetup);                  // OSFall goes true for one scan. User must repeatedly press 
    OSFSetup = button;                               // and not just hold down BUTTON to advance through tracks
    delay (100);                                     // use of delay acceptable to debounce BUTTON here as we are waiting for user input
  if (OSFall){songRequest++;}                        // song request numbered 1 to NUMSONGS
  if (songRequest > NUMSONGS) {songRequest = 1;}     // cycle song request counter back to first song after NUMSONGS button presses
  Serial.println (songRequest);
  displaySong (songNameArray[songRequest-1], 13);    // display currently selected song name on OLED display. Refer to header file for file list
  }
  else {                                             // play the selected track when timer has expired    
    playSong(songNameArray[songRequest-1], 13);      // playSong function does not return until song is complete
    selectTimer = millis();                          // After song is complete, restart the track selection window timer
    songRequest++;                                   // Advance to next song, in case the user makes no selection    
  }
}

// Function to play the selected track.
// Note that it does not return to loop() until track is complete.
void playSong (char songName[], int size){ 
  File myFile = SD.open(songName);                   // open .wav file from sdcard.
  delay(1000);
  // 44100kHz stereo => 88200 mono sample rate
  AudioZero.begin(88200);
  if (!myFile) {                                     // if the file didn't open, print an error and stop   
    Serial.println("error opening file");
    while (true)
      ;
  }
  Serial.println("Playing");  

  AudioZero.play(myFile);                            // Play until the file is finished. Only returns when song is complete
  AudioZero.end();
  Serial.println("End of file.");
}

// Function to display the selected track's filename
void displaySong (char songName[], int size){
  u8g2.firstPage();
  do {    
    u8g2.setFont(u8g2_font_ncenB12_tr);
    u8g2.drawStr(0,38,songName);
  } while (u8g2.nextPage() );
}

Sketch uses 28592 bytes (10%) of program storage space. Maximum is 262144 bytes.
Global variables use 5084 bytes (15%) of dynamic memory, leaving 27684 bytes for local variables. Maximum is 32768 bytes.

That's pretty vague. Can you give any more details, like size/number/Watts of speaker, size of room... something to quantitatively or qualitatively give an idea of the sound level needed.

I would recommend a DFplayer Mini. It has an amplifier built-in which can drive a small speaker directly with enough volume to be heard from pretty much anywhere in my house. You simply save your audio sounds to MP3 file(s) on a micro-SD card and insert it into the player. The Arduino can send it commands to play any track.

If you need more powerful sound, or stereo, the DFplayer Mini also has line-level outputs which could be connected to a more powerful amplifier module to drive larger speakers.

Certainly

I have used amps from both these companies for 5 years or more now, for the price and size, they are my gotos for Arduino projects (or even just a good home stereo - Fosi sound a little richer to my ears)

Thank you everyone! What an amazing response! Looks like i have a lot of kearning to do, i had discovered the DFplayer mini before and had looked at amplifiers, rtc's, lcd's etc, but had no idea keypads and such were available, or that there had been new arduino compatible options developed. I will start working on a schematic and researching speaker size required etc.