Oscilation on signal received from proximity sensor + optocoupler

Hi, merry Xmas

I’ve previously posted a topic (https://forum.arduino.cc/index.php?topic=636117.0) but I have a more specific thread now.

I’m trying to use a proximity sensor (Omron E2EG-X5C2) to count motor cycles (maximum speed: 3600 rpm) and I’m using a optocoupler (6n136, for speed) and an Arduino Mega. This is not my area of expertise so it can be basic errors, maybe you guys can help me, both datasheet are attached. Attaching it to an interrupt is a next step, the problem now is that the value read from D2 keeps oscilating, as one can see on print from plotter serial (just a println(digitalRead(buttonPin)).

My scheme is attached too, I’ve placed some led to identify if sensor is working, both of them turn on when an object is near (LED 2 with more ligth than LED 1), as well as expected.

Searching on web I would guess it should be a basic grounding mistake, but as I said, I’m not much experienced on eletronics, so any opinion of yours will help.

Thank you very much,

Pedro

6N136.pdf (609 KB)

E2EG-X5C2.pdf (221 KB)

Proximity_and_opto_25_dez_19.pdf (17 KB)

Monitor.ino (412 Bytes)

That circuit looks wrong: LED1 and LED2 particularly.

What's the purpose of that optocoupler in the mix?

Do you have the NPN or PNP output version of the sensor?

As you forgot to add units to the axis of that "oscillation" graph, nor shows a difference between "motor running" and "motor not running", it's completely useless. All I can say is that it looks very much like the signal I'd expect from a spinning motor's rpm sensor.

Thanks for your reply.

The purpose is to protect arduino board.

NPN version.

The motor is not fixed yet, I'm using some object just to activate the sensor, this graph doesn't changes with or without activating sensor. The graph amplitude is about 1V.

Any suggestion?

NPN output can be connected directly to the Arduino pin; and connect the grounds together. If you’re afraid it outputs higher voltages, add a diode in between (pointing towards the sensor output). That’s all you really need. And of course use INPUT_PULLUP.

If you do a digitalRead() the amplitude can not be 1V, as the voltage on the pin must be at least 0.5*Vcc to be read as HIGH. So that again doesn’t make sense. You are reading 1s and 0s, as it’s a digital input. That’s it. This looks more like a floating pin, as if you forgot to connect ground between the Arduino and the 12V circuit. Or at the very least the optocoupler pin 5 to Arduino ground.

wvmarle:
If you do a digitalRead() the amplitude can not be 1V, as the voltage on the pin must be at least 0.5*Vcc to be read as HIGH. So that again doesn’t make sense. You are reading 1s and 0s, as it’s a digital input. That’s it. This looks more like a floating pin, as if you forgot to connect ground between the Arduino and the 12V circuit. Or at the very least the optocoupler pin 5 to Arduino ground.

Understood perfectly, thanks

wvmarle:
NPN output can be connected directly to the Arduino pin; and connect the grounds together. If you’re afraid it outputs higher voltages, add a diode in between (pointing towards the sensor output). That’s all you really need. And of course use INPUT_PULLUP.

I’ve tryied it now and it works perfectly, I was affraid of higher voltages, in fact.
I don’t know how to thank you properly as it’s been a couple of weeks I’m trying to make it work. Thank you very much wvmarle, I’m really grateful. :slight_smile: :slight_smile:

Karma is always good :slight_smile:

That's the beauty of an NPN output: it's basically connected to GND, or not connected (floating), making the working voltage of both sides irrelevant (to an extent, of course). Now if there's still a higher voltage on the output, the diode blocks this.

Simplest solutions are often the best solutions.

You placed LED1 and the opto coupler in parallel - but they have different forward voltages so only one is likely to function.

LED2 shorts out the other devices anyway, so if it has a small forward voltage it will be the only thing getting current.

LED1 and LED2 need to be removed.

Are you sharing grounds anyway? If so then opto-isolation is doing nothing.

Thanks for your explanation.

I am using without opto now, as wvmarle explained.

I didn't even put the diode there, as it is NPN think there's no problem. For curiosity, when I placed a LED on that way (between pin 2 and sensor output, pointing to sensor) the signal becomes unstable again.

Thanks all

No surprise, especially with a red LED. Forward voltage is typically 2.2V, which is in between guaranteed high (>3V) and guaranteed low (<1.5V).