Induced power supply noise on switch contact
What does this switch activates ? Make sure you are seeing the switch effect and not some trigerred actions by the switch.

You can use an L-C filter at the pedal, those are much more effective at handling high frequency noise than a R-C filter. You can also use L-C filter after your power supply.

Make sure your 24V supply is stable.

You can also add decoupling capacitor between the high side of R2 and GND and keep R2 near U1 and far from the MCU.

You can also increase R2, and add a 10nF capacitor on the reset line of the MCU.

You can use a shielded cable for your pedal to avoid having it as an antenna.

While those might help solve your issue, it is likely that you have some layout issue on your design. Make sure the ground plane if fine and that there is no bottleneck at some point.







simulate this circuit &ndash; Schematic created using CircuitLab