Signal from 12 to 5v

Hello, I have a question related to a level crossing in a train layout. When the barriers are up or down, the signal to stop the motor is a tension of 12 V (the same as the input). I want to control it through an arduino. This means that I have to convert the 12 v to the 5 v for a digital input in the Arduino. Any advise?

Thank you very much

Arturo

Google: voltage divider.

You need a 5:7 ratio. = 5/12 across the lower resistor.

10k from pin to ground, and 14k 15k from pin to the 12volt source.
Higher values (same ratio) are ok.
Leo..

You could use a trimpot like below as an adjustable voltage divider.

http://www.ebay.com/itm/10pcs-3296W-502-3296-W-5K-ohm-Trim-Pot-Trimmer-Potentiometer-Square-Shape-/400917518509?hash=item5d588bd8ad:g:yNYAAOSwNSxVUHZr

If I were doing that, the most robust way to handle it is with a Logic Optocoupler. You can use the internal pullup of the Arduino and about 1K series resistor for your 12V input to the diodes. Tie the emitter to Arduino ground, the collector to the input you are using.

That allows you to isolate your Arduino from your train. You didn't mention whether the train uses AC or DC, with this device it doesn't matter.

zoomkat:
You could use a trimpot like below as an adjustable voltage divider.

Dangerous.
If you adjust is wrong, you could have 12volt on the pin.
Leo..

Wawa:
Dangerous.
If you adjust is wrong, you could have 12volt on the pin.
Leo..

Adjust the pot using a multimeter to check wiper voltage prior to connecting the wiper to the arduino.

Or add a fixed resistor between 12V and the pot, limits the upper voltage out of the pot.