How to wire and program Photoelectric sensors? (beginner)

Hello, my fellow Electrical enthusiasts,

I’ve been having some issues that give me headaches to figure out and my last resort was Chief Delphi, so here I am!

Our team has been struggling to wire and program a photoelectric sensor and hopefully, we can get some assistance.
From FIRST Choice, we bought:
2 of the Photoelectric Sensor, RightSight (fc-42EF-D2MPAK-F4)
1 of the Photoelectric Sensor (fc-42JT-F5LET1-A2)

I have looked at the other posts on Chief Delphi and was still baffled.

One of the many specific questions would be WHERE do we plug the wires into the RoboRIO? Would it be in the 0-9 slots of the DIO, the 0-4 in the Analog input, or another part of the robot?

As the topic goes along, I’ll reply with more questions if I am confused.

Thank you!

1 Like

First, I would try the brown wire to +12v and blue to ground. Either from the VRM or directly from the PDP. When powered, you can see the LED change based on the photoswitch state. You can adjust the distance with the screw.

Then the signal can be read in through the DIO. I believe either signal wire is possible, but haven’t used it in a while.

How can it be read through the DIO? Isn’t it on the RoboRIO where you connect PWM cables, etc.?

So you’d want a “pwm cable” but only using a connection to the signal pin. You can cut the other two wires if you are using a 3 pin connector. But it goes to the DIO 0-9 pin.

For the 42EF-D2MPAK-F4
image

It has 4 wires:

  1. White - Signal (NPN output)
  2. Black - Signal (PNP output)
  3. Blue - Ground
  4. Brown - 12v

  1. The White Lead should be connected to the RoboRIO Digital IO. We used two 10K ohm resistors to create a voltage divider as the RoboRIO’s Digital Input is rated for 5v.
  2. The Black Lead will be unused.
  3. The Blue lead is connected to the associated negative output of the PD.
  4. The Brown lead is connected to a positive (+12 V) output of the Power Distribution panel through a 20 amp breaker OR to the 12v on the Voltage Regulator Module.

Here is a quick wiring diagram that worked for us:

As for programming, you can use the DigitalInput class (http://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/wpilibj/DigitalInput.html)

The sensor will work just like a limit switch as far as the code is concerned. This article may be of help:
http://wpilib.screenstepslive.com/s/currentCS/m/java/l/599744-using-limit-switches-to-control-behavior

Edit: Flipped White and black in wording. Diagram is correct.

2 Likes

I cannot express how much I thank both of you.

I’ll see if I can get it to work with both of your information!

If there is another problem, I will definitely reply to this post for more help.

Thank you again!

The diagram you posted contradicts this.

To save you the trouble of finding some resistors and finding a place to install them without anything shorting out, get some of the “Voltage Detectors” that pugsly14 shows in his post in this thread.

Good catch, sorry about that. The diagram is correct, the wording was wrong and has now been corrected.