What's the best way to use a 12 volt npn sensor the sensor is using a external power
Do you have a data sheet for the sensor? We need to know what type of output it has.
Mikeh23:
What's the best way to use a 12 volt npn sensor the sensor is using a external power
The best way would be to power it with 5V.
This it the data sheet
The data sheet is for several models. Which do you have?
Yea sorry it's M18-3VNLPC-2M
Unfortunately I don't really understand the circuits as sketched in the data sheet.
In general an NPN output (aka open collector) can be connected directly to a digital pin, with the internal pull-up enabled. This output connects to GND when active (giving a logical low), is floating when not active (and the pull-up ensures a logical high).
If you want to be sure, add a diode pointing away from your digital pin, so any higher voltage can never reach your Arduino.
Remember to connect Arduino GND to sensor GND.