Electronic – arduino – read 12V logic pin from arduino using an NPN transistor

12v5varduinodigital-logictransistors

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.

Best Answer

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.