Hi Everyone,
So ill start this off by saying I am relatively new to Arduino, however i am doing a school subject that means i get to make a robot. The desired end robot is an Owl robot that moves its wing and makes sounds in relation to the time of day. But i cannot get the SD to play the audio file i have placed on it. I am using an Arduino UNO, a Arduino to SD chip (not the microSD version) and i also have a pair of pillow speaker in which my sound should come from.
So for now i want to find out why my SD doesn't play sound, below i have included a Fritzing File of my wiring schematic, also the code i have currently. The part that Arduino recognises to have the problems is { { tmrpcm.play("1.wav"); }. My audio files name is "1.WAV" and i did convert it into wav with correct alterations into making it 8-bit, sampling rate 16000Hz and audio channel to mono.
int lightCal;
int lightVal;
int photocellPin = 0; //define photo cell reading input
int photocellReading; //define photo cell reading variable
int winggoing = 0;
int wingstopped = 0;
#include <Servo.h> //add servo libary
Servo wings; //define servo for wings
int pos = 0;
#include <SD.h>
#include<SPI.h>
#include<pcmRF.h>
#include<pcmConfig.h>//add SD libary
#include <TMRpcm.h> //add audio libary
#define SD_ChipSelectPin 4 //SD pin 4
const int sensorPin = A0; //attach photoresistor pin A0
TMRpcm tmrpcm;
void setup() {
Serial.begin(9600); //initiate serial @ 9600 baud
lightCal = analogRead(sensorPin);
wings.write(pos);
wings.attach(6); //attach wing servo pin 6
tmrpcm.speakerPin = 9; //attch speark pin 9
lightVal = analogRead(sensorPin);
if (!SD.begin(SD_ChipSelectPin)) {
return;
}
tmrpcm.setVolume(7); //IF DOESN'T RUN, REMOVE!! Figure out why audio not playing,
(maybe move into loop)
//tmrpcm.play("1.wav"); //REMOVE!! When this code is not commented code wont run and
audio wont play regardless
}
void play(){
tmrpcm.stopPlayback();
tmrpcm.play("1.wav");
delay(10000);
return;
}
void loop()
{
Serial.print("Brightness = "); //print "Brightness = "
Serial.println(photocellReading);
//print the photocell reading
photocellReading = analogRead(photocellPin); //define photocellReading as pin 0 input from LDR
photocellReading = map(photocellReading, 0, 1023, 0, 179); //map the LDR input to a value between 1-180 so the servo can understand it
{
if (photocellReading >= 110) // && wingstopped == 0)
{ //if the LDR is showing less than half light intensity
for (pos = 1; pos <= 180; pos += 1) { //Move wings
wings.write (pos);
delay(15);
}
for (pos = 180; pos >= 1; pos -= 1) { //move wings
wings.write(pos);
delay(15);
}
delay(20000);
wingstopped = 1;
winggoing = 0;
} //then tell the servo to rotate backwards at a steady rate
else if (photocellReading <= 70) // && winggoing == 0)
{ //if the LDR is showing more than half light intensity
wings.write(1); //then tell the servo to rotate forwards at a steady rate
//delay(15);
winggoing = 1;
wingstopped = 0;}
}
} //else if (photocellReading >= 71 && photocellReading <=109)
//Use code above /\ if you want it to turn off midday
Edit: I may have found the problem to be that the card format needs to be MS-DOS(FAT)?