Best way to get 5v or 12v or 0v from arduino pin
Let me expand on the answer to that previous question with a similar circuit that uses two inputs. One input selects what the output voltage swing would be. This is the VOLT_SEL input which selects 0-5V or 0-12V operation. The other input SIGNAL determines if the output will be at 0V or the selected high output voltage. This scheme eliminates the need to worry about how to protect separate driver circuitry that would connect to the load. The zener diode in the circuit is a 6.8V device.



This shows the simulation voltage waveforms.