Digital IR Sensor Issues

Hi CD,

I’m having a little issue with my IR sensor code. We are trying to use the IR sensors to see how many power balls we have on board and index balls through out system. We are using Sharp GP2Y0D805Z0F Digital Distance Sensors from Adafruit. Since they’re a digital input, it should just be like a limitswitch, right? Therefore like IR1.get() would return false when nothing is there and true when something is there. We know that they’re wired correctly because they have an LED on the back that lights up when the beam is broken.Am I thinking about this in the right way? I can upload code if anyone wants to see it.

Thanks

You are correct. If I had to guess, its a wiring issue. You may have the ground and signal wire backwards. Flip the cable around.

More:
If you have the cable backwards, it will always read true. If that is what you are seeing, that is why.

We use Beam break sensors (IR sensors that are similar to what garage doors have at the bottom). Those DigitalInputs actually are true when there is nothing between them, and false when something is there.

I would recommend just using something like smartdashboard to view what they are doing, and make sure that when they change you see the values change the way you expect.

Those will still work in disabled() so you can safely do it without your motors turning on.

Per the Specs on the Adafruit Product Page:
image
So it would be false (low) on detect, and true (high) otherwise.

Most of these IR Photoelectric sensors are like that, from the Beam Break sensors, to the Sharp Digital/Analog Sensors to those generic yellow Reflection Diffuse sensors.

What I recommend is writing a method to return the state of the sensors that includes the inversion, ie:

public boolean getIR1() {
    return !IR1.get();
}

Thank you very much. I swear I looked through that product page a hundred times and somehow I still missed it.

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