If you use a proximity switch such as the LJ12A3-4-Z/BX, you will need a supply voltage of 6 to 36v. anything below 10v won't work reliably (I found to my cost). The advantage of this proximity switch is that it is a sealed unit, you just need to keep swarf away from the sensor end.