# read 12V logic pin from arduino using an NPN transistor

I have an inductance sensor on a CNC machine that goes 12V high when triggered (open collector when not) . I want to read that input on my arduino who uses 5V logic.

I was thinking I could just use a simple NPN transistor to do the logic level shifting. Would this work? I dont want to test it incase it could fry the arduino.

It will work. This circuit should be at logic 1 if there is no signal and at logic 0 if there is 12V signal present.

                +5V
|
-
|1|
|0|
|K|
-
|----Arduino
|
/
12V --|10K|----|
|   \
-    >
| |    |
| |   ---
-     -
|
---
-


P.S. 10K resistors are just there as a generic value. For this purpose you can use almost anything. Base-ground resistor is 100K as recommended by @Russell.

• Add a 100k from base to ground 'for safety' - especially so when input can be open circuit. Without this, transistor leakage can turn the transistor on when the input is open circuit. With 100k base to ground leakage current would need to make Vbe > say 0.4V to start to have any turn of effect. So i=V/R = 0.4/100k = 4 UA.Not much, but as long as it is less than that all should be well. – Russell McMahon Mar 15 '12 at 4:59

If you only need to read from the sensor, I'd suggest a simple voltage divider instead.

Hook the sensor up to ground with 3 10k resistors in series in between. hook your arduino up in between the 2nd and 3rd resistor and you are done.