Code is randomly getting stuck in a particular function

an int can't be 45000 on an Arduino UNO (int are on 2 bytes, signed, so the max value is 32767 and then you roll over).... so your delay is not 45 seconds anymore

why do you need to be stuck there for 45 seconds before playing a sound ?

you might benefit from studying state machines. Here is a small introduction to the topic: Yet another Finite State Machine introduction

1 Like