Interfacing Micro Switch Photoelectric Sensors

Hi!

I have some of these: Light operated (L.O.) sourcing (PNP) output; vertical mount FE7B-RPE6V-971.
Datasheet can be found here: datasheet.

I thought that I can use for a limiter in GRBL. But have problem with configuring.

There are three wires
Brown - 10-24V
Black - PNPOUTPUT
Blue - 0V

So i connected it to 12V (Brown) but there is no response nor on indicator, nor on output.
I made a sketch:

const int motorLimitSwitch = 9;

void setup()
{
  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor

  Serial.println("Hello!");
  
  //pinMode(motorLimitSwitch, INPUT);
  pinMode(motorLimitSwitch, INPUT_PULLUP);

}

void loop(){

  //Serial.println(analogRead(motorLimitSwitch));
  Serial.println(digitalRead(motorLimitSwitch));

  delay(100);
}

And no change for analog nor digital read. What am i doing wrong?

Best regards!

e-San:
And no change for analog nor digital read. What am I doing wrong?

Don't know because we have no idea how you have actually connected it, but it sounds as if you are incredibly lucky that you have not trashed your Arduino by connecting a 12 V source to an input. :astonished:

Maybe dumb question, but you are using a retro-reflective target? Wiring would have been so much easier with the sinking (NPN) version. With that one you need a voltage divider to drop the 12V output down below 5V.

Don't know because we have no idea how you have actually connected it

So i connected it to 12V (Brown)

I wasn't specific enough, sorry:
12V - Brown aka 10-24V,
Arduino(9) - Black aka PNPOUTPUT,
Arduino(GND) - Blue aka 0V.

you are incredibly lucky that you have not trashed your Arduino by connecting a 12 V source to an input.

Yes, i am! Now i know that :wink:

Maybe dumb question, but you are using a retro-reflective target?

Not that dumb. Can i substitute it somehow for testing or i need to buy specific ones?

Wiring would have been so much easier with the sinking (NPN) version. With that one, you need a voltage divider to drop the 12V output down below 5V.

Yeah, but i have some of this only. I will use divider if it starts working (indicator at least).

Will those be good?

fb4430d44d3ead38dfa0608c92e3.jpg

e-San:
Will those be good?

a00180ff540a961bcf286081ecdd5c71064a9aea.jpg
Looks plausible.

If the sensor's output is 12V, you MUST use a voltage divider.

18k 10k
12V----///--+--///----GND
|
|
A0, 4.3V

outsider:
If the sensor's output is 12V, you MUST use a voltage divider.

        18k        10k

12V----///--+--///----GND
              |
              |
             A0, 4.3V

Well, in another discussion, according to this application note, ATMEL specifically warrants that it is safe to use the internal protection diodes to clip up to 1 milliamp in either direction, so you do not need the 10k, just use a 47k in series. (Put it right at the Arduino pin to avoid any interference problem.)

1mA might be too susceptible to noise. At least add some capacitance to ground on the inputs, this
will absorb noise spikes picked up by the wiring (47k is a pretty high impedance, enough to be sensitive
to nearby motors and so forth).

MarkT:
47k is a pretty high impedance, enough to be sensitive to nearby motors and so forth.

Which is of course, precisely the reason for my advice to put the resistor right at the Arduino pin.

To pick up interference, you need an antenna, which is the trace between the resistor and the microcontroller. This needs to be as short as possible, the less interference you can pick up, the less you need to consider extra steps to suppress it.

If there is any concern about interference, you need to de-bounce the input in code, and by not using interrupts.

Many thanks guys for your help!

I've switched to Inductive sensor since photoelectric ones was not satisfactory for me.

Just one question: why 47k?
I understand that clamping diodes are designed to be up to 1mA, so they will have to conduct up to 12V@1mA, it gives 12k resistor in series (at least). Ofcourse it is always a good idea to work somehow uder the limitation, so why wont we use, for example, 22k? It would give us 12V/22kohm = 0,55mA..

Best regards!

e-San:
Just one question: why 47k?

Because it is a standard value.

Because if wired directly at the Arduino pin, there is negligible risk of the pin picking up interference so no expectation it will not respond reliably and without delay.

There is a great concern about voltage surges on automotive systems. Not necessarily at the battery itself, which is one reason why important equipment such as communication radios are generally wired directly to the battery, but there is a lot of wire in a car loom, high voltages on the ignition and funny things can happen.

And because really good engineers are really careful and conservative.

Paul__B:
And because really good engineers are really careful and conservative.

Obviously, I'm not one...

Paul__B:
Because it is a standard value.

And that's an argument! :wink:
Thanks.

Unfortunately, it didn't work. As I mentioned at the beginning of the topic, I'm going to use it for GRBL.
There are INPUT_PULLUPS set for limiter. So i used NPN transistor and 47k resistor.

C - Collector connected to input,
B - Base --- 47k --- limiter output,
E - Emitter connected to GND.

And it works now.