Modify Arduino 5v relay module to work from 3.3v

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.

Relay module I had
Relay module I had

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:

Original schematics of relay module
Original schematics of relay module

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.

Modified relay module
Modified relay module
Relay module with optocoupler replaced by resistor
Relay module with optocoupler replaced by a resistor

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

R9=Vr9/Ib=2.6V/800uA~3.2K

So I chose 3K resistor.

 

 

9 Comments

  1. This does not seem to work with more than one of these at a time. I daisy chained 3 together and only 1 works. Any ideas?

    • Yes, that’s right. I actually managed to get it working by using lower ohm resistors. Through a bit of trial and error, I found that using a 350 ohms resister on each provided enough current to trigger each relay.

  2. You should mention though, that the decoupling of the currents is undone this way… As I understand, if the relay switches a heavy load, the circuit of your controller board (i.e. by the pin) might be confronted with an unstable current, which could lead to unwanted side effects, like even causing damage. So I do not think, this is a good idea in general.

    • Yes, it looses decoupling, proper would be to use correct decoupler for correct valtage and current, but it was a quick hack just to make it work when you need it right now! 😉

  3. Didn’t your calculation omit the current passing through the LED? I understand from your calculations that you only took into account the current passing through the relay coil, but shouldn’t the current passing through the LED be added to the current through the transistor?
    Anyway, thanks for the solution!

    • You are right, good catch, with 1k current limiting resistor and 5v it was expecting to get 5mA, so with relay current expectancy was 76mA, in calculations I have chosen Ic 100mA, so its more then enough 🙂

Leave a Reply

Your email address will not be published.


*