I am implementing a power-off function for my Ender 3 using OctoPi. For that, I need a relay and I happened to have one.
Unfortunately, after connection relay to Raspberry Pi GPIO pin, the relay was always on and not listening to any commands from OctoPi.
It appears this module was designed for 5v logic levels and Raspberry Pi works with 3.3v logic levels.
After investigating relay one can see that its circuit is:
For JC817C forward voltage Vf=1.2V and forward current If=20mA
For Raspberry Pi output high (when VDD is 3.3V) is VO=2.3V 17mA
So, it seems that the output of Raspberry Pi is not enough to drive JC817C.
To solve this I decided to remove optocoupler from the module and connect the input pin directly to Q1 transistors base.
To connect the output pin to a transistor you should limit output to appropriate current. You can do that by choosing the appropriate resistor value.
I calculated it like that.
From S8050 (J3Y) transistors datasheet: DC current gain hfe ~ 120
From relay datasheet: Rrelay=70Ohm Vrelay=5V so calculated Irelay=Vrelay/Rrelay=5/70=71mA
Let’s choose Ic=100mA
To turn it on, we must have ~ Ib=Ic/120=100mA/120=833uA ~800uA
Vbe usually is ~0.7V
R9 voltage would be Vr9=Vinput-Vbe=3.3V-0.7V=2.6V
So I chose 3K resistor.