# Solution for accepting 3-24v as digital high for microcontroller

I'm after any suggestions for converting a digital input in the range of 3-24vdc to a 3.3v signal for a microcontroller.

I need to handle a total of 32 inputs (each of which could vary anywhere between those voltages), so density is more important than cost.

Someone suggested a non-inverting hex buffer like TI's CD4050 (http://www.ti.com/lit/ds/symlink/cd4050b.pdf) might be the solution, but I'm not entirely sure if it will handle multiple different input voltages.

EDIT: The inputs will be connected to either:

1. Various mechanical switches which may pull the line to GND or to a voltage anywhere in the given range of 3-24v

or

1. Sensors of various types with digital outputs. Those outputs could be low (gnd) or high with voltages that could be anywhere in the given 3-24v range, depending on the type, make and model of the sensor.

Any of the inputs could be connected to any type of switch or sensor within the limits specified above.

EDIT 2: Multiplexers and the like are unfortunately not possible as timings are VERY tight and interrupts of varying priority are to be used extensively which requires direct connections to the microcontroller pins.

• Did you read that datasheet? – Chupacabras May 1 '17 at 5:17
• How about a 10:1 voltage divider and a comparator? – uint128_t May 1 '17 at 6:07
• There could be lots of system design issues here. How are the sensors powered? Could they be powered when the micro isn't? Because that will require special treatment if that is the case. Etc. – mkeith May 1 '17 at 6:39
• How about a large value resistor, and a low-drop diode to the 3.3 v rail. This will read high for any voltage > 2.5 V. Use a much larger pull down resistor so even 3 V input still exceeds the logic threshold. – tomnexus May 1 '17 at 7:03
• Such sensors are common on PLCs. Opto-isolated inputs are are the most common robust solution to the task you have described. The 3V input requirement requires careful component selection 5V is more common and much easier to achieve. Follow some of the links on this image search. - google.com/search?q=3V+24V+opto+isolator&tbm=isch – KalleMP May 1 '17 at 15:33

You could use dual pre-biased transistors (16 required). If the MCU has suitable internal pullups you would not require any other parts. R1/R2 of 22K/22K or 47K/47K could be suitable. The input voltage rating is -10V to +40V for those values.

They're about 2mm x 2mm, so they don't use up much board space.

• Thanks for the suggestion @spehro-pefhany. I think this will probably do what I'm after. Components have been ordered and I'll start testing tomorrow. Thanks again. – Lachlan Fletcher May 2 '17 at 13:07

simulate this circuit – Schematic created using CircuitLab

With pull-up resistor input voltage microcontroller is HIGH. No matter what is voltage on 3-24V input. Except on 3-24V input voltage below the threshold microcontroller input. (including the forward voltage across the diode). In this case, the diode passes current and the input of the microcontroller is LOW.

• The major problem here is that the MCU input will have a Vinput(Low) of < 0.8 V typically, so to pull the input to a guaranteed low you have to have extreme low voltage (even if you use a Schottky diode) of < 0.6 V or less on the sensor side. That will be hard to achieve. – Jack Creasey May 1 '17 at 16:31
• @Jack Creasey, you are right. If I understand the question these requirements are met. And Schottky diode version with less demanding than the version of the FET. And diode to protect the microcontroller when it is no supply voltage. – AltAir May 1 '17 at 19:18

Since your voltage range is so high I think you could achieve a good result with a single N-Channel FET. There are FET's available that have V(GS) ratings above 24 V ....here's one that has a 40 V rating: 2n7002. You can even get FETs in an array, though it's a bit tougher to find them with high V(GS) ratings.
You could also use the newer FETs such as the NTJD5121NT1G, these have Gate ESD protection diodes built in and you could use this to clamp the input with only a series resistor. You can see from the datasheet that the ESD protection is beginning to conduct at the gate rating of 20 V.

simulate this circuit – Schematic created using CircuitLab

The V(GS) transfer curve is:

This should provide an input high of about 1.5 to 24 V. Low would need to be below 1 V input.

No matter what you do for 32 inputs you are going to need at least 32 resistors (if you want high impedance inputs) and probably 16-32 SMD packages, so significant board space is going to be required. You could consider an HV5622 and use a serialized reading method as I proposed here. The sense input could be re-arranged to use a single comparator. This reduces PCB complexity, but it's still a layout job with lots of tracks. The nice thing about serial acquisition is of course it/s easy to separate the acquisition board and isolate from the MCU.

• Thanks for the excellent detail in your answer Jack. I think this solution would definitely work, however for 32 individual inputs I think the circuit might get a little complicated and take up a bit too much board space. – Lachlan Fletcher May 1 '17 at 9:11
• @LachlanFletcher You can also get pre-biased transistors which have the resistors integrated into the package. These come in dual packages so you could get by with 16 of these. Look at something like the NXP PUMH range. – Jon May 1 '17 at 10:22
• This one will of course may not work if $V_{OL}$ max > 1.022V which is not atypical for 24V sensors and definitely will not work if $V_{OL}$ max > 2.555 which is also not unheard of. – Trevor_G May 1 '17 at 13:37
• Add to Jack's answer the possibility of a 36V 16 channel multiplexer and you can simply scan the inputs. That would require the power to be at or above the maximum expected input voltage though; ti.com/product/mux36s16 – Peter Smith May 1 '17 at 14:35
• @Trevor. You can of course select the FETs with any V(GS) threshold you want, I simply selected one of the newer very low threshold devices. – Jack Creasey May 1 '17 at 15:45

the simplest would be to use a large resistor for each of the input. the clamping diode on the input pin + that resistor will do a fine job.

alternatively, use a resistor + a 3.3v zener.