Use optocoupler PC817 with Teensy 4.0

laro

New member
Hello everyone,
I am new here, i have only one question and i will be happy if someone could help me.

Here it is: is it safe to use optocoupler PC817 with Teensy 4.0 or Teensy 4.1 in order to control 3.3v relay? i already fry a T4.1 trying to control 5v relay via the logic level RFP30N06LE mosfet connected to the T4.1 and i want to be carefull now.

Thank you in advance.
 
With just a quick look at the datasheet from the link at the end of that page, my first impression is you probably need to add at least a transistor, a diode, and probably 2 resistors to make this part control a relay.

First, it is rated for 5mA input current, and the forward voltage for the LED input is 1.2V (pretty typical for optocouplers - almost all have infrared LEDs inside). So you will need a resistor between the Teensy pin and the opto's LED. It should be no higher than 420 ohms, so you'll get at least 5mA. I'd probably go with a 330 or 390 ohm resistor.

The specs says the current transfer ratio can be between 50% to 600%. So you should depend on getting as little as 2.5 mA output. That's not enough to turn on nearly any mechanical relay. So you'll need to connect the opto to a transistor, which then turns on the relay.

Whatever you do, make sure you always have a diode connected in parallel with the relay. The cathode side (the side with a stripe) connects to the positive voltage. The diode is critically important to prevent the relay from damaging the transistor or opto when you turn off the current.
 
Thank you very much for helping me, now i am sure to not fry my Teensy again by doing mistakes. I will follow your advice. Thank you again
 
Back
Top