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?

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

1 Answer 1


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.

This EE.SE post has some good info about this, related to ADC, but still the same.

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

  1. Google
  2. Wikipedia

This circuit from Hyperphysics shows the basics: Hyperphysics

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):

credit to Olin

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:

enter image description here

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.

  • 1
    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
    – frarugi87
    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 ;)
    – frarugi87
    Dec 1, 2015 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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