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.
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:
- 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.
- Read the datasheet.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Does your sensor toggle between 0V and 24V with each impulse? Are the GNDs connected? You don't need an optocoupler then but can use a much simpler circuit:
How does this work? Easy, the +24V from the input don't ever reach the Raspberry Pi GPIO port. Only the 0V do. Your impulses toggle between 0V and 24V, remember? When the sensor outputs 24V, the diode is non-conducting and thus, the GPIO is pulled to 3.3V by the resistor. When the sensor outputs 0V, the diode is conducting and the GPIO is pulled to 0.4V by the sensor.
Depending on your Raspberry Pi GPIO pullup setup, you may even leave out R1.
if the sensor generate high speed pulses use high speed optocouplers 6N137