The simplest circuit:
simulate this circuit – Schematic created using CircuitLab
Figure 1. Single diode rectifier.
- The diode will conduct when Vin > Vout.
- The diode will block when Vin < Vout.
Whether this is suitable for your application depends on whether you can tolerate a 0.6 or 0.7 V drop across the diode as well as any factors you haven't told us.
Sorry, (1) it is a DC voltage, (2) It comes from the output of an operational amplifier which compares two voltages. (3) It will be sent to a microcontroller pin.
Use @dim's circuit:
simulate this circuit
Figure 2. GPIO interface for bipolar signal. Use (a) when Vin ≤ Vcc. Use (b) if Vin ≥ Vcc.
Let's say that Vin is 15V. Isn't it dangerous to send that voltage to the GPIO?
Yes. We wouldn't connect 15 V directly to the input. If Vin ≥ Vcc then use Figure 2(b).
- If Vin goes above V+ then D3 shunts the current to V+ and R2 limits the current to around a milliamp.
- Between 0 and V+ the diodes don't affect the circuit.
- Below 0 V D2 conducts and prevents the GPIO seeing any less than -0.6 to -0.7 V.