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?
-
2Lookup voltage dividers.Gerben– Gerben2015年11月09日 18:44:57 +00:00Commented 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– Guilherme2015年11月11日 01:29:34 +00:00Commented Nov 11, 2015 at 1:29
-
15v indeed. But I'd leave a bit of margin.Gerben– Gerben2015年11月11日 15:50:15 +00:00Commented 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,
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):
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.
schematic
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.
-
1Be 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 microcontrollerfrarugi87– frarugi872015年12月01日 15:28:02 +00:00Commented 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– RSM2015年12月01日 15:39:33 +00:00Commented 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– frarugi872015年12月01日 15:54:37 +00:00Commented Dec 1, 2015 at 15:54