Electrical – How to design an optocoupler circuit for raspberry pi

opto-isolatorraspberry pisensor

I want to give sensor pulse to raspberry pi. The sensor signal comes from a running conveyor . The sensor gives 24v signal hence I used a optocoupler to convert the 24v to 3.3v . How should I design a best optocoupler suitable for PI.

Best Answer

It seems your problem is that you have a 24 V signal that you want to get into a 3.3 V digital input.

Since the signal is coming from some industrial equipment, I agree that opto-isolating it is a good idea. So here is what you do:

  1. Pick a opto-coupler. Just about any will do since you seem to have plenty of input voltage and presumably current available. Use whatever your company already has in stock. If you don't already have something available, check out the FOD817 family. They are cheap, widely available, and have good CTR. They aren't for high speed applications, but should be instantaneous for a signal from a conveyor belt.

  2. Read the datasheet.

  3. Look at what kind of digital input is available. The best would be one that has a internal pullup, because then you need not other parts than the opto itself on the digital side. If all you have is a regular digital input, then you have to supply your own pullup resistor. 10 kΩ is usually a good value for such things.

    Either way, find how much current the opto has to sink to pull the digital input low.

  4. Divide the minimum required pulldown current by the minimum guaranteed CTR (current transfer ratio). Now at least double that. This is current you want to drive the input of the opto with.

  5. Check the specs for the 24 V signal and verify it can source the current computed in the previous step, with some margin. I'll assume it can. If it can't, you'll have to get more clever and the solution isn't as simple as hooking up a opto-isolator.

  6. Look at the minimum guaranteed signal voltage (24 V nominal might only be 22 V min guaranteed, for example), and subtract off the maximum LED voltage from the opto datasheet. This is the minimum voltage that will be across the resistor.

  7. Use Ohm's law to calculate the maximum allowed resistor in series with the LED on the opto's input side. Go one or two standard values down from that, or some value you already stock that is a bit lower than the calculated value.

  8. Connect everything up. Put the opto physically close to the digital input it drives. In other words, the long pair of wires should be between the conveyor and the opto, not the opto and the digital board.