Feeding +12V into digital pins

Hi all!

I'm asking you for advice to bridge the electronic sides of my project. Two light barriers will be polled for objects passing the lights, when an object passes and triggers a barrier, the barrier provides +12V on one of it's connections. The Arduino is programmed to watch for +5V on two pins.

What I need to know is a simple and reliable way to feed those two +12V signals into the Arduino. Done directly, it would damage the Arduino.

One way could be using two standard 5V regulator circuits (one circuit for one light barrier) based on a 78m05 and three capacitors, which should regulate the 12V (object detected) down to 5V.

Another approach, using a LM317K and one resistor, is described here Roboternetz - Roboternetz-Startseite.

Would you agree on either of these, is there a more straightforward solution?

TIA, Pat

One way could be using two standard 5V regulator circuits (one circuit for one light barrier) based on a 78m05 and three capacitors, which should regulate the 12V (object detected) down to 5V.

This is a classic beginners mistake. Do not use voltage regulators for signal voltage level translation.

Simply use two resistors in a potential divider to get the 12V down to 5V.

Regulators are used to power circuits not for voltage translation of signal lines, the regulator would most likely try and draw too much current from your signal source. What you can use is a simple two series wired resistor voltage divider, where the 12vdc signal wires to the top resistor the bottom resistor wires to ground of both the signal source and the arduino. The junction of the resistors would wire to a arduino digital input pin. a 10k ohm top resistor and a 5k ohm bottom resistor would result in a 4vdc signal avalible at the junction of the resistors suitable to wire to the arduino.

Lefty

Mike, Lefty, thanks for your swift answers.
I'm glad to read that the solution is by far simpler than I thought. Lefty, are 4V (as opposed to 5V) enough to provide a stable digital high on the pins? Would you advise to apply a 10k? pull-down resistor as recommended


when using the potential divider?

Best, Pat

No pull-down resistor required, the voltage divider is also acting as a pull-down as the lower resistor is wired to ground and is why the arduino ground must wire to the divider and signal source's ground. As far as what a legal HIGH voltage is the AVR data sheet says minimum voltage for a HIGH is .7 X Vcc, so with an arduino 5volt board the value is 3.5vdc to 5.5vdc.

Lefty

This may be the first time, things get less complicated, the more I learn about them :wink:
Thank you Lefty, for helping me out on this matter!

1 Like

There is a good diagram of the wiring at the start of this post:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1288614795

You would use a digital pin on the Arduino rather than an analogue one. You would probably need to change the value of the resistors.

Thanks for the diagram lemming, but using an analogue pin here never was a subject to my case.

Yes, that's why he said "You would use a digital pin on the Arduino rather than an analogue one."

Electrons behave the same for analog and digital pins!

You're right. I wasn't looking close enough on the Terminals of the Arduino.

retrolefty:
No pull-down resistor required, the voltage divider is also acting as a pull-down as the lower resistor is wired to ground and is why the arduino ground must wire to the divider and signal source's ground. As far as what a legal HIGH voltage is the AVR data sheet says minimum voltage for a HIGH is .7 X Vcc, so with an arduino 5volt board the value is 3.5vdc to 5.5vdc.

Lefty

Actually for the supply voltages used in Arduinos the input thresholds are 0.3Vdd and 0.6Vdd (ie 1.5V and 3.0V for a 5V supply). In particular 3.3V will reliably be recognised as high. These values apply to normal I/O pins (not Xtal or Reset) and only if the supply is 2.4V or greater.

Good to know! Can this be found on the Arduino playground? If not, it should be pinned here or elsewhere.

patrick:
Good to know! Can this be found on the Arduino playground? If not, it should be pinned here or elsewhere.

These specifications (along with many many more) are from the AVR datasheet for a 328p chip, of which every Arduino user should download a copy to have avalible at all times.

Lefty