Protection for -/+12V signal into Arduino digital input

I need Arduino to read a digital value from an input signal that can be anything from -12V to 12V. Everything below ~3V should be read as LOW, anything higher as HIGH.

I found many topics here about input protection from over-voltage or negative voltage, but nothing I found looks working in both cases, and often it is assumed the input signal values are known, i.e. 0V, 10V, so you'd just need a voltage divider, for example.

So I thought about using a transistor instead. I had some BC337 amplifier NPN, so I tried this:

R1 is for limiting input current, R2 is a pull-down resistor. I found the diode necessary because the emitter starts outputting low negative voltages when the input signal is strongly negative.

I used a multimeter to check the voltage at the emitter, before going into Arduino, and looks just fine in any condition from -12V to +12V. The voltage stays at 0V when the signal is -12V-0V, then goes up with it, and stays at 5V when signal is +5V-12V.

My question is, do you see any drawbacks or problems with that? I don't want to break my Arduino, so I want some feedback before connecting the board. Thanks!

I'd have skipped the transistor and just used a diode with a resistor divider but I'm a cheapskate :slight_smile:

Two diodes and a 22k resistor.

saximus:
I'd have skipped the transistor and just used a diode with a resistor divider but I'm a cheapskate :slight_smile:

But this way you won't read HIGH values when input signal is, for example, 4V or 5V. A divider that "converts" 12V max into 5V max, will convert 4V and 5V to ~2V, below the threshold for reading them as HIGH on Arduino... Right?

Paul__B:
Two diodes and a 22k resistor.

How?

joeSeggiola:
How?

The input pin has protection diodes which are apparently rated to take up to a milliamp. A 22k resistor in series will limit current from a ±12 V source to no more than half a milliamp, but as some backup protection, a diode from the input pin "pointing" to the 5 V rail and one "pointing" from the ground to the input pin will limit the current seen by the chip protection diodes. If you want further protection, two 10k resistors in series with the input pin and the diodes connected to the mid-point of the two resistors.

Paul__B:
The input pin has protection diodes which are apparently rated to take up to a milliamp. A 22k resistor in series will limit current from a ±12 V source to no more than half a milliamp, but as some backup protection, a diode from the input pin "pointing" to the 5 V rail and one "pointing" from the ground to the input pin will limit the current seen by the chip protection diodes. If you want further protection, two 10k resistors in series with the input pin and the diodes connected to the mid-point of the two resistors.

I mean, why not just use an optocoupler? Probably would be easier and more reliable.

I would
1)
connect the emitter to GND.
2)
R2 between 5V and the collector; collector will be the output to the Arduino.

When reading the pin, the logic will be inverted but that is simple to solve in the software.

If you omit R2, you can use the internal pull-up.

A 22k in series limit the current and internal diodes clamp the voltage.

sterretje:
I would

  1. connect the emitter to GND.
  2. R2 between 5V and the collector; collector will be the output to the Arduino.

When reading the pin, the logic will be inverted but that is simple to solve in the software.

Cool thanks. What are the advantages of that? Does it solve some issues?

I tried that, it prevents negative and over-voltage on the Arduino pin, but the reading is not only inverted, but scaled differently. Anything above ~0.6V will be seen as zero, but I need a more even threshold, like the usual 2V-3V. Also, I'll use the same technique in other circuits, where I'll read the value on an analog input, so the near-linearity of my approach (reading from the emitter) looks preferable.

Paul__B:
The input pin has protection diodes which are apparently rated to take up to a milliamp. A 22k resistor in series will limit current from a ±12 V source to no more than half a milliamp, [...]

Datman:
A 22k in series limit the current and internal diodes clamp the voltage.

Nice, I didn't know there are protection diodes already in there, thanks. I'm using a Nano with ATmega328, is it the same?

Yes, all ATmega controllers have these clamping diodes.