Communicating with a 12V device?
You could use an opto-coupler:

An opto-isolator (also called an optocoupler, photocoupler, or optical
isolator) is an electronic component that transfers electrical signals
between two isolated circuits by using light. Opto-isolators
prevent high voltages from affecting the system receiving the
signal. Commercially available opto-isolators withstand
input-to-output voltages up to 10 kV and voltage transients with
speeds up to 25 kV/μs.
A common type of opto-isolator consists of an LED and a
phototransistor in the same opaque package. Other types of
source-sensor combinations include LED-photodiode, LED-LASCR, and
lamp-photoresistor pairs. Usually opto-isolators transfer digital
(on-off) signals, but some techniques allow them to be used with
analog signals.

Here is an example schematic and packaging:

If you have a heavy load (although this does not seem to be your case) then they can also be used in conjunction with relays - here is an eight channel opto-coupler relay module board: