Using a voltage divider and an N-channel MOSFET to switch an Arduino input pin from a EL2008 Beckhoff digital output module
Do you need to use a mosfet? Why not just use an optocoupler:

But if you need to use the mosfet, keep the common 0V reference: