# Two-way voltage limiting circuit to protect microcontroller

I am making a device with a micro controller that has a single exposed pin that needs to be able to function as either an input or an output based on the software. When in OUTPUT mode, there has to be at least 1kΩ impedance so it can't get shorted. When in input mode, I have to limit the incoming voltage. The external voltage could be ±10 V but the micro controller can only handle 0 - 5 V. This port will carry a digital signal so it does not need to care about the analog value. It just needs to transmit HIGH and LOW states effectively (around 0 V and 5 V).

My current solution looks like this:

simulate this circuit – Schematic created using CircuitLab

It works perfectly in OUTPUT mode, and it is almost perfect in INPUT mode, as long as the input is capable of sinking current. But, if I leave the input floating, the micro controller's side is pulled HIGH (I want it to be LOW by default).

My first thought was to add a pulldown resistor on the input, but it then works as a voltage divider in OUTPUT mode, reducing the voltage. If I put a small enough pulldown resistor to counteract the pullup force on the microcontroller side, then the output is reduced enough to no longer register as "HIGH".

Is there any relatively simple way I can fix this problem? Or is there a better type of circuit to use for this purpose? Maybe something based on diodes would be simpler?

• Does your circuit really use a pnp transistor? Please show the full interface circuit - you mentioned a 1k resistor feeding to the raw output node and I’m unsure how that works in what you have shown. Also, be aware that reversing the base emitter junction by 10 volts may exceed the rating for the transistor. Commented Mar 30, 2021 at 20:38
• You say "output mode", but where is the output going? 0-5V or another +/-10V? Commented Mar 30, 2021 at 20:41
• @Andyaka Yes, I was using a PNP transistor but I had it in upside down in the diagram. My mistake! Commented Mar 30, 2021 at 20:49
• @DKNguyen The output will be connected to another device that I don't have control over. I only need to output 0-5v but the receiving device could connect it to +/-10v if they wanted to Commented Mar 30, 2021 at 20:51
• Understood. You should edit that into your post. Commented Mar 30, 2021 at 20:52

Maybe something like this:

simulate this circuit – Schematic created using CircuitLab

This typically clamps at about -300mV/5.1V and does not depend on the 5V supply sinking current.

All modern microcontrollers have ESD protection on all I/O pins, that can handle +/- 2 kV fast transient pulses.

You only have to protect those I/O pins from constant voltages like +12 VDC or +24 VDC.

If you could add a resistor of 10 k Ohms in series to that pin then you will not have problems. In fact, a voltage source of +24 VDC with 10 k Ohms resistor in series won't hurt.

I have in my lab an EFT tester and, time ago, I made all these kind of tests.

10 k Ohms in series will also prevent your I/O pin from going in latch-up state.

In some applications one can't add a 10 k Ohm resistor in series to the I/O pin. In those cases one may add an external bidrectional TVS diode, like NXP PESD1CAN, or a bidirectional Zener diode.

Cables protect a lot from EFT or Surge transient voltages. The longer the cable, the better is the protection. The distributed capacitance of cables acts like an excellent low pass filter that attenuates and smooth peak voltages.

I did a lot of these kind of measurements with my EFT instrument. I always set it to +/- 4 kV which is the requirement for industrial environments. The instruments has an output resistance of 50 Ohm as required by the norm.

After many tests, I decided to buy NXP PESD1CAN.

I got no affiliation to NXP.

• The voltage may exceed the safe range for an indefinite period of time in this application. Just to be clear, are you saying that just a 10k resistor is enough to protect the microcontroller from that voltage? Commented Mar 30, 2021 at 21:26
• Yes, I'm. The voltage absolute maximum ratings are meant without a limiting resistor. I'm saying that 10 k Ohm are enough to protect the pin from EFT +/- 2 kV and from +/- 24 VDC for an unlimited period of time. I would use a 0805 or 1206 resistor package and/or look for a resistor that stands at least 50 VDC. Commented Mar 31, 2021 at 4:09

Can you not use something like this?

D1 clamps the voltage to 5V+Vd. D2 clamps the voltage to GND-Vd.

So +10V becomes ~5.3V and -10V becomes ~-0.3V. 0-5V signals are unaffected.

simulate this circuit – Schematic created using CircuitLab

You might want the Zener to clamp the voltage if the +/-10V signal is powered but the 5V is not.

20mA sinking current is a bit excessive though. I'd increase R1 and R2 to 5K or 10K. 20mA of current is definitely going to cause problems if 5V is unpowered and the +/-10V signal is sending 20mA to your power rails without the zener.

• OP wants 1k output impedance. Make those both 470 Ω and make the diodes Schottky to reduce the negative voltage a bit more. Add in 100 kΩ in parallel with D2 to give the pull-down when input is floating. Commented Mar 30, 2021 at 20:43
• @Transistor I'd personally increase the resistance 10-20x so Schottky doesn't need to sink 20mA when clamping. Commented Mar 30, 2021 at 20:46
• It seems like this might be the most straightforward solution. I would like to avoid syncing a lot of current if possible but I don't think it's a problem to just increase the impedance. I've never seen diodes used before in this particular application and I'm not really sure why. I assumed people were avoiding them for some reason but maybe not. Commented Mar 30, 2021 at 21:03
• @QuinnFreedman D1 and D2 are in virtually every CMOS chip to protect against ESD. Also, "syncing" is short for synchronization. You mean sinking. Commented Mar 30, 2021 at 21:04