Protect a micro controller even on mistakenly connected
Use a bridge rectifier before your 12 V to 5 V regulator.







simulate this circuit &ndash; Schematic created using CircuitLab

Figure 1. The bridge rectifier BR1 will rectify (as in "correct") the voltage so that input polarity does not matter.