I have a project which was using ir photosensors powered by a Mega. They weren’t accurate enough and I’ve change them for CMOS laser sensors (LR-ZB90CB, Keyence)
The laser sensors use a dedicated 24v supply. These are the specs for the output signal:
Specifications - Control output: NPN+PNP Open collector, Applied voltage 30 VDC or less, Control current 100 mA or less, Residual voltage 1.2 V or less at 10 mA or less, 2 V or less at 10 to 100 mA
Will I need to use a resistor in series with the output to the Mega digital input?
You can interface to an NPN open collector using a diode (anode to Arduino pin), and enabling pull-up on the pin using pinMode INPUT_PULLUP. The diode isn't strictly required, but will prevent damage if 24V accidentally got onto the wire.
A PNP open-collector pulls to 24V and isn't ideal - a resistive divider can be used to reduce the voltage, 10k and 2k2 would work.
Active NPN open-collector pulls the pin LOW, note.
Yes in the I/O circuit diagram the blue/3 and white/2 wires are the ones to use for ground and signal - it already has a protective diode in circuit so you don't have to worry about it generating unwanted voltages, it can only pull down.