# Digital read on voltages between 1 and 31 volts?

Hello Arduino comunity!

I am working on a circuit that uses an Arduino Mini to read values from certain points of a boost/buck converter circuit to determine things like input state, output state, overheat and so on. The circuit is working all right, and the only part left to do is to connect the digital pins of the Arduino to the different points in the boost/buck regulator.

The problem is however that I need to read from a range of voltages between 1 and 31 volts with the Arduino, which isn't possible, because not only will it damage the controller if the voltage exceeds 5V, but values below 3V will be regarded as false.

I thought of putting some potential dividers, which would obviously not do the trick, and I also thought of using a WS78L05 voltage regulator per input pin (because each pin might have a different voltage from the rest) but that isn't dealing with voltages <=5V and 31V exceeds its rating as well.

Lastly I thought of using transistors, which seemed like a good idea, but I would require 2 transistors per input wired as follows: simulate this circuit – Schematic created using CircuitLab

But it is impractical to do for 4 inputs and there is limited space available on the PCB too :(

Is there any IC that encapsulates the circuit above, or is there any other way to achieve what I want to do?

Thanks very much :)

• First you need to look at each individual input and what exactly it is sensing, and what those voltages mean. Then you can work out what you need for that input. Don't try and make a "one solution fits all" system, unless all your input sense the same thing.
– Majenko
Jan 7 '17 at 14:14
• @Majenko Not trying to find a 'fit all' situation. The thing is that the output can either be on, or off therefore 1 or 0. If the output voltage is 10V or if it is 31V makes no difference, the output is open (1) whereas if the voltage in the output is 0V it means that the DPDT switch before it is off therefore the output is closed. Thats what im trying to sense. Same aplies for the input and the overheat switch (it is a 65C thermal switch. if it is off then there is overheat, if it lets n volts through then its alright) Jan 7 '17 at 14:26
• So a voltage divider sized to cope with the highest voltage you want to sense, fed into an analog input. You then read the value and compare it to a threshold for on or off.
– Majenko
Jan 7 '17 at 14:29
• @Majenko Well the potential divider i thought of consists of a 51k and a 10k resistor (we dont need much current) at 31V it produces 5.082V which is alright, however at 1V it produces 0.16V which would be hard to sense and would very easily provide false-trigers... Not to mention that it would probably drop even further with a pulldown resistor :( Jan 7 '17 at 14:36
• 0.16V would read 32 on the ADC. That's plenty, surely? If you want more, then size your divider a little higher (say 7V) and clip it with a 5V zenner diode?
– Majenko
Jan 7 '17 at 14:43

Using a simple voltage divider (51K / 10K as you have worked out already) fed directly into an ADC input will give you a reading of 32 on the ADC at 1V input. That should be enough to give a reliable threshold detection.

If you want to have higher sensitivity at lower voltages you can increase the output of your voltage divider to more than 5V and then clip it with a zenner diode. For instance if you reduce the 51K to 33K you get 7.2V out of the voltage divider. A 5V zenner diode can then clip it to 5V. Your 1V input (which would be 0.233V on the output of the divider) would now read 47 on the ADC. Anything over 21V would then read 1023. simulate this circuit – Schematic created using CircuitLab

Theoretically you could get away with not having the voltage divider at all and just using the zenner and one resistor to clip the incoming voltage to 5.1V. That would give you the greatest sensitivity, but also the greatest current flow through the zenner. simulate this circuit

Size R1 to limit the current at your maximum voltage to within the rating of the zenner.

• Thanks for the response, it does make sense but i dont think that i can manage all those in the tight space i have :S 4 input pints that need voltage regulation (they are one next to the other) and the space in which i need to fit all that is small (it has to be to fit in the enclosure as well) Also which of the two designs above is going to be the one with the least drop when 1V is in the input? Also isnt there any IC you are aware of that holds the two transistors in the arrangement i showed above? Lastly, it just poped in my mind to use optocouplers. Would that be possible and effective? Jan 7 '17 at 15:06
• Why do you use a zener, instead of clamping the voltage to the 5V rail with a regular diode? Jan 7 '17 at 15:07
• @Gerben Because it gives less noise on the power rail that way. With a regular diode it takes time to switch from reverse to forward bias and you get spikes of noise on the power rail while it is doing that. With a zenner it breaks over at its rated voltage and limits the voltage without needing to switch from reverse to forward bias.
– Majenko
Jan 7 '17 at 15:09
• @fillpant The second design will give you 1V out when you put 1V in. It will give you 3V out when you put 3V in. It will give you 5.1V out when you put 6V in. It will give you 5.1V out when you put 31V in. It doesn't scale the voltage, it clips the voltage. Anything above 5.1V is thrown away as heat in the resistor.
– Majenko
Jan 7 '17 at 15:11
• @fillpant Opto couplers are possible, yes, but I would have thought a resistor and zenner diode would be the smallest possible footprint. Especially in SMD formats.
– Majenko
Jan 7 '17 at 15:11

Use two quad lm339 voltage comparator chips to make an analog to digital convertor-you will need 2 to read 31 volts accurately. Its a standard ADC circuit, with this common lm339 is, so a search will find circuit-it may need a simple modification to combine the two circuit.

The junction of a 51KΩ, 10KΩ voltage divider will feed an Arduino ADC input 5.08 V at 31 V input, and 0.16 V at 1 V input. With a 5 V reference, I think the first of those will give 1023 counts, and the latter, 33 counts. This is from 1023*(1/5)*10/(10+51) ≃ 33.54. That may be enough counts for reliable detection, depending on how noisy the environment is.

For more sensitivity at lower voltages, if the first reading is less than 225 counts, one can switch to the 1.1 V internal ADC reference and take another reading. (1023*1.1/5 ≃ 225.06.) With a 1.1 V reference, a 1 V input to the divider produces 152 counts, and a 6.7 V input produces about 1023 counts. (1023*(1/1.1)*10/(10+51) ≃ 152.46 and 1.1/(10/61) ≃ 6.7.)

To change the ADC reference voltage, say `analogReference(DEFAULT)` for Vcc reference, or `analogReference(INTERNAL)` for 1.1 V reference.