# How to read a higher voltage digital input?

Lets suppose I have a circuit with a car battery, a switch and a led. The led will turn on when the switch is closed, and turn off if it's not. I want to remove the led from the circuit and put an Arduino in that place to "read" when the circuit is closed or open.

I'm a good programmer, so the code is not the real problem. I only want to know how to do this without damaging the board.

How can I do this?

• Lookup voltage dividers. Nov 9, 2015 at 18:44
• @Gerben What should be the destination voltage to enter into a digital input pin on the arduino? 5v? Nov 11, 2015 at 1:29
• 5v indeed. But I'd leave a bit of margin. Nov 11, 2015 at 15:50

As @Gerben says, voltage dividers are a good place to start. To elaborate on the topic, you can use a combination of voltage dividers, zener diodes and clamping diodes.

First off, a voltage divider circuit is easily found on the internet,

This circuit from Hyperphysics shows the basics: To add more protection to this so as not to go over the max I/O voltage of the MCU, you can add a zener diode on the Vout. That would give you something like this(Olins): This will give you the desired range to give legitimate High and Low on an I/O.

If you wanted to forgo the voltage divider and zener you can use clamping diodes to the microcontroller supply voltage Vcc. This will give a range that will not damage the I/O. simulate this circuit – Schematic created using CircuitLab

The 10k resistor is there to limit the current through the diodes, which are Schottky diodes.

Another method, which I have used before and is reliable, is to use a diode and two resistors like below: The logic is that, when the input `IN` is > Vcc(5V) the signal on the I/O `_IN` will be the voltage of the pull_up resistor `R2`, if it is low or floating the signal will be low. R1 also gives a known logic state if the input floats.

Edit: Changed the image to proper logic flow.

• Be careful that the IN and _IN pins in the last circuit are "logically" swapped, i.e. the signal goes RIGHT to LEFT: IN is the input, _IN is the microcontroller Dec 1, 2015 at 15:28
• @frarugi87 - I copied it straight from a schematic I'm working on(makes sense to me, as I did it ;)), thanks for pointing it out, I will edit it tomorrow when I get a chance.
– RSM
Dec 1, 2015 at 15:39
• Of course, but it took me a while to understand it ;) anyway thank you for sharing, I'll tkeep it in my mind next time I'll need this kind of converters ;) Dec 1, 2015 at 15:54