Relay Switch Problem Using 74HC595 Shift Register and ESP32

I am currently working on a project where I use a PZEM-016, an 8-ch relay switch, and shift registers, (165 and 595).

All of my components seem to work normally when they are Isolated; the problem arose when I added my PZEM-016 circuit with my relay switch. The relay switch started giving out random outputs, and would frequently fail to light up whenever I turn a relay on. (It lights up but would immediately shuts down). Initially, all my shift registers were powered using Vin of my ESP32, but I tried to put the 595 shift register that is connected with the relay in an external power to see if it would work but it didn't. Additionally, the schematics below are separate because of the limited editing capability of the app I used.


I've read something similar from this post about adding a capacitor?? But I'm not totally sure because we used different microcontrollers. Can anyone please suggest a possible solution? :pray::pray::pray:

You can't drive that relay board with a 595, especially if you power it with 3.3V

Your LEDs in the second image are backwards.

2 Likes

this 8 channel relay board has optocouplers and transistors, so it may be controlled by hc595 with current limiting resistors

1 Like

An explanation would be useful.

I would suggest using a pcf8575 or mcp23017 instead of the 2x 595 + 165. It would save you a lot of wiring and ESP pins.

But if you must use 595 and 165, you must add a 0.1uF ceramic bypass capacitor close to each chip.

You can save pins by daisy-chaining the 2x 595 and also sharing the clock pin between the 585 and 165.

1 Like

If @newb123 asks I wil supply one

That relay module should have the 3 pin header with JD-Vcc, Vcc, and GND.
The board comes with a jumper between JD-Vcc and Vcc, so that the relays are powered by Vcc.
When using a separate power supply for the relays, remove the jumper and apply power to JD-Vcc and GND, with no connection to VCC.
At the 10-pin header there are connections for GND, Vcc, and the 8 inputs to drive the relays.
Connect ONLY the Vcc and relay inputs, with Vcc being the Vcc used for the 74HC595, not the 5V supply for the relay board. DO NOT connect GND, otherwise you lose any benefit from the opto-isolation. There should be no common connections between the power supply for the relay board and the power supply/circuitry on the input side of the board.

The problem may be from powering the 74HC595 from 5v, that puts the minimum HIGH level input voltage very near the supply voltage of the ESP32.

1 Like

I powered the 165 and the second 595 using the Vin pin while the ESP32 is powered through USB. Doesn't that make the Vin pin a 5v?

Now that I looked at my schematics again, I think I saw a couple of mistakes plus the one you have mentioned. Thank you very much, Sir!

Yes but even if the hc595 did have enough current to drive the relay board it would not work because with Vcc = 5V, the minimum Vih for the HC595 is around 3.5V and the ESP can only output 3.3V

1 Like

I tried doing this, but I used the same power supply for my JD-Vcc and Vcc. I think that's the part where I made a mistake. I will retry this technique with your correction; I will use the ESP32 Vin so the 595 is powered separately. Really hope this works.

This is what I have been considering, but I didn't exactly know how to do it. I will give your solution a try. Thank you very much!

It wont work at 3.3V it won't work at 5V.
You need another IC to drive the relays.

But if I try powering my hc595 using an external 5v supply and ground it both with the supply and the ESP. Will it work?

Can you please suggest an IC that I can use for my project?

No.

Let me see.
Can it be a surface mount device?

Use a SN74AHCT595N or SN74HCT595N whichever you can get.
Power it with 5V.
Connect the outputs of the 595 to a 74ACT244N and it's outputs to the relays.

Guaranteed to work.

You should also power the 165 with 3.3V or you will damage the ESP input pin.
I also recommend using the pushbottons pull-up resistors to 3.3V rather than pull-downs on the 165 inputs.

Anything connecting to an ESP32 I/O should be 3.3V

I've asked for this component in our local store, but unfortunately, this wasn't available. I have now ordered one online, and I'll just try some other method while I wait for this. Thank you so much for your help! :))

Hi again, I would like to clarify how I should place my bypass capacitor. I found in this youtube video and they used an electrolytic capacitor like this:

but you've mentioned that I have to put it as CLOSE to the IC as possible. Should I place my ceramic capacitor the same as this one, or should I exclude pin 10 (Vcc) and pin 13 (GND), and just put it in pin 16 and 8?

From the 74hc165 datasheet:

1 Like

You also need the ACT244
Don't forget to power the 165 with 3.3 NOT 5V

1 Like