Unexpected high voltage on digital pins during power shutdown

Has anyone had issues with digital pins going high after/during device power shutdown? I have built a garage door opener using Blynk. It’s very simple. I simply have a Blynkapp button directly assigned to my D0 pin (that is initialized in setup as an output:
“PinMode(D0, output);”

The pin is tied to the signal pin of relay 1 on a 2 relay module I got from Sunfounder. It works perfectly with output of the relay attached to the “close button” terminals of my opener. However if I pull the USB pwr plug on my Photon somehow the relay closes momentarily and my door will activate (and close or open). I got this project from Make magazine and to avoid this problem (they mentioned it but I ignored cause it makes no sense) they tie 2 digital output pins to the 2 relay modules in series. Somehow this strange behavior does not occur in all pins/relays at the same time.

Hello,

Let me ping someone that might be able to help, @rickkas7 are you able to assist?

Kyle

Thanks Kyle. It’s such a weird problem at this point it’s just driving me crazy not knowing how this stuff works.

@Sklarm, is it possible to try using an Ax pin instead of a Dx pin to drive the relay? Pulling power on a device can lead to unexpected events while the regulator output decays but not sure why you get those results. Is the relay module powered from the Vin pin of the Photon?

Thanks PK I Connected the relay module pwr to the Photon 3v3 regulated output. I can try using an Ax pin.

@Sklarm, the 3.3v output can’t supply enough current for the relays. You may want to connect to Vin instead.

Since we also don’t know what relay boards you are using exactly and how they are powered we can only guess.
One thing that comes to mind is the voltage induced into the relay coil by the collapsing magnetic field when swtiching off the relay.
This is the reason why relays should also have flyback diodes attached to protect the rest of the circuitry against that voltage spike.

I’m using a Sunfounder 2ch-5v relay module with 2 high voltage Songle relays , Part no

SRD-05vdc-SL-C

Here is a pic of the board: