Odd behavior when wiring a QMIC-0N-0A photogate to the RoboRIO DIO

We bought some QMIC-0N-0A NPN retroreflective IR photogates: https://www.automationdirect.com/adc/shopping/catalog/sensors_-z_encoders/photoelectric_sensors/dc_rectangular/retroreflective_(qm-z-cx-z-fe_series)/qmic-0n-0a
The spec sheet can be found here: https://cdn.automationdirect.com/static/specs/peminirectqm.pdf
Since we have 3 on the Robot, we wired them up to the RIO DIO 5V rail with a small boost converter to 15V.
I know that the RoboRIO DIO has a 40kOhm pullup resistor to 3.3V (page 15 here http://www.ni.com/pdf/manuals/374474a.pdf)
I also know the RIO needs 0.0 to 0.8V to read low on the DIO, (page 4 Product Documentation - NI) so any NPN sensor should work. This is in line with the sensors we get in the KOP, other threads on CD, and what an EE told me.
However, when I wire the sensor as shown:

Code cannot read the sensor. When I probe the signal line between the sensor and the DIO, I read either 3.3V (expected due to the pullup) or 1.3 when the sensor is triggered, not low enough to trigger the DIO.

Since I don’t know the internal workings of the sensor, I decided to try adding a 100kOhm pulldown to GND, as shown:

This pulled down the high voltage to 2.4V, but when the sensor triggered, it would again read 1.3V. (I didn’t do this test on an actual RIO, but I created a test setup that is equivalent to the above. The first result that showed 3.3V and 1.3V was verified on the test setup)

My only other idea is to add another NPN transistor that would do a better job sinking current than the sensor would. The sensor would trigger that NPN transistor. But, I’m not sure if that would work or even how to go about it if it would.

How can I get this thing to work with the RIO?

This might be relevant. How to wire and read QM Series Photoelectric Sensor?

I don’t know if this will help, but we had the same problem, so we wired ours to the analog pins and wrote our own conditions for the cutoff voltage. I believe we set it at 2 or 3 in the condition of the if statement to separate true and false.

It seems like the net result of that thread was to use Analog In pins with an optional pullup resistor on them. I didn’t think of that, and it would work. Thanks @Breakaway3937 and @Travis_Hoffman for the idea.

However, we use three of these photogates and one analog pressure sensor, meaning our Analog In ports will be full. It would be nice I could figure out how to use these on the DIO to ensure future flexibility. It would also help my burning curiosity. If we really need to though, I could use the MXP Analog In that’s broken-out on the NavX-MXP we just so happen to use.

According to this post, the team plugged the sensor DIRECTLY into a DIO with no external power, and it actually functioned.

That was the confusing part of the thread for me. The sensors are both NPN from the same series and really ought to be functioning the same. No matter what I do though, I always read 1.3V low when its sinking, which shouldn’t trigger the RoboRIO DIO. I’ll double check everything and give it another shot hooked up to the RIO the next chance I get.

Regarding the 1.3V number, that’s likely the VCE(sat) of the NPN phototransistor in the device. There may also be a protection diode on the pin that’s part of that 1.3V, depending on the internal design.

VCE(sat) is the collector-emitter saturation voltage. It’s dependent on the collector current. The thread mentioned above where the user plugs the device directly into the RIO essentially has the device supply voltage set at 3.3V. Since you are boosting the supply voltage to 15V, that means you are likely increasing the collector current, which in turn increases VCE(sat) and prevents you from triggering the buffer on the DIO port.

Try reducing the supply voltage as suggested in the thread above. That likely reduces VCE(sat) sufficiently to trigger the port. The disadvantage of reducing the supply voltage is that it may change the behavior of the sensor.

That’s all a very broad guess based on BJT transistor theory as to what may be going on. YMMV.

I will definitely try lowering the supply voltage. I chose 15V because I had tried running this sensor off of lower voltages (using a bench-top supply) and it quickly ceased to function below the rated minimum of 10V.

After some research, I managed to flesh out my idea of adding another transistor. I think wiring like this would work:

The idea being that the sensor would constitute the base current, opening the transistor and sinking the collector current to GND. The emitter current would pull down the sensor line much closer to 0V.
Could someone give this a review? I also don’t know how to shop for a BJT transistor.

Your new BJT is mounted backwards. You need the emitter to ground and the collector attached to the RIO.

But, this still may not work, depending on the Base-Emitter diode voltage and current gain of your new BJT. You may still be turning on the new transistor with the sensor’s current even in the low state.

Another approach with more configuration options is to use an N-Channel MOSFET in place of your BJT. Then you can use a voltage divider to set the gate voltage in the high and low states so you are below the FET’s threshold voltage in the low state and above it in the high state. There is some added sensitivity to ESD, but a quality device will handle that fine.

1 Like

It is unclear if the external NPN transistor connection that described by jee7s will work. There is no source for the base current to turn the transistor on. If there is some internal path in the sensor that can supply the base current, the external NPN will always be on, regardless of the state of the sensor output. The sensor output voltage when it is on, 1.3V, is high enough to keep the NPN turned on.

You can connect a resistor as a load for the sensor and use a voltage divider to drop the voltage down so that the input to the DIO is below 0.8V even if the sensor output is 2.0V (Voltage drop in the data sheet table). This is shown in the upper portion of the attached sketch. I did the calculations with 1kOhm resistors. Originally, I tried the calculation with 10kOhm resistors but the internal 40kOhm in the Roborio messed things up. The voltages applied to the DIO pin are shown in the sketch. The 1kOhm sensor load resistor is well within the sensor’s capabilities.

A second way of doing this would be to use an NPN transistor as shown in the lower part of the attached sketch. Please note that his inverts the logic of the sensor output; when the sensor output is Hi the DIO will be Lo, when the sensor output is Lo the DIO will be Hi. A 10kOhm resistor acts as the load for the sensor when it’s output pulls low and limits the base current when the sensor output NPN turns off. The three diodes ensure that the external NPN turns off even if the sensor output voltage is 2.0V.

It is possible to replace the NPN transistor with a MOSFET. You would want to select a MOSFET with a threshold voltage above 3V. The three diodes can be deleted and the sensor load resistor should be dropped to something like 1kOhm or 2 kOhm.

photo-e NPN sensor interface.pdf (17.9 KB)

These types of sensors typically have a pnp and an npn output. Thou should use the npn output to pull down. That should provide a voltage is less than 1 volt when triggered.

The specific part the OP is using is NPN only. It also seems to have an unusually large on-state output voltage (2.0 V). Making the output voltage lower would have only cost a few pennies more :-/

It may be they intend for these sensors to drive relays directly or something like that where the larger voltage can be tolerated.

Truthfully, the QM series are cheaper than the CX-series we typically use from Automation Direct:

If I remember correctly, these function well running at 12 VDC and plugged into a DIO. I know the CX5 has behaved for us in the past:


The CX series has the same maximum output voltage spec of 2.0V as the QM series. In real life, there may be some difference that makes the output voltage low enough to get below around 1.5V which may cause your DIO to sense a Lo level. It needs to be below 0.8V for the DIO to guarantee it is sensed as a Lo level. While the CX series worked for you, it isn’t guaranteed for all applications.

Sorry guys, I was trying to respond from my phone. In looking at the data sheets I have to ask are you getting solid indication on the sensor LEDs when the object is detected? The output low specification is at 100ma and the RoboRio will not pull that kind of load when connected to a DIO. So the output of the sensor should be lower. (I have not worked with these devices.) My suspicion is that the sensor may be reacting to a a variety of reflections and may in fact be switching rapidly between detect and not detect. In that case the output could be high because of the switching. If you are using a multimeter to check the output voltage, try switching it to AC and see if you get any voltage indication. It should read “0”.

@philso I went out and purchased some 1k resistors and your top diagram worked perfectly. The predicted voltages were near perfect. Due it being easier to find replacement resistors than transistors and diodes, this is the method I think we are going to go with. Because of time limits, I didn’t test the transistor method, but I might later as I already bought the parts. Putting those part numbers in was super helpful!

I haven’t looked at AC voltage, but this issue has now been reproduced in 3 separate sensors and environments across a variety of sensitivities by me. Other teams in the prior linked threads also had the same issue.

Thank you all for your help!

In case anyone ever wants to do this or cares to see my jank test setup, I took some pictures. Obviously the final setup will be nicely soldered, glued, and heat-shrinked.

Glad it worked for you, @Lytigas. I figured it was easier to present a solution that only used one resistor value.

It would be interesting to know if the sensor output has any significant AC voltage on it.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.