Can Arduino forget the code somehow ?

Hi guys. Apologies if this is not the best forum section to ask this question, but I found this one to be the most fitting.

I finished recently a project for "room escape" and it involved opening door when secret code is knocked on door. I used Arduino Nano (old bootloader) for the project and, among other things, piezo to detect knocking. Arduino is placed inside door frame (inside moving part of doors).

The project was working okay when I left it.

After a few days a worker was painting doors and Arduino stopped working after that. Not that it died, but it "forgot the program" somehow ... It seemed as if Arduino would restart half a second after setup() function, it would restart and do it again, no matter how many times we turned it off and on again.

We left a USB communication on top of doors, so I re-programmed arduino, and it started working again.

What could've caused such a problem ? I want to leave a project that is working, and not have to go back there every now-and-then just to re-program arduino. I've left some hardware specifics down bellow. Let me know if you need schematics, I can draw them as well. Unfortunately, measuring anything would be impossible, because the board is closed in doors, I only have access to USB for programming.

As you will see from specifics, I tried to make the hardware as safe (for arduino) as possible.
Some specifics:

  1. The power and connection to door lock is done on top of doors through springs. When doors open, springs detach from door frame and arduino looses power. Once again, Arduino is INSIDE the door.
  2. Input voltage is 12v.
  3. I use relay to lock/unlock door lock. Door lock are run on top of doors, next to 12v for power (using same mechanism with springs). I did use flyback diode (silicone) across relay.
  4. I use piezo connected to analog pin. I have a resistor (can't remember the value, i think it is 100k) across it. One side of piezo is connected to ground and other is connected to silicone diode, which is connected to analog pin.

I have 2 possible explanations for such behaviour:

  1. Maybe a hard hit on doors happened (when either it was on or off) and piezo generated a really high voltage
  2. Before I re-programmed the Arduino, spring contacts for Arduino power were not very good, so when closing/opening doors, Arduino could lose/get power several times per second. But could those restarts make Arduino permanently forget the program ?

I also attached my crude schematics project, but let me know if you need more detailed schematic. Empty header on the right was supposed to be NRF, but I never really added it. (full image url: Dropbox - 20200714_131835.jpg - Simplify your life )

Lose connections guarantee unknown results. There are a lot of ways it could lose some memory. With loose connections there is no way to my knowledge to determine exactly what happened. I assume it is working fine now.