I want to share with you what drove me crazy for a few days.
I connected a button to a digital input (with a pull-up resistor), and when I connected the Arduino UNO via USB, everything worked fine. The application generates sounds, and I connected a 12V DC power supply to an audio amplifier while also powering the Arduino with 12V DC.
Then, strange things started happening—the digital input would trigger randomly. I even disconnected the wire from the button, and the input would still activate on its own unpredictably. After spending a few days debugging the software, I thought the issue might be with the power supply. I switched the 12V DC power supply to a more powerful one, and everything was fixed!
Apparently, the amplifier was drawing too much current, leaving too little for the Arduino. I hope this helps others too...
Regards
Salmec