Optocoupler for reading a -6V to 6V square wave with an Arduino

Thread Starter

Tinkerton

Joined Nov 30, 2023
5
I'm currently working with a sensor that is a open collector output flow sensor. The manufacturer states I need to use a 12V supply and a pull up resistor connected the output of that supply (R1). This generates a roughly -6V to 6V square wave with the frequency changing based on the flow rate. I need to read this data with an Arduino and based on the recommendation of a coworker I'm trying to use an optocoupler with the hope of getting a 0 to 5V square wave out. I've made a crude drawing with the circuit but the issue I'm having is protecting the optocoupler from the negative voltage from the sensor, the optocouplers I've looked at have a reverse voltage of 6V and I believe this means any voltage exceeding this spec will damage the optocoupler. Based on a little research I think others use a reverse biased diode to protect the internal LED of the optocoupler but I haven't been able to find any info on how these parts are selected. Any guidance or info is appreciated.

drawing.png
 

Thread Starter

Tinkerton

Joined Nov 30, 2023
5
The signal from the open collector output is 0V to +12V.
It would only be ±6V if the signal goes through a coupling capacitor.
I've attached an oscilloscope capture of the output from the sensor, perhaps I've made a mistake in setting up the oscilloscope? Any ideas on easy things to check?

Capture.JPG
 

schmitt trigger

Joined Jul 12, 2010
843
10k ohm with a 12V supply will only provide a little more than 1 mA to the optocoupler. The optocoupler better have a very high CTR. I would lower the resistor's value by at least half.
 

sghioto

Joined Dec 31, 2017
5,369
Seems one could eliminate the opto if the 12 volt supply is stable using two resistors. The two supplies share a common ground as seen in post #1.
1701392404083.png
 

Thread Starter

Tinkerton

Joined Nov 30, 2023
5
Seems one could eliminate the opto if the 12 volt supply is stable using two resistors. The two supplies share a common ground as seen in post #1.
View attachment 308787
Yes, this is what I'll be doing. I didn't really understand how the open collector output works and the manufacturers info was a little confusing so I didn't think to check the issue with the oscilloscope.
 

sghioto

Joined Dec 31, 2017
5,369
I also noted that when the sensor out is LOW the input to Arduino is HIGH with the schematic in post #1. Is that your intent as well or does it matter?
 

crutschow

Joined Mar 14, 2008
34,044
I didn't really understand how the open collector output works
Typically it's an NPN transistor with the emitter connected to common and the collector unconnected.
You add a resistor from the collector to a positive supply to complete the circuit.
The output voltage then goes from ground to the positive supply value.
 

Sensacell

Joined Jun 19, 2012
3,399
Why can't this just be done with a single pullup resistor to +5 Volts?
I have never heard of an open collector output that requires a pullup to any specific voltage?

How many leads does this sensor have? Do have a part number?
 

dendad

Joined Feb 20, 2016
4,426
Why can't this just be done with a single pullup resistor to +5 Volts?
I agree. If the sensor is open collector, just hook a pullup from the output to +5V and you should get a 0 to 5V square wave signal.
You only need an opto if you want electrical isolation.
 

Thread Starter

Tinkerton

Joined Nov 30, 2023
5
Why can't this just be done with a single pullup resistor to +5 Volts?
I have never heard of an open collector output that requires a pullup to any specific voltage?

How many leads does this sensor have? Do have a part number?
Finding info online about the part was kind of challenging so I had to resort to contacting their sales support team and was specifically told that the pull up needed to be connected to the operable supply range provided in their document with a particular comment saying don't go below 9V. This is the only document I've been able to find/was provided.

Screenshot 2023-12-01 010950.png
 

Sensacell

Joined Jun 19, 2012
3,399
Should work with 12 volts on the BLUE and the GREEN going to ground.

A simple pullup of 2.2 K ohms to +5V going to WHITE, the signal.
This is the totally bog-standard open-collector solution.

(post 13 shows correct wiring)
 

eetech00

Joined Jun 8, 2013
3,820
Use the "Isolated" circuit in post #13 since the arduino's input is 5V. The ardunio already has an internal 22k pull up (if enabled).
If you use an external pull-up, then disable the internal pull-up.

Edit: added comment
In addition, it seems the sensor and circuit may be used in an industrial environment, so I recommend the "isolated" circuit with the opto.
 
Last edited:

Ramussons

Joined May 3, 2013
1,395
I'm currently working with a sensor that is a open collector output flow sensor. The manufacturer states I need to use a 12V supply and a pull up resistor connected the output of that supply (R1). This generates a roughly -6V to 6V square wave with the frequency changing based on the flow rate. I need to read this data with an Arduino and based on the recommendation of a coworker I'm trying to use an optocoupler with the hope of getting a 0 to 5V square wave out. I've made a crude drawing with the circuit but the issue I'm having is protecting the optocoupler from the negative voltage from the sensor, the optocouplers I've looked at have a reverse voltage of 6V and I believe this means any voltage exceeding this spec will damage the optocoupler. Based on a little research I think others use a reverse biased diode to protect the internal LED of the optocoupler but I haven't been able to find any info on how these parts are selected. Any guidance or info is appreciated.

View attachment 308774
Why not replace the R2 with 1 (or 2) diodes in series that allow the +ve level to pass and block the -ve part? Of course, you will not get galvanic isolation, but is it necessary?
 
Top