project doesn't work, maybe voltage to low/problem with code?

hey!

I'm having some problems getting my project to work, I've gotten someone to write some code for me since i'm pretty bad at it.
but now when I upload it it never gets any further than "doPlayAudio1".
and I dont actually hear audio 1 being played
I think it might be a voltage problem?

I included the way I have everything wired now, its a bit of a mess so it also has the text with what stuff is on which pin.

#include "SPI.h"
#include "SD.h"
//#include <pcmRF.h>     // kan volgens mij weg, als het zonder werkt
//#include <pcmConfig.h> // kan volgens mij weg, als het zonder werkt
#include "TMRpcm.h"
#define SD_ChipSelectPin 10 // ChipSelect op pin 10
TMRpcm music; // TMRpcm heet vanaf nu 'music'

int button1 = 7; // pin 7 connected to button 1
int button2 = 6; // pin 6 connected to button 2
int button3 = 5; // pin 5 connected to button 3
int button4 = 4; // pin 4 connected to button 4
int button5 = 3; // pin 3 connected to button 5
int ldr = A0;  // pin A0 connected to ldr

long nobody = 10000; // 10 seconds

// define application states
enum AppStates
{
  Nothing = 0,
  PlayAudio1 = 1,
  PlayAudio2 = 2,
  PlayAudio3 = 3,
  PlayAudio4 = 4,
  PlayAudio5 = 5,
  PlayAudio6 = 6,
  PlayAudio7 = 7,
  PlayAudio8 = 8,
  PlayAudio9 = 9,
  PlayAudio10 = 10
};

// define behaviors
void doNothing()
{
  Serial.println("doNothing"); 
}

void doPlayAudio1()
{
  Serial.println("doPlayAudio1"); 
  {music.play("1.wav");} //Play song 1 
}

void doPlayAudio2()
{
  Serial.println("doPlayAudio2"); 
  {music.play("2.wav");} //Play song 2 
}

void doPlayAudio3()
{
  Serial.println("doPlayAudio3"); 
  {music.play("3.wav");} //Play song 3 
}

void doPlayAudio4()
{
  Serial.println("doPlayAudio4"); 
  {music.play("4.wav");} //Play song 4 
}

void doPlayAudio5()
{
  Serial.println("doPlayAudio5");
  {music.play("5.wav");} //Play song 5  
}

void doPlayAudio6()
{
  Serial.println("doPlayAudio6"); 
  {music.play("6.wav");} //Play song 6 
}

void doPlayAudio7()
{
  Serial.println("doPlayAudio7"); 
  {music.play("7.wav");} //Play song 7 
}

void doPlayAudio8()
{
  Serial.println("doPlayAudio8"); 
  {music.play("8.wav");} //Play song 8 
}

void doPlayAudio9()
{
  Serial.println("doPlayAudio9"); 
  {music.play("9.wav");} //Play song 9
}

void doPlayAudio10()
{
  Serial.println("doPlayAudio10"); 
  {music.play("10.wav");} //Play song 10 
}

// logic
int state = Nothing;

struct Movement
{
  int button;
  int from;
  int to;
};

struct Behavior
{
  int state;
  void (*func)();
};

const int maxMovements = 64;
Movement movements[maxMovements];
int numMovements = 0;

const int maxBehaviors = 32;
Behavior behaviors[maxBehaviors];
int numBehaviors = 0;

void addMovement(int f, int b, int t)
{
  movements[numMovements].button = b;
  movements[numMovements].from = f;
  movements[numMovements].to = t;
  numMovements++;
}

void addBehavior(int s, void (*f)())
{
  behaviors[numBehaviors].state = s;
  behaviors[numBehaviors].func = f;
  numBehaviors++;
}

void setup() {
  // setup, basically some preparations
  
  pinMode(button1, INPUT); // button 1-5 and ldr are inputs
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);
  pinMode(button4, INPUT);
  pinMode(button5, INPUT);

  pinMode(ldr, INPUT);

  music.speakerPin = 9; // audio output on pin 7

  Serial.begin(9600);

  if (!SD.begin(SD_ChipSelectPin)) {
    Serial.println("SD fail");
    return;
  }

  music.setVolume(7); // 0 tot 7, stel volume in
  music.quality(1); //Set 1 for 2x oversampling Set 0 for normal
  
  addMovement(Nothing, button1, PlayAudio2);
  addMovement(Nothing, button2, PlayAudio3);
  addMovement(PlayAudio2, -1, PlayAudio7);
  addMovement(PlayAudio3, -1, PlayAudio7);
  addMovement(PlayAudio7, -1, PlayAudio1);

  addMovement(Nothing, button3, PlayAudio4);
  addMovement(PlayAudio4, -1, PlayAudio8);
  addMovement(PlayAudio8, -1, PlayAudio10);
  addMovement(PlayAudio10, -1, PlayAudio1);

  addMovement(Nothing, button4, PlayAudio5);
  addMovement(PlayAudio5, -1, PlayAudio8);

  addMovement(Nothing, button5, PlayAudio6);
  addMovement(PlayAudio6, -1, PlayAudio9);
  addMovement(PlayAudio9, -1, PlayAudio1);

  addMovement(PlayAudio1, button1, PlayAudio2);
  addMovement(PlayAudio1, button2, PlayAudio3);
  addMovement(PlayAudio1, button3, PlayAudio4);
  addMovement(PlayAudio1, button4, PlayAudio5);
  addMovement(PlayAudio1, button5, PlayAudio6);

  addBehavior(Nothing, &doNothing);
  addBehavior(PlayAudio1, &doPlayAudio1);
  addBehavior(PlayAudio2, &doPlayAudio2);
  addBehavior(PlayAudio3, &doPlayAudio3);
  addBehavior(PlayAudio4, &doPlayAudio4);
  addBehavior(PlayAudio5, &doPlayAudio5);
  addBehavior(PlayAudio6, &doPlayAudio6);
  addBehavior(PlayAudio7, &doPlayAudio7);
  addBehavior(PlayAudio8, &doPlayAudio8);
  addBehavior(PlayAudio9, &doPlayAudio9);
  addBehavior(PlayAudio10, &doPlayAudio10);
}

int buttonPressed = 0;
long pressedMillis = 0;

void checkButtonPressed(int button)
{
  if (digitalRead(button) == HIGH && millis() - pressedMillis > 1000) 
  {
    buttonPressed = button;
    pressedMillis = millis();
  }
}

void goToState(int s)
{
  state = s;

  for (int i = 0 ; i < numBehaviors ; i++)
    if (behaviors[i].state == state && behaviors[i].func != 0)
      (*behaviors[i].func)();
}

void loop() {
  // put your main code here, to run repeatedly:
  buttonPressed = 0;
  checkButtonPressed(button1);
  checkButtonPressed(button2);
  checkButtonPressed(button3);
  checkButtonPressed(button4);
  checkButtonPressed(button5);

  int lightThreshold = 800;

  int lightValue = analogRead(ldr);

  if (buttonPressed != 0 && lightValue >= lightThreshold)
  {
    for (int i = 0 ; i < numMovements ; i++)
      if ((movements[i].button == -1 || movements[i].button == buttonPressed) && movements[i].from == state)
      {
        goToState(movements[i].to);
        break;
      }
  }
  else if (state != PlayAudio1 && (millis() - pressedMillis > nobody || lightValue < lightThreshold))
    goToState(PlayAudio1);
}

it might be usefull for me to explain what the goal is of this particular project as well.
basically its a finite state machine in the form of an als fashioned phone.
pich up the receiver triggers the LDR which triggers audio1 to play.
buttons pressed afterwards trigger other pieces of audio to play.
i've attached a picture which explains it slightly better.

Is this the same project as in your other Threads here and here?

If you keep all the info for one project in one Thread it is easier to see the entire context and it avoids wasting time with duplicate or irrelevant advice or questions.

...R

Is this the same project as in your other Threads here and here?

If you keep all the info for one project in one Thread it is easier to see the entire context and it avoids wasting time with duplicate or irrelevant advice or questions.

yes it is, I always find it easier to start a new topic if a new problem arises that no longer really has anything to do with the main subject of the topic. In hopes of finding people who know how to help said problem better.
but if thats bad forum etiquette I will definitely stop doing that, sorry!

It would not be bad etiquette if the new question really has nothing to do with the other Threads. My problem is that without reading those Threads (which I don't propose to do) I do not know that.

I have seen a lot of questions where we were assured that the problem was in X when (after several days) it transpired that it had been in Y all the time.

Consequently I find it very difficult to get my ageing brain around a problem if there is a niggle in the back of it that an important piece of the jigsaw may be lost under the sofa.

Other contributors may have more pliable brains.

...R

First thing I'd do is verify that I could play something by making a minimal program that does the minimal necessary setup and then plays a single wav. You have way too much code there for something that's not working at all.

First thing I'd do is verify that I could play something by making a minimal program that does the minimal necessary setup and then plays a single wav. You have way too much code there for something that's not working at all.

I've done this using this code:

 //TMRpcm library is needed

#include "SD.h"
#define SD_ChipSelectPin 10
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm tmrpcm;

void setup()
{
tmrpcm.speakerPin=9;
Serial.begin(9600);
if(!SD.begin(SD_ChipSelectPin))
{
  Serial.println("SD fail");
  return;
}
tmrpcm.setVolume(6);
tmrpcm.play("test.wav");

}

void loop() {
  // put your main code here, to run repeatedly:

}

using this it will play the music

I've also tested the button setup using some LED's to verify each button working

const int buttonPin1 = 8;
const int buttonPin2 = 12;
const int buttonPin3 = 11;
const int buttonPin4 = 10;
const int buttonPin5 = 9;// the number of the pushbutton pin
const int ledPin1 =  2; 
const int ledPin2 =  4;
const int ledPin3 =  5;
const int ledPin4 =  6;
const int ledPin5 =  7; // the number of the LED pin

// variables will change:
int buttonState1 = 0; 
int buttonState2 = 0; 
int buttonState3 = 0; 
int buttonState4 = 0; 
int buttonState5 = 0; // variable for reading the pushbutton status

void setup() {
  pinMode(ledPin1, OUTPUT);
  pinMode(buttonPin1, INPUT);
   pinMode(ledPin2, OUTPUT);
  pinMode(buttonPin2, INPUT);
   pinMode(ledPin3, OUTPUT);
  pinMode(buttonPin3, INPUT);
   pinMode(ledPin4, OUTPUT);
  pinMode(buttonPin4, INPUT);
   pinMode(ledPin5, OUTPUT);
  pinMode(buttonPin5, INPUT);

 

}

void loop() {
  // read the state of the pushbutton value:
 buttonState1 = digitalRead(buttonPin1);
 buttonState2 = digitalRead(buttonPin2);
 buttonState3 = digitalRead(buttonPin3);
 buttonState4 = digitalRead(buttonPin4);
 buttonState5 = digitalRead(buttonPin5);


  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState1 == HIGH) {
    // turn LED on:
    digitalWrite(ledPin1, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin1, LOW);
  }

   if (buttonState2 == HIGH) {
    // turn LED on:
    digitalWrite(ledPin2, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin2, LOW);
  }

   if (buttonState3 == HIGH) {
    // turn LED on:
    digitalWrite(ledPin3, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin3, LOW);
  }

   if (buttonState4 == HIGH) {
    // turn LED on:
    digitalWrite(ledPin4, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin4, LOW);
  }

   if (buttonState5 == HIGH) {
    // turn LED on:
    digitalWrite(ledPin5, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin5, LOW);
  }
 }

it seems each individual component works fine using a simple code to test it, however when i put everything together and use the previous code things stop functioning.

Do those tests work with your current wiring?

If I compile that for an Uno with IDE 1.6.12, with warnings to the Max in preferences, I get a lot of warnings about the TMRpcm library. More importantly, I get this:

Global variables use 1,758 bytes (85%) of dynamic memory, leaving 290 bytes for local variables. Maximum is 2,048 bytes.
Low memory available, stability problems may occur.

You might want to use the F macro on the strings you're Serial.printing. Also, you've reserved more space for your movements and behaviors that you need. It would be trivial to reduce them for testing purposes.

Do those tests work with your current wiring?

Yes they do

I also figured out why it wasn't printing anything for any of the buttons I pressed, de LDR threshold wasn't right for the current lighting (stupid mistake)

however now that it is printing that certain audio needs to be played I still cant hear any audio from my speaker.
the setup works fine when i use this code;

#include "SD.h"
#define SD_ChipSelectPin 10
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm tmrpcm;

void setup()
{
tmrpcm.speakerPin=9;
Serial.begin(9600);
if(!SD.begin(SD_ChipSelectPin))
{
  Serial.println("SD fail");
  return;
}
tmrpcm.setVolume(6);
tmrpcm.play("test.wav");

}

void loop() {
  // put your main code here, to run repeatedly:

}

so I don't understand why it wont work with this code;

 #include "SPI.h"
#include "SD.h"
#include <pcmRF.h>     // kan volgens mij weg, als het zonder werkt
#include <pcmConfig.h> // kan volgens mij weg, als het zonder werkt
#include "TMRpcm.h"
#define SD_ChipSelectPin 10 // ChipSelect op pin 10
TMRpcm music; // TMRpcm heet vanaf nu 'music'

int button1 = 7; // pin 7 connected to button 1
int button2 = 6; // pin 6 connected to button 2
int button3 = 5; // pin 5 connected to button 3
int button4 = 4; // pin 4 connected to button 4
int button5 = 3; // pin 3 connected to button 5
int ldr = A0;  // pin A0 connected to ldr

long nobody = 10000; // 10 seconds

// define application states
enum AppStates
{
  Nothing = 0,
  PlayAudio1 = 1,
  PlayAudio2 = 2,
  PlayAudio3 = 3,
  PlayAudio4 = 4,
  PlayAudio5 = 5,
  PlayAudio6 = 6,
  PlayAudio7 = 7,
  PlayAudio8 = 8,
  PlayAudio9 = 9,
  PlayAudio10 = 10
};

// define behaviors
void doNothing()
{
  Serial.println("doNothing"); 
}

void doPlayAudio1()
{
  Serial.println("doPlayAudio1"); 
  {music.play("1.wav");} //Play song 1 
}

void doPlayAudio2()
{
  Serial.println("doPlayAudio2"); 
  {music.play("2.wav");} //Play song 2 
}

void doPlayAudio3()
{
  Serial.println("doPlayAudio3"); 
  {music.play("3.wav");} //Play song 3 
}

void doPlayAudio4()
{
  Serial.println("doPlayAudio4"); 
  {music.play("4.wav");} //Play song 4 
}

void doPlayAudio5()
{
  Serial.println("doPlayAudio5");
  {music.play("5.wav");} //Play song 5  
}

void doPlayAudio6()
{
  Serial.println("doPlayAudio6"); 
  {music.play("6.wav");} //Play song 6 
}

void doPlayAudio7()
{
  Serial.println("doPlayAudio7"); 
  {music.play("7.wav");} //Play song 7 
}

void doPlayAudio8()
{
  Serial.println("doPlayAudio8"); 
  {music.play("8.wav");} //Play song 8 
}

void doPlayAudio9()
{
  Serial.println("doPlayAudio9"); 
  {music.play("9.wav");} //Play song 9
}

void doPlayAudio10()
{
  Serial.println("doPlayAudio10"); 
  {music.play("10.wav");} //Play song 10 
}

// logic
int state = Nothing;

struct Movement
{
  int button;
  int from;
  int to;
};

struct Behavior
{
  int state;
  void (*func)();
};

const int maxMovements = 64;
Movement movements[maxMovements];
int numMovements = 0;

const int maxBehaviors = 32;
Behavior behaviors[maxBehaviors];
int numBehaviors = 0;

void addMovement(int f, int b, int t)
{
  movements[numMovements].button = b;
  movements[numMovements].from = f;
  movements[numMovements].to = t;
  numMovements++;
}

void addBehavior(int s, void (*f)())
{
  behaviors[numBehaviors].state = s;
  behaviors[numBehaviors].func = f;
  numBehaviors++;
}

void setup() {
  // setup, basically some preparations
  
  pinMode(button1, INPUT); // button 1-5 and ldr are inputs
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);
  pinMode(button4, INPUT);
  pinMode(button5, INPUT);

  pinMode(ldr, INPUT);

  music.speakerPin = 9; // audio output on pin 9

  Serial.begin(9600);

  if (!SD.begin(SD_ChipSelectPin)) {
    Serial.println("SD fail");
    return;
  }

  music.setVolume(7); // 0 tot 7, stel volume in
  music.quality(1); //Set 1 for 2x oversampling Set 0 for normal
  
  addMovement(Nothing, button1, PlayAudio2);
  addMovement(Nothing, button2, PlayAudio3);
  addMovement(PlayAudio2, -1, PlayAudio7);
  addMovement(PlayAudio3, -1, PlayAudio7);
  addMovement(PlayAudio7, -1, PlayAudio1);

  addMovement(Nothing, button3, PlayAudio4);
  addMovement(PlayAudio4, -1, PlayAudio8);
  addMovement(PlayAudio8, -1, PlayAudio10);
  addMovement(PlayAudio10, -1, PlayAudio1);

  addMovement(Nothing, button4, PlayAudio5);
  addMovement(PlayAudio5, -1, PlayAudio8);

  addMovement(Nothing, button5, PlayAudio6);
  addMovement(PlayAudio6, -1, PlayAudio9);
  addMovement(PlayAudio9, -1, PlayAudio1);

  addMovement(PlayAudio1, button1, PlayAudio2);
  addMovement(PlayAudio1, button2, PlayAudio3);
  addMovement(PlayAudio1, button3, PlayAudio4);
  addMovement(PlayAudio1, button4, PlayAudio5);
  addMovement(PlayAudio1, button5, PlayAudio6);

  addBehavior(Nothing, &doNothing);
  addBehavior(PlayAudio1, &doPlayAudio1);
  addBehavior(PlayAudio2, &doPlayAudio2);
  addBehavior(PlayAudio3, &doPlayAudio3);
  addBehavior(PlayAudio4, &doPlayAudio4);
  addBehavior(PlayAudio5, &doPlayAudio5);
  addBehavior(PlayAudio6, &doPlayAudio6);
  addBehavior(PlayAudio7, &doPlayAudio7);
  addBehavior(PlayAudio8, &doPlayAudio8);
  addBehavior(PlayAudio9, &doPlayAudio9);
  addBehavior(PlayAudio10, &doPlayAudio10);
}

int buttonPressed = 0;
long pressedMillis = 0;

void checkButtonPressed(int button)
{
  if (digitalRead(button) == HIGH && millis() - pressedMillis > 1000) 
  {
    buttonPressed = button;
    pressedMillis = millis();
  }
}

void goToState(int s)
{
  state = s;

  for (int i = 0 ; i < numBehaviors ; i++)
    if (behaviors[i].state == state && behaviors[i].func != 0)
      (*behaviors[i].func)();
}

void loop() {
  // put your main code here, to run repeatedly:
  buttonPressed = 0;
  checkButtonPressed(button1);
  checkButtonPressed(button2);
  checkButtonPressed(button3);
  checkButtonPressed(button4);
  checkButtonPressed(button5);

  int lightThreshold = -800;

  int lightValue = analogRead(ldr);

  if (buttonPressed != 0 && lightValue >= lightThreshold)
  {
    for (int i = 0 ; i < numMovements ; i++)
      if ((movements[i].button == -1 || movements[i].button == buttonPressed) && movements[i].from == state)
      {
        goToState(movements[i].to);
        break;
      }
  }
  else if (state != PlayAudio1 && (millis() - pressedMillis > nobody || lightValue < lightThreshold))
    goToState(PlayAudio1);
}

You might want to use the F macro on the strings you're Serial.printing. Also, you've reserved more space for your movements and behaviors that you need. It would be trivial to reduce them for testing purposes.

I have to be honest, I'm not quite sure what that means.
right now since things aren't working perfectly yet I would like to keep the serial printing, would it work more effectively if I were to remove them?

The F macro avoids using RAM for strings. You use it like this:

  Serial.println(F("SD fail"));

Do it to all your debugging prints and you'll see your free RAM at compile time rise. I'm just guessing that you have a memory issue, but it's easy to make these changes to see.

The F macro avoids using RAM for strings. You use it like this:

Do it to all your debugging prints and you'll see your free RAM at compile time rise. I'm just guessing that you have a memory issue, but it's easy to make these changes to see.

okay this did help to some degree where now i do get sound when buttons get pressed etc. however the sound it just really loud static which makes it sound as if the speaker is posessed by demons.
it is still distinctly different static every time but nowhere near what the soundfile actually sounds like.

I tried once again with the test code, this time with a soundfile also used in the other code and that works fine?

#include "SD.h"
#define SD_ChipSelectPin 10
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm tmrpcm;

void setup()
{
tmrpcm.speakerPin=9;
Serial.begin(9600);
if(!SD.begin(SD_ChipSelectPin))
{
  Serial.println("SD fail");
  return;
}
tmrpcm.setVolume(6);
tmrpcm.play("1.wav");

}

void loop() {
  // put your main code here, to run repeatedly:

}

Here's another easy place to save some memory:

const int maxMovements = 64;
Movement movements[maxMovements];
int numMovements = 0;

const int maxBehaviors = 32;
Behavior behaviors[maxBehaviors];

Count up how many movements and behaviors you're actually using and reduce those two constants accordingly.

Count up how many movements and behaviors you're actually using and reduce those two constants accordingly.

still haunted audio unfortunately :frowning:

What are these for?

#include <pcmRF.h>     // kan volgens mij weg, als het zonder werkt
#include <pcmConfig.h> // kan volgens mij weg, als het zonder werkt

Can you test without them?

Can you test without them?

yes i've made those comments by now.
I didn't write this code myself so im not sure what it does but the person who wrote if for me told me those you can get rid of if it works without.
because I was having some problems I un-commented them in hopes of solving the problems but that didn't work unfortunately

is there perhaps another way of creating more memory space for my arduino?

this is the current code; I'm hoping there is still some stuff that can be taken out?

 #include "SPI.h"
#include "SD.h"
//#include <pcmRF.h>     // kan volgens mij weg, als het zonder werkt
//#include <pcmConfig.h> // kan volgens mij weg, als het zonder werkt
#include "TMRpcm.h"
#define SD_ChipSelectPin 10 // ChipSelect op pin 10
TMRpcm music; // TMRpcm heet vanaf nu 'music'

int button1 = 7; // pin 7 connected to button 1
int button2 = 6; // pin 6 connected to button 2
int button3 = 5; // pin 5 connected to button 3
int button4 = 4; // pin 4 connected to button 4
int button5 = 3; // pin 3 connected to button 5
int ldr = A0;  // pin A0 connected to ldr

long nobody = 10000; // 10 seconds

// define application states
enum AppStates
{
  Nothing = 0,
  PlayAudio1 = 1,
  PlayAudio2 = 2,
  PlayAudio3 = 3,
  PlayAudio4 = 4,
  PlayAudio5 = 5,
  PlayAudio6 = 6,
  PlayAudio7 = 7,
  PlayAudio8 = 8,
  PlayAudio9 = 9,
  PlayAudio10 = 10
};

// define behaviors
void doNothing()
{
  Serial.println(F("doNothing")); 
}

void doPlayAudio1()
{
  Serial.println(F("doPlayAudio1")); 
  {music.play("1.wav");} //Play song 1 
}

void doPlayAudio2()
{
  Serial.println(F("doPlayAudio2")); 
  {music.play("2.wav");} //Play song 2 
}

void doPlayAudio3()
{
  Serial.println(F("doPlayAudio3")); 
  {music.play("3.wav");} //Play song 3 
}

void doPlayAudio4()
{
  Serial.println(F("doPlayAudio4")); 
  {music.play("4.wav");} //Play song 4 
}

void doPlayAudio5()
{
  Serial.println(F("doPlayAudio5"));
  {music.play("5.wav");} //Play song 5  
}

void doPlayAudio6()
{
  Serial.println(F("doPlayAudio6")); 
  {music.play("6.wav");} //Play song 6 
}

void doPlayAudio7()
{
  Serial.println(F("doPlayAudio7")); 
  {music.play("7.wav");} //Play song 7 
}

void doPlayAudio8()
{
  Serial.println(F("doPlayAudio8")); 
  {music.play("8.wav");} //Play song 8 
}

void doPlayAudio9()
{
  Serial.println(F("doPlayAudio9")); 
  {music.play("9.wav");} //Play song 9
}

void doPlayAudio10()
{
  Serial.println(F("doPlayAudio10")); 
  {music.play("10.wav");} //Play song 10 
}

// logic
int state = Nothing;

struct Movement
{
  int button;
  int from;
  int to;
};

struct Behavior
{
  int state;
  void (*func)();
};

const int maxMovements = 30;
Movement movements[maxMovements];
int numMovements = 0;

const int maxBehaviors = 11;
Behavior behaviors[maxBehaviors];
int numBehaviors = 0;

void addMovement(int f, int b, int t)
{
  movements[numMovements].button = b;
  movements[numMovements].from = f;
  movements[numMovements].to = t;
  numMovements++;
}

void addBehavior(int s, void (*f)())
{
  behaviors[numBehaviors].state = s;
  behaviors[numBehaviors].func = f;
  numBehaviors++;
}

void setup() {
  // setup, basically some preparations
  
  pinMode(button1, INPUT); // button 1-5 and ldr are inputs
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);
  pinMode(button4, INPUT);
  pinMode(button5, INPUT);

  pinMode(ldr, INPUT);

  music.speakerPin = 9; // audio output on pin 9

  Serial.begin(9600);

  if (!SD.begin(SD_ChipSelectPin)) {
    Serial.println(F("SD fail"));
    return;
  }

  music.setVolume(7); // 0 tot 7, stel volume in
  music.quality(1); //Set 1 for 2x oversampling Set 0 for normal
  
  addMovement(Nothing, button1, PlayAudio2);
  addMovement(Nothing, button2, PlayAudio3);
  addMovement(PlayAudio2, -1, PlayAudio7);
  addMovement(PlayAudio3, -1, PlayAudio7);
  addMovement(PlayAudio7, -1, PlayAudio1);

  addMovement(Nothing, button3, PlayAudio4);
  addMovement(PlayAudio4, -1, PlayAudio8);
  addMovement(PlayAudio8, -1, PlayAudio10);
  addMovement(PlayAudio10, -1, PlayAudio1);

  addMovement(Nothing, button4, PlayAudio5);
  addMovement(PlayAudio5, -1, PlayAudio8);

  addMovement(Nothing, button5, PlayAudio6);
  addMovement(PlayAudio6, -1, PlayAudio9);
  addMovement(PlayAudio9, -1, PlayAudio1);

  addMovement(PlayAudio1, button1, PlayAudio2);
  addMovement(PlayAudio1, button2, PlayAudio3);
  addMovement(PlayAudio1, button3, PlayAudio4);
  addMovement(PlayAudio1, button4, PlayAudio5);
  addMovement(PlayAudio1, button5, PlayAudio6);

  addBehavior(Nothing, &doNothing);
  addBehavior(PlayAudio1, &doPlayAudio1);
  addBehavior(PlayAudio2, &doPlayAudio2);
  addBehavior(PlayAudio3, &doPlayAudio3);
  addBehavior(PlayAudio4, &doPlayAudio4);
  addBehavior(PlayAudio5, &doPlayAudio5);
  addBehavior(PlayAudio6, &doPlayAudio6);
  addBehavior(PlayAudio7, &doPlayAudio7);
  addBehavior(PlayAudio8, &doPlayAudio8);
  addBehavior(PlayAudio9, &doPlayAudio9);
  addBehavior(PlayAudio10, &doPlayAudio10);
}

int buttonPressed = 0;
long pressedMillis = 0;

void checkButtonPressed(int button)
{
  if (digitalRead(button) == HIGH && millis() - pressedMillis > 1000) 
  {
    buttonPressed = button;
    pressedMillis = millis();
  }
}

void goToState(int s)
{
  state = s;

  for (int i = 0 ; i < numBehaviors ; i++)
    if (behaviors[i].state == state && behaviors[i].func != 0)
      (*behaviors[i].func)();
}

void loop() {
  // put your main code here, to run repeatedly:
  buttonPressed = 0;
  checkButtonPressed(button1);
  checkButtonPressed(button2);
  checkButtonPressed(button3);
  checkButtonPressed(button4);
  checkButtonPressed(button5);

  int lightThreshold = -800;

  int lightValue = analogRead(ldr);

  if (buttonPressed != 0 && lightValue >= lightThreshold)
  {
    for (int i = 0 ; i < numMovements ; i++)
      if ((movements[i].button == -1 || movements[i].button == buttonPressed) && movements[i].from == state)
      {
        goToState(movements[i].to);
        break;
      }
  }
  else if (state != PlayAudio1 && (millis() - pressedMillis > nobody || lightValue < lightThreshold))
    goToState(PlayAudio1);
}

if not perhaps there is a hardware way of creating more memory?

I'm quite desperate at this point since my deadline is in 3 days :confused:

There are some minor things - wherever you use a pin, it doesn't need to be an int, byte will do.

I have a slight suspicion that it may not be just memory and that one of your libraries is using a conflicting pin or some such.

I would comment out most of your code and just leave enough for button one and the code that uses it and see if that plays correctly. if it does, add stuff back until it breaks again.

I would comment out most of your code and just leave enough for button one and the code that uses it and see if that plays correctly. if it does, add stuff back until it breaks again.

I've commented a bunch of code now, but it's still incredibly broken. I'm not getting any kind of notifications of what it could be trough the IDE tough

#include "SPI.h"
#include "SD.h"
//#include <pcmRF.h>     // kan volgens mij weg, als het zonder werkt
//#include <pcmConfig.h> // kan volgens mij weg, als het zonder werkt
#include "TMRpcm.h"
#define SD_ChipSelectPin 10 // ChipSelect op pin 10
TMRpcm music; // TMRpcm heet vanaf nu 'music'

int button1 = 7; // pin 7 connected to button 1
//int button2 = 6; // pin 6 connected to button 2
//int button3 = 5; // pin 5 connected to button 3
//int button4 = 4; // pin 4 connected to button 4
//int button5 = 3; // pin 3 connected to button 5
int ldr = A0;  // pin A0 connected to ldr

long nobody = 10000; // 10 seconds

// define application states
enum AppStates
{
  Nothing = 0,
  PlayAudio1 = 1,
  PlayAudio2 = 2,
  PlayAudio3 = 3,
  PlayAudio4 = 4,
  PlayAudio5 = 5,
  PlayAudio6 = 6,
  PlayAudio7 = 7,
  PlayAudio8 = 8,
  PlayAudio9 = 9,
  PlayAudio10 = 10
};

// define behaviors
void doNothing()
{
  Serial.println(F("doNothing")); 
}

void doPlayAudio1()
{
  Serial.println(F("doPlayAudio1")); 
  {music.play("1.wav");} //Play song 1 
}

/*void doPlayAudio2()
{
  Serial.println(F("doPlayAudio2")); 
  {music.play("2.wav");} //Play song 2 
}

//void doPlayAudio3()
{
  Serial.println(F("doPlayAudio3")); 
  {music.play("3.wav");} //Play song 3 
}

//void doPlayAudio4()
{
  Serial.println(F("doPlayAudio4")); 
  {music.play("4.wav");} //Play song 4 
}

//void doPlayAudio5()
{
  Serial.println(F("doPlayAudio5"));
  {music.play("5.wav");} //Play song 5  
}

//void doPlayAudio6()
{
  Serial.println(F("doPlayAudio6")); 
  {music.play("6.wav");} //Play song 6 
}

//void doPlayAudio7()
{
  Serial.println(F("doPlayAudio7")); 
  {music.play("7.wav");} //Play song 7 
}

//void doPlayAudio8()
{
  Serial.println(F("doPlayAudio8")); 
  {music.play("8.wav");} //Play song 8 
}

//void doPlayAudio9()
{
  Serial.println(F("doPlayAudio9")); 
  {music.play("9.wav");} //Play song 9
}

//void doPlayAudio10()
{
  Serial.println(F("doPlayAudio10")); 
  {music.play("10.wav");} //Play song 10 
}
*/

// logic
int state = Nothing;

struct Movement
{
  int button;
  int from;
  int to;
};

struct Behavior
{
  int state;
  void (*func)();
};

const int maxMovements = 30;
Movement movements[maxMovements];
int numMovements = 0;

const int maxBehaviors = 11;
Behavior behaviors[maxBehaviors];
int numBehaviors = 0;

void addMovement(int f, int b, int t)
{
  movements[numMovements].button = b;
  movements[numMovements].from = f;
  movements[numMovements].to = t;
  numMovements++;
}

void addBehavior(int s, void (*f)())
{
  behaviors[numBehaviors].state = s;
  behaviors[numBehaviors].func = f;
  numBehaviors++;
}

void setup() {
  // setup, basically some preparations
  
  pinMode(button1, INPUT); // button 1-5 and ldr are inputs
  //pinMode(button2, INPUT);
 // pinMode(button3, INPUT);
  //pinMode(button4, INPUT);
  //pinMode(button5, INPUT);

  pinMode(ldr, INPUT);

  music.speakerPin = 9; // audio output on pin 9

  Serial.begin(9600);

  if (!SD.begin(SD_ChipSelectPin)) {
    Serial.println(F("SD fail"));
    return;
  }

  music.setVolume(7); // 0 tot 7, stel volume in
  music.quality(1); //Set 1 for 2x oversampling Set 0 for normal
  
  addMovement(Nothing, button1, PlayAudio2);
  /*addMovement(Nothing, button2, PlayAudio3);
  addMovement(PlayAudio2, -1, PlayAudio7);
  addMovement(PlayAudio3, -1, PlayAudio7);
  addMovement(PlayAudio7, -1, PlayAudio1);

  addMovement(Nothing, button3, PlayAudio4);
  addMovement(PlayAudio4, -1, PlayAudio8);
  addMovement(PlayAudio8, -1, PlayAudio10);
  addMovement(PlayAudio10, -1, PlayAudio1);

  addMovement(Nothing, button4, PlayAudio5);
  addMovement(PlayAudio5, -1, PlayAudio8);

  addMovement(Nothing, button5, PlayAudio6);
  addMovement(PlayAudio6, -1, PlayAudio9);
  addMovement(PlayAudio9, -1, PlayAudio1);

  addMovement(PlayAudio1, button1, PlayAudio2);
  addMovement(PlayAudio1, button2, PlayAudio3);
  addMovement(PlayAudio1, button3, PlayAudio4);
  addMovement(PlayAudio1, button4, PlayAudio5);
  addMovement(PlayAudio1, button5, PlayAudio6);
  */

  addBehavior(Nothing, &doNothing);
  addBehavior(PlayAudio1, &doPlayAudio1);
  /*addBehavior(PlayAudio2, &doPlayAudio2);
  addBehavior(PlayAudio3, &doPlayAudio3);
  addBehavior(PlayAudio4, &doPlayAudio4);
  addBehavior(PlayAudio5, &doPlayAudio5);
  addBehavior(PlayAudio6, &doPlayAudio6);
  addBehavior(PlayAudio7, &doPlayAudio7);
  addBehavior(PlayAudio8, &doPlayAudio8);
  addBehavior(PlayAudio9, &doPlayAudio9);
  addBehavior(PlayAudio10, &doPlayAudio10);
  */
}

int buttonPressed = 0;
long pressedMillis = 0;

void checkButtonPressed(int button)
{
  if (digitalRead(button) == HIGH && millis() - pressedMillis > 1000) 
  {
    buttonPressed = button;
    pressedMillis = millis();
  }
}

void goToState(int s)
{
  state = s;

  for (int i = 0 ; i < numBehaviors ; i++)
    if (behaviors[i].state == state && behaviors[i].func != 0)
      (*behaviors[i].func)();
}

void loop() {
  // put your main code here, to run repeatedly:
  buttonPressed = 0;
  checkButtonPressed(button1);
  //checkButtonPressed(button2);
  //checkButtonPressed(button3);
  //checkButtonPressed(button4);
  //checkButtonPressed(button5);

  int lightThreshold = 800;

  int lightValue = analogRead(ldr);

  if (buttonPressed != 0 && lightValue >= lightThreshold)
  {
    for (int i = 0 ; i < numMovements ; i++)
      if ((movements[i].button == -1 || movements[i].button == buttonPressed) && movements[i].from == state)
      {
        goToState(movements[i].to);
        break;
      }
  }
  else if (state != PlayAudio1 && (millis() - pressedMillis > nobody || lightValue < lightThreshold))
    goToState(PlayAudio1);
}

There are some minor things - wherever you use a pin, it doesn't need to be an int, byte will do.

I also did a run where I changed all these ints to bytes without commenting away anything but that doesn't seem to change anything.

byte button1 = 7; // pin 7 connected to button 1
byte button2 = 6; // pin 6 connected to button 2
byte button3 = 5; // pin 5 connected to button 3
byte button4 = 4; // pin 4 connected to button 4
byte button5 = 3; // pin 3 connected to button 5
byte ldr = A0;  // pin A0 connected to ldr

with regards to the libraries
the same 3 libraries are used in my audio testing code as well as in the broken code;

#include "SD.h"
#define SD_ChipSelectPin 10
#include "TMRpcm.h"
#include "SPI.h"