Maybe I don't quite understand how zener diodes work but, I thought that they would block a reverse voltage until it reached a certain threshold (the zener voltage) and above that, they would allow the current to flow. This diagram shows my circuit:
When the switch is flipped to 5v, I would expect Vout = ~0v because current would flow through D1 instead of R1, but instead I get Vout = ~3.5v.
When the switch is flipped to 3v, I would expect D1 to block the current and so Vout = ~3v. I get Vout = ~2.7v which is close enough.
I don't have a zener diode to test this with a physical circuit. I wanted to simulate it first so I would know what parts to get. I have tried it in both iCircuit and CircuitLab and both produce the same results.
I also tried putting the zener diode directly between SW1 and Vout like this:
This gets me sort of what I expected. When switched to 3v I get Vout = ~0v but when switched to 5v, I only get Vout = ~1.2v.
How do I get Vout closer to 5v when switched to 5v?