(edit, as I posted early without diagrams)
Hi everyone
I'm controlling sounds and scares in an escape room using an uno. A few days ago, it just stopped playing the soundbites. (There is a diagram at the bottom of the previous setup)
Pretty much the entire setup stopped behaving properly, none of the inputs and outputs were being recognised by the code, I was grounding gpio 11 (for example) but was getting the result in the serial monitor from what I'd expect if I grounded gpio A3, just really random stuff.
So, I uploaded the code to another board, and just connected the mp3 module up, with a few jumpers to trigger the sounds. The serial monitor suggests that things are being properly triggered in the code, but I cannot for the life of me get the player to play the sounds. I'm not even getting the flashing red led on the module as if it's saying "I'm playing a sound". Here's a diagram (because I'm rushing, I made the VCC wire black and the gnd wire red, but they're connected correctly it's just the colour that's nonsensical)
I have tried:
Swapping the uno out for a new one
Changing the SD card
Changing the mp3 player for a known working module
Changing the baud rate from 9600 to 19200 for the player (I don't even know if this makes a difference)
I'm not massively confident with arduino so I'm a bit limited on what I can do to troubleshoot the problem which is why I'm here. I've searched around and no one really has this issue, they're always using different pins than myself or a different kind of software serial so for someone who isn't that useful with programming, it's like apples and oranges
Here's the code I'm running. There's a lot of redundant stuff in it that I'm too anxious to remove in case it was holding the entire thing together!
#define DEBUG
// Scare control UNO
#include <AltSoftSerial.h> // Alt serial library, see library folder in dropbox
#include <Wire.h>
#include <MD_YX5300.h> // See library folder in dropbox
#include <Bounce2.h> // For debouncing button input. See https://github.com/thomasfredericks/Bounce2
// Tunable variables - These are so you can sync up sounds and scares easily
#define DEBUG
#ifdef DEBUG
int vaDelay = 5000; // violent attack delay. Debug 5000. Live 60000.
int cbDelay1 = 5000; // first crying delay. Debug 5000. Live 10000.
int cbDelay2 = 5000; // second cry delay. Debug 5000. Live 5000.
int FHdim = 1500; // Time for the spotlight to dim after the MP3 has been triggered
int FHrelay = 2500; // Time for relay to hit
int BYdelay1 = 2000; // Time for first behind you after reed trigger
int BYdelay2 = 4000; // Time for second behind you after first behind you
int BYflicker1 = 2000; // Time for first flicker pulse
int BYflicker2 = 3000; // Time for second flicker pulse
int fadeAmount = 5; // how many points to fade the spotlight by
int fadeinTime = 50; // how quickly to fade the spotlight up (this is slower)
int fadeoutTime = 20; // how quickly to fade the spotlight up (this is quick)
int postScareTime = 5000;
#endif
#ifndef DEBUG
int vaDelay = 60000; // violent attack delay. Debug 5000. Live 60000.
int cbDelay1 = 10000; // first crying delay. Debug 5000. Live 10000.
int cbDelay2 = 5000; // second cry delay. Debug 5000. Live 5000.
int FHdim = 1500; // Time for the spotlight to dim after the MP3 has been triggered
int FHrelay = 2500; // Time for relay to hit
int BYdelay1 = 12000; // Time for first behind you after reed trigger
int BYdelay2 = 20000; // Time for second behind you after first behind you
int BYflicker1 = 2000; // Time for first flicker pulse
int BYflicker2 = 3000; // Time for second flicker pulse
int fadeAmount = 5; // how many points to fade the spotlight by
int fadeinTime = 50; // how quickly to fade the spotlight up (this is slower)
int fadeoutTime = 20; // how quickly to fade the spotlight up (this is quick)
int postScareTime = 5000;
#endif
// Input pins
int hiss = 12;
int hissSelect; // Random number to select which hiss mp3 to select
int flicker = 8;
int exhale = 10;
int baby = 11;
// Output pins
int megaFlicker = A5; // THIS IS NOW ATTACHED TO AN LED
int megavolumeDown = 2;
// Input triggers
int circsqtriPin = A0; // CHANGED Trigger for 1612 and starts violet attack countdown
int circsqtriLev;
int rfidPin = A1; // CHANGED Trigger the facehugger sequence
int rfidLev;
int jump7Pin= A2; // CHANGED Trigger the window opening sounds
int jump7Lev;
int reedPin = A3; // CHANGED Trigger any behind you sequence
int reedLev;
int plugPin = A4; // Trigger the scare
// int ultrasoundPin = 7;
int threshold = 800; // Threshold for detecting the LED flashes
// Pins for scare switch
int scareSwitch = 13; // This is pulled low when scares are being turned on.
int switchState; //
bool scaresOn = false; // bool to keep track of if scares are on
// Utility
int spotlight = 9; // PWM pin to control the brightness of the light
int spotlightDelay = 0; // Counter to keep track of the delay for the spotlight
int spotlightThreshold = 10000; // Threshold for when to turn on the spotlight
int brightness = 0; // how bright the spotlight is
int lightRelay = 3; // Relay attached to light NO is floor NC is hand
int facehuggerRelay = 4; // Relay to release the facehugger scare
bool plugState = false; // Keeps the "waiting for plug" loop going
// GLOBALS
// Create an array of Bounce objects for each input button
//Bounce circsqtriSwitch = Bounce();
//Bounce reedSwitch = Bounce();
//Bounce rfidSwitch = Bounce();
//Bounce jump7Switch = Bounce();
Bounce plugSwitch = Bounce();
//Bounce ultrasoundSwitch = Bounce();
Bounce hissSwitch = Bounce();
Bounce exhaleSwitch = Bounce();
Bounce babySwitch = Bounce();
Bounce flickerSwitch = Bounce();
// Initialise a software serial interface on the approriate Rx/Tx pins (8/9)
AltSoftSerial altSerial;
// And create an MP3 object based on the serial connection
MD_YX5300 mp3(altSerial);
void setup()
{
delay (1000);
// Initialise a serial connection (used for debugging only)
Serial.begin(115200);
Serial.println(__FILE__ __DATE__);
Serial.println("Serial connection initialised");
Serial.println ("Setup 2 begun, buffer initiated");
delay (10000);
Serial.println ("Buffer 2 complete");
//reedSwitch.attach(reedPin, INPUT_PULLUP); // REED
//rfidSwitch.attach(rfidPin, INPUT_PULLUP); // DOOR
//circsqtriSwitch.attach(circsqtriPin, INPUT_PULLUP);// 16
//jump7Switch.attach(jump7Pin, INPUT_PULLUP); // J7
plugSwitch.attach(plugPin, INPUT_PULLUP);
// ultrasoundSwitch.attach(ultrasoundPin, INPUT_PULLUP);
// Changes adding the LDRs
pinMode(reedPin, INPUT);
pinMode(rfidPin, INPUT);
pinMode(circsqtriPin, INPUT);
pinMode(jump7Pin, INPUT);
hissSwitch.attach(hiss, INPUT_PULLUP);
flickerSwitch.attach(flicker, INPUT_PULLUP);
exhaleSwitch.attach(exhale, INPUT_PULLUP);
babySwitch.attach(baby, INPUT_PULLUP);
Serial.println("Utility buttons initialised");
// Scare mode?
pinMode (scareSwitch, INPUT_PULLUP);
switchState = digitalRead(scareSwitch);
Serial.println(switchState);
// Initialise pins and test
pinMode(megaFlicker, OUTPUT); // Because this is the LED
digitalWrite(megaFlicker, LOW); // Make sure it's not on
pinMode(megavolumeDown, OUTPUT);
pinMode(spotlight, OUTPUT);
pinMode(facehuggerRelay, OUTPUT);
digitalWrite(facehuggerRelay, LOW);
pinMode(lightRelay, OUTPUT);
digitalWrite (lightRelay, LOW);
// Test
// Initialise the serial interface to the MP3 player
altSerial.begin(9600);
mp3.begin();
mp3.volume(30);
delay(1000);
if (switchState == 0){
scaresOn = true;
Serial.print(switchState);
mp3.playTrack(1); // "Horror mode is turned on"
Serial.println ("Horror mode is turned ON");
}
else {
scaresOn = false;
Serial.print(switchState);
mp3.playTrack(2); // "Horror mode is turned off"
Serial.println ("Horror mode is turned OFF");
}
delay(1000);
Serial.println("Setup complete");
}
void loop()
{
switchState = digitalRead(scareSwitch);
if (switchState == 0){
scaresOn = true;
Serial.println("SPOOKY");
}
if (switchState != 0) {
scaresOn = false;
Serial.println("Safe");
}
// reedSwitch.update();
// rfidSwitch.update();
// circsqtriSwitch.update();
// jump7Switch.update();
// ultrasoundSwitch.update();
// Read the light levels
circsqtriLev = analogRead (circsqtriPin);
rfidLev = analogRead (rfidPin);
jump7Lev = analogRead (jump7Pin);
reedLev = analogRead (reedPin);
// Print the light levels
Serial.print(circsqtriLev);
Serial.print("\t");
Serial.print(rfidLev);
Serial.print("\t");
Serial.print(jump7Lev);
Serial.print("\t");
Serial.print(reedLev);
Serial.println("\t");
// Update the manual switches
hissSwitch.update();
flickerSwitch.update();
exhaleSwitch.update();
babySwitch.update();
// Now run through the statements to detect changes
//if(circsqtriSwitch.fell())
if (circsqtriLev>threshold)
{
Serial.println("1612 complete");
#ifdef DEBUG
Serial.println("Debug pause");
delay(5000);
#endif
violentAttack();
}
//if(rfidSwitch.fell())
if (rfidLev>threshold)
{
Serial.println("rfid complete");
#ifdef DEBUG
Serial.println("Debug pause");
delay(5000);
#endif
if (scaresOn == true)
{
Serial.println("SCARES ARE ON");
jumpScare();
}
else
{
Serial.println("SCARES ARE OFF");
noScare();
}
}
//if(jump7Switch.fell())
if (jump7Lev>threshold)
{
Serial.println("jump7 complete");
#ifdef DEBUG
Serial.println("Debug pause");
delay(5000);
#endif
cryBabies();
}
//if(reedSwitch.fell())
if (reedLev>threshold)
{
Serial.println("reed complete");
behindYou();
}
if(flickerSwitch.fell())
{
Serial.println("flicker");
#ifdef DEBUG
Serial.println("Pause");
delay(5000);
#endif
{
delay(5000);
sendFlicker();
}
}
if(babySwitch.fell())
{
Serial.println("baby");
#ifdef DEBUG
Serial.println("Pause");
delay(5000);
#endif
if (scaresOn == true)
{
mp3.playTrack(10);
delay(1000);
}
}
if(hissSwitch.fell())
{
Serial.println("hiss");
#ifdef DEBUG
Serial.println("Pause");
delay(5000);
#endif
if (scaresOn == true)
{
whataHisser();
}
}
if(exhaleSwitch.fell())
{
Serial.println("exhale");
#ifdef DEBUG
Serial.println("Pause");
delay(5000);
#endif
if (scaresOn == true)
{
mp3.playTrack(11);
}
}
}
void violentAttack()
{
Serial.println("in function violentAttack");
#ifdef DEBUG
Serial.println("Debug pause");
delay(5000);
#endif
if (scaresOn == true)
{
Serial.println("playing violent attack");
delay(vaDelay);
mp3.playTrack(3);
}
return;
}
void jumpScare() // TO DO
{
Serial.println("in jumpScare");
digitalWrite(lightRelay, HIGH);
mp3.playTrack(7); // Containment cell access granted, warning eteenfeijnfei
do
{
plugSwitch.update();
spotlightDelay ++;
Serial.print("Spotlight delay is ");
Serial.println(spotlightDelay);
if (spotlightDelay == spotlightThreshold)
{
mp3.volume(20);
mp3.playTrack(5); // Facehugger cry
Serial.println ("Facehugger crying");
mp3.volume(30);
brightness = 0;
do
{
analogWrite(spotlight, brightness); // Set current brightness
// Serial.println (brightness);
brightness = brightness + fadeAmount; // Increase brightness
delay(fadeinTime);
}
while (brightness <= 225); // Till brightness maxed
analogWrite(spotlight,225);
//digitalWrite(megavolumeDown, LOW); // Send volume down signal
//delay(200);
//digitalWrite(megavolumeDown, HIGH);
}
if(plugSwitch.fell())
{
Serial.println("plug connected");
mp3.playTrack(9); // Facehugger strike begins
delay(FHdim); // Delay a bit so people can react to the sound
do
{
analogWrite(spotlight, brightness); // Set current brightness
//Serial.println (brightness);
brightness = brightness - fadeAmount; // Decrease brightness
delay(fadeoutTime);
}
while (brightness >= 0); // Till brightness at minimum
analogWrite(spotlight, 0);
delay(FHrelay);
digitalWrite (facehuggerRelay, HIGH);
delay(200);
digitalWrite(facehuggerRelay, LOW);
plugState = true;
delay(postScareTime);
// digitalWrite(lightRelay, LOW);
sendFlicker();
// digitalWrite(megavolumeDown, LOW); // Send volume up signal
// delay(200);
// digitalWrite(megavolumeDown, HIGH);
}
}
while (plugState == false);
}
void noScare()
{
Serial.println ("in noScare");
mp3.playTrack(8);
return;
}
void cryBabies ()
{
if (scaresOn == true)
{
delay(cbDelay1);
mp3.playTrack(5);
delay(cbDelay2);
mp3.playTrack(4);
}
else
{
return;
}
}
void behindYou()
{
if(scaresOn == true)
{
mp3.volume(25);
delay (BYdelay1);
mp3.playTrack(12);
delay (BYdelay2);
sendFlicker();
delay (BYflicker1);
mp3.playTrack(13);
delay (BYflicker2);
sendFlicker();
}
else
{
return;
}
}
void spotlightOff()
{
do
{
analogWrite(spotlight, brightness); // Set current brightness
// Serial.println (brightness);
brightness = brightness - fadeAmount; // Decrease brightness
delay(fadeoutTime);
}
while (brightness >= 0); // Till brightness at minimum
analogWrite(spotlight, 0);
return;
}
void whataHisser()
{
hissSelect = random(3);
Serial.println (hissSelect);
#ifdef DEBUG
Serial.println("Debug pause");
delay(5000);
#endif
if (hissSelect == 0)
{
mp3.playTrack(14);
}
else if (hissSelect == 1)
{
mp3.playTrack(15);
}
else if (hissSelect == 2)
{
mp3.playTrack(16);
}
}
void sendFlicker()
{
if (scaresOn == true)
{
digitalWrite(megaFlicker, HIGH);
delay(200);
digitalWrite(megaFlicker, LOW);
mp3.playTrack(18);
}
}
Diagram of what I want to eventually end up with (edit, I know this is really hard to read and zoomed out sorry about that, it's a work in progress and a bit of a draft where I'm jotting down as I go along, it looks a lot like what it looked like before everything died)