Is it better to use the NPN or PNP version of the E3F Photo Switch?
I found a post that mentions NPN transistors as being faster than PNP but I don't know if that matters in this use case.
I found a Manual for the PNP version that showed connecting it to a MCU but couldn't find anything about using the NPN with a microcontroller.
And all instructions I can find about using NPN transistors with a MCU is using the MCU to control the switch not monitor if the switch is open or closed.
NPN is usually best with an Arduino. This is an open collector configuration so you have to declare the input pin as INPUT_PULLUP and the logic is reversed. That is, a HIGH on the pin means no detection.
NPN pulls to ground which won't over-voltage the Arduino pin. Just add a pull-up to the
Arduino's Vcc of about 4k7 for good solid response - built-in pull-ups are a bit weak for
anything with a long cable that might pick up noise - though they may be enough.
PNP pulls up to the sensor supply which is often more than a logic voltage level, so you'd have to
fiddle around with a voltage divider and its less simple to wire.
Those look really similar to units I just bought. Mine came with 4 foot cables. Wired the reddish/brown colors to +5, the blue to Gnd, and the Black to an input with INPUT_PULLUP worked just fine. The label around the bottom will likely show the same.
Use the NPN for sure.
When the beam is not-broken, the input will be low, and otherwise.
Here's a simple test I wrote
Didn't really catch the receiver in that clip, but it's down there, 6 feet away.
Both were powered from the 5V USB port on the 1284P module I was using with a blue diode on D13.
Wow thanks for all the quick responses.
I think that answers my question about using NPN vs PNP but I want to answer your questions in case it changes anything.
Here is the link to the PNP version I found showing how to use it with the MCU.
I am able to use 5v on the receiver side so I don't over do the input pin.
I wonder if putting the 10k resistor to +5v instead of ground will do the same thing since I have the NPN?
(See attached Image of Type2 from the PDF)
The 2nd image (2020910_192205sml.jpg) is the tag attached to the receiver wire for connecting the sensor.
It shows 6-36VDC but it will work on 5VDC. I haven't tested how that effects the distance though.
BU- is the common ground between the E3F-5DN1 sensor, its power supply, and the Arduino.
BN+ is the power supply positive rail (6 to 36 VDC) to the E3F-5DN1 sensor. You do NOT connect this to the Arduino, not even through a (single) resistor.
BK is the collector of the NPN transistor. This is connected to the Arduino pin. You define the Arduino pin as INPUT_PULLUP and/or you connect a external pullup resistor between that pin and the Arduino's 5 volt power rail.
The diagram with the PNP output will confuse you because this is not appropriate for an NPN output. It does, however, imply that the E3F-5DN1 can be powered at only 5 volts which, if it is true, could be useful to you.
You may have to add a timing element to your algorithm. For example, don't accept a new detection if the old detection was terminated within the last 50ms.