Hi,
I am currently working on a project to create an alarm clock, that will play a ".WAV" file off of an SD card.
I am trying to integrate the following components on an Genuino Uno:
-DS 1307 RTC
-SD Shield 3.0
-LCD (16, 2) display
The code I have is probably a lot more clunky than I need it to be, but I am new to the Arduino world so at the moment it is the best I can put together. It is splices of different codes found out on the interweb.
The issue I have is that once the program enters into the Alarm function the file will not play off of the SD card. I have placed a "Serial.print" command inside the alarm function, so I know that the program is at least entering the function, but is just not playing the file. The file does play when I have a program to play off the SD card as a stand alone program, so the ability is there. But once everything is combined it will not play.
As the code is long, I have attached it to this post. And portion of the sketch trying to play the audio file is at the bottom of the sketch.
Any assistance at all is much appreciated.
**EDIT - So I changed around some wiring, and changed the code to test a possible solution. I thought the LCD pins 11, 12 were interfering with the SPI pins 11, 12, 13. This did not prove to be the case and actually made the problem worse, as the LCD display would not work properly now. So I changed the wiring back to the original configuration but forgot to change the code back to the original configuration before attaching it to this post. The code in this section below (not the attachment) is the code that I was using before making things worse with the LCD.
#include <RTClib.h>
#include <TimeLib.h>
#include <Wire.h>
#include<EEPROM.h>
#include "TMRpcm.h"
#include "SD.h"
#include "SPI.h"
#define SD_ChipSelectPin 4
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 6, 8, 9, 11, 12);
RTC_DS1307 RTC;
int temp, inc, hours1, minut, add = 11;
int next = 7;
int INC = 5;
int set_mad = 3;
//#define buzzer 3
int HOUR, MINUT, SECOND;
TMRpcm tmrpcm; //***
void setup()
{
Serial.begin(9600);
Wire.begin();
RTC.begin();
lcd.begin(16, 2);
pinMode(INC, INPUT);
pinMode(next, INPUT);
pinMode(set_mad, INPUT);
tmrpcm.speakerPin = 10;
//pinMode(buzzer, OUTPUT);
digitalWrite(next, HIGH);
digitalWrite(set_mad, HIGH);
digitalWrite(INC, HIGH);
lcd.setCursor(0, 0);
lcd.print("Arduino Project");
lcd.setCursor(0, 1);
lcd.print("Alarm Clock ");
delay(2000);
if (!RTC.isrunning())
{
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop()
{
int temp = 0, val = 1, temp4;
DateTime now = RTC.now();
if (digitalRead(set_mad) == 0) //set Alarm time
{
lcd.setCursor(0, 0);
lcd.print(" Set Alarm ");
delay(2000);
defualt();
time();
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Alarm time ");
lcd.setCursor(0, 1);
lcd.print(" has been set ");
delay(2000);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time:");
lcd.setCursor(6, 0);
lcd.print(HOUR = now.hour(), DEC);
lcd.print(":");
lcd.print(MINUT = now.minute(), DEC);
lcd.print(":");
lcd.print(SECOND = now.second(), DEC);
lcd.setCursor(0, 1);
lcd.print("Date: ");
lcd.print(now.day(), DEC);
lcd.print("/");
lcd.print(now.month(), DEC);
lcd.print("/");
lcd.print(now.year(), DEC);
match();
delay(200);
}
void defualt()
{
lcd.setCursor(0, 1);
lcd.print(HOUR);
lcd.print(":");
lcd.print(MINUT);
lcd.print(":");
lcd.print(SECOND);
}
void time() //Function to set alarm time and feed time into Internal eeprom
{
int temp = 1, minuts = 0, hours = 0, seconds = 0;
while (temp == 1)
{
if (digitalRead(INC) == 0)
{
HOUR++;
if (HOUR == 24)
{
HOUR = 0;
}
while (digitalRead(INC) == 0);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set Alarm Time ");
//lcd.print(x);
lcd.setCursor(0, 1);
lcd.print(HOUR);
lcd.print(":");
lcd.print(MINUT);
lcd.print(":");
lcd.print(SECOND);
delay(100);
if (digitalRead(next) == 0)
{
hours1 = HOUR;
EEPROM.write(add++, hours1);
temp = 2;
while (digitalRead(next) == 0);
}
}
while (temp == 2)
{
if (digitalRead(INC) == 0)
{
MINUT++;
if (MINUT == 60)
{
MINUT = 0;
}
while (digitalRead(INC) == 0);
}
// lcd.clear();
lcd.setCursor(0, 1);
lcd.print(HOUR);
lcd.print(":");
lcd.print(MINUT);
lcd.print(":");
lcd.print(SECOND);
delay(100);
if (digitalRead(next) == 0)
{
minut = MINUT;
EEPROM.write(add++, minut);
temp = 0;
while (digitalRead(next) == 0);
}
}
delay(1000);
}
void match() //Checking for a match in alarm time and real time
{
int tem[17];
for (int i = 11; i < 17; i++)
{
tem[i] = EEPROM.read(i);
}
if (HOUR == tem[11] && MINUT == tem[12])
{
beep();
//beep();
//beep();
//beep();
lcd.clear();
lcd.print("Wake Up........");
lcd.setCursor(0, 1);
lcd.print("Wake Up.......");
//beep();
//beep();
//beep();
//beep();
}
}
void beep() //The alarm section trying to play the audio file
{
Serial.println ("Entered alarm section");
tmrpcm.setVolume(6);
tmrpcm.play("The_view.wav");
//digitalWrite (10, HIGH);
//delay (500);
//digitalWrite (10, LOW);
//delay (500);
}
Alarm_clock_SD_Dec_11.ino (3.67 KB)