optocoupler 817 and Raspberry Pi

Thread Starter

MeAtHome

Joined Jul 23, 2022
5
Hi,
I'm a novice at designing circuits. The more I read about the optocoupler PC817, linked to a raspberry Pi, the more confused I get.
I would like to connect a 5VDC source via a pushbutton and a resistor to pin1 of the PC817, and pin2 to ground.
Pin4 (collector) is going to another powersource (is 3.3VDC sufficiant), and pin5 (emitter), via another resistor to my GPIO pin.
With all information like voltage dop, forwarding voltage, CTR percentage,... I'm not able to figure out what resistors I have to take to get a 3.3V/0.5mA signal om my Pi.
Can someone explain a few things to me?
Thanks,
Martin
 

MaxHeadRoom

Joined Jul 18, 2013
25,991
Look up the data sheet, the version I have is 20ma input max, with a 1.2v drop across the LED, so a 275ohm should be on the safe side.
the output is 35ma max.
S0 150/200 ohm on the output.
 

Papabravo

Joined Feb 24, 2006
19,309
The basic idea of using an optocoupler boils down to a couple of concepts:
  1. On the diode (input) side you use the power supply voltage, the forward voltage drop of the diode and the resistor to set the amount of current through the diode.
  2. Use the CTR (Current Transfer Ratio) to calculate the collector current on the output.
  3. Use the output power supply voltage, the range of collector currents, and the Vce drop of the output transistor to compute the pullup or pulldown resistor.
There are some problems you should be aware of:
  1. CTR is NOT a well controlled parameter of an optoisolator. There will be considerable variation among a selection of devices.
  2. CTR can decrease with age
  3. The PC817 has a suffix letter A, B, C, D which tells you the minimum CTR you should expect. The devices with a higher minimum CTR will cost more.
Here is a simulation example using the resistor values calculated by @MaxHeadRoom for a PC817B with a CTR of approximately 150% showing the input and output voltages along with the currents.
1658609058161.png
 
Last edited:

Thread Starter

MeAtHome

Joined Jul 23, 2022
5
What's the purpose of the optocoupler here?
Why do you think you need the isolation?
Hi,
On the IR LED side (pins 1 and 2) I have a seperate circuit, with its own powersupply. In case something goes wrong at that side,
the protection of the GPIO pins on my RPi is my objective. So an optocoupler looks like the best solution.
 

Papabravo

Joined Feb 24, 2006
19,309
Hi,
On the IR LED side (pins 1 and 2) I have a seperate circuit, with its own powersupply. In case something goes wrong at that side,
the protection of the GPIO pins on my RPi is my objective. So an optocoupler looks like the best solution.
A logic device (74LVC1Gxxx) with a 3.3V supply and 5V tolerant input works just as well at far lower cost and complexity. Also the PC817 is at or near EOL so securing an adequate supply of those parts may be a problem.
 

Thread Starter

MeAtHome

Joined Jul 23, 2022
5
Look up the data sheet, the version I have is 20ma input max, with a 1.2v drop across the LED, so a 275ohm should be on the safe side.
the output is 35ma max.
S0 150/200 ohm on the output.
Hi,

Thanks for this information.
So the 275Ohm at the LED side (at 5VDC) gives me a current of 13-14mA.
To be sure to protect the GPIO pin (where I would like to limit the current to 0.5mA, at 3.3V ) : can a 6600Ohm resistor
between my powersupply of 3.3V and the collector (pin4) do the job?
 

BobTPH

Joined Jun 5, 2013
5,785
You do not need a resistor in series to protect the the input. The input will only draw nanoamps as long as the voltage is between 0 and 3.3V as guaranteed by the optocoupler circuit.
 

Thread Starter

MeAtHome

Joined Jul 23, 2022
5
Hi guys,

In the first steps of my project, I'm trying to get a a white LED on a RPi GPIO, using an EL817 optocoupler.
An soon as I connect the 5V, the LED starts to 'glow'. Touching the resistor at the basis of the BC547 makes the LED shine like a star ..... same result when connecting the resistor to any GPIO pin (none of them are configured as GPIO.OUT.
1. The 380Ohm over 3.3V from the GPIO pin is to get 5mA at the basis of my BC547.
2. The 670Ohm between EL817 and the BC547 is there to get 5.5mA through the IR LED inside the EL817
3. The 180Ohm near the white LED is to limit the current to 10mA.

Question : Do I need an external pulldown resistor on my GPIO pin to solve the problem?
I don't want to wreck my RPi during a trial-and-error .....

PS : the 5V is not provided by the RPi.

Thanks,
Martin
EL817_BC547_setup.jpg
 

Thread Starter

MeAtHome

Joined Jul 23, 2022
5
Hi MaxHeadRoom,

I'm sure there are more elegant ways to do the job, like a Mosfet (e.g. the IRF520). I was hoping to be able to build something with components that I have in my drawer..... and to understand why it's not doing what I'm expecting.
Regards,
Martin
 
Top