# If negative input ==> 0 V Otherwise, input voltage

I am struggling, and I would like to know how I can make a circuit that holds the following conditions:

1. If the input voltage is negative, then the output should be zero volts.
2. If the input voltage is zero or positive, then the output voltage should be the same as the input voltage.

• (1) What is the input signal? (Volts, amps & frequency.) (2) Where does it come from? (3) What is it feeding into? – Transistor May 25 '16 at 5:50
• It is a DC voltage. – lmiguelvargasf May 25 '16 at 5:51
• You need to answer all the questions otherwise we're all guessing what you want. – Transistor May 25 '16 at 5:56
• 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. – lmiguelvargasf May 25 '16 at 5:58

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.
• Isn't there another alternative? I have checked that diode, and it seems it is not available in my country. – lmiguelvargasf May 25 '16 at 6:10
• Yes, any small signal diode will do. The 1N4148 is available internationally. It is the most popular small signal diode. – Transistor May 25 '16 at 6:11
• you are right! I am so sorry. – lmiguelvargasf May 25 '16 at 6:13
• Precision rectifier op amp configuration satisfies the 0V requirement. – Chu May 25 '16 at 13:36
• @imiguelvargasf: See my update. – Transistor May 25 '16 at 17:11

What you are looking for is a rectifier, if the voltage drop of the diode is of no importance ,then this circuit will do the trick. simulate this circuit – Schematic created using CircuitLab

But, if you want to compensate for the voltage loss over the diode you'll need an Opamp . simulate this circuit

• Wouldn't a (R2R) opamp without the diode do if the negative voltage is connected to GND? – glglgl May 25 '16 at 7:19
• The problem with circuit (1) is that you have the diode drop on VIN. That is why I suggested the opposite (resistor on VIN, diode on GND). It has generally less side effects to alter the GND limit than the input voltage itself. – dim May 25 '16 at 7:25

There is a very simple solution, but whether this works will depend on

• the input impedance of the subsequent circuit
• the output impedance of the previous circuit
• the fact you can tolerate a small amount of remaining negative voltage (~0.4v).

You can put a resistor of about 1-10k between the input signal and the cathode of a diode (preferably schottky, like BAT54) with the anode of the diode tied to ground. The output signal will be taken between the resistor and the diode.

If the impedances/remaining negative voltage is a problem, a more complex solution would be to use an active device like an opamp, but I'll let someone else suggest this.