I am looking for a way to protect my Arduino's digital outputs from unwanted, outside voltages. My project uses about 20 different outputs, each connected to a wire (run) that can range from 20 to 100 feet (I used cat5 cable, with each inner wire (randomly chosen) dedicated to a single digital in, out, +5, +9 or ground.) There is a good change that outside voltages could impact these digital outs (or any other pin or power wire.)

I have a good resource on protecting digital in's but I ma not sure how to protect the digital outs. Each needs to be able to both pull a connect component to ground, and push it up to 5 volts (am I saying this correctly?)

This should be able to protect the digital outs from shorts or 12v spikes.

How can I build this circuit?

Edit: it is difficult for me to describe this problem without mentioning the danger to all components.

Note that ways of protecting digital inputs is HERE.


Some good results you can get with optocouplers. PC817 photo

It's electrically disconnects one part of your circuit from another.

For example, here is my IoT-ish device, which is detects water leaks in my bathroom: Scheme

I use the transformer (T1), which have two separate output windings, so, that windings does not connected electrically, only magnetically. The block in border "Sensing unit" doesn't have any wires with other scheme - only magnetic field, which is gives it power, and infrared light in the optocoupler (u2, PC817), which informs ESP01 about leak presence.

How does it work? Very simple! When the water shorts JP1 (long naked wires on the floor), Q1 opens and lights-up the IR diode in PC817. Light from this diode opens another transistor - and pulls the RxD PIN of ESP01 down.

Small sketch, written on Arduino for ESP8266 periodically sends pin state by HTTPS on my web server, where monitor software, Nagios, checks the information age and the pin state, and send to me notifications, when something goes wrong.

  • Can you add a bit more detail please? This is basically a link-only answer that says the link will solve your problems. – Nick Gammon Nov 3 '15 at 4:41
  • @NickGammon - Done! – gbg Feb 7 '20 at 7:46

Add a resistor in the circuit to limit the current in case of a short.

Add clamping diode to prevent voltages higher than 5v (combined with the resistor from before). The AVR has internal clamping diodes, but those can only handle very little current. Since you are running such long wires, you probably need to add the lowest value resistor, to limit noise.

PS The possibility of have a external voltage applied to an output sound pretty troubling to me.

  • 1
    The possibility of have a external voltage trouble me too. My circuits are accessible to other 'technicians' who disconnect / reconnect them without powering down everything. There is a very real chance that a 12 volt wire will touch a digital in, digital out, a 5 volt supply wire or the Arduino's ground. I have discussed this with them and the boss, and the response is to build a circuit that will not be damage by such things. – Hoytman Jul 4 '15 at 19:42
  • Just add a 220v wire. That way they are required to power everything down. That will protect the rest of the circuit from idiots messing with a powered circuit. q-: – Gerben Jul 4 '15 at 19:52
  • Would love to, but the Arduino is a part of a drama stage, so the techs have to be really fast and really safe. – Hoytman Jul 4 '15 at 21:52
  • Related to: best way to protect a digital or analog input from 12volts by @Hoytman – Nick Gammon Jul 4 '15 at 21:54
  • 1
    The configuration mentioned in the other thread, which has a 1 k resistor in series with the signal, won't work so well for an output. For a start, due to Ohm's Law, it would limit the amount of current it could source, or sink, to 5 mA. If the output is just something like a serial port, that may not matter. If you are trying to turn on a relay or LED, you may find it a limitation. – Nick Gammon Jul 5 '15 at 1:51

Check with your favorite automotive semiconductor supplier such as ST. In there automotive listings you will find drivers that will do exactly what you want and if shorted to long will shut down and come back when the short is removed. I am not going to make a recommendation as there are literally hundreds of possibilities. These come from 1 driver per unit to 8 that would be easy to purchase. They have parallel and serial interfaces depending on what you want. If you want to be nasty get a 50 amp driver and put a huge power supply behind it, then enjoy the looks and smoke when shorted and you get the last laugh your Arduino will be OK. Have Fun!


See 10 Ways to Destroy An Arduino

One of the suggestions there for output pins was:

Put a 30mA resettable fuse (PTC) in series with every I/O pin. Not only is the current safely limited to 30mA under all conditions (more on this below), but the built-in 220 ohm resistance of the fuse naturally limits the current to 5V/220 = 23mA right off the bat.

You may also want to look at some of the suggestions on the question about protecting input pins which could help with keeping spikes out of the output circuits.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.