Relay causes GPIOs flicker/on-off rapidly

When starting Mycodo (8.15.8) with a 4 channel relay installed to 5 V (JD-VCC) and 3.3 V (VCC) it causes all the GPIOs to flicker/turn on-off rapidly. If starting without the relay connected, or connecting the power to it while running, it runs normally.

This happens regardless of I plug the system to a 3 A+ or a Zero W Pi - BUT it does not happen when running on an older version of Mycodo (8.12.9)

The relay is controlled by a Bang-Bang On/Off function with a light sensor (BH1750), the relay is a standard SRD-05VDC-SL-C. I use a raspberry power supply.

I have tested back and forth, reinstalled Mycodo and Raspbian without success, the error comes right back… I have measured the voltages at the pins and it´s ok.

Any ideas what can be the issue?
Thanks in advance

Are you powering the relay board from your Pi’s 5v and 3.3v pins at the same time?
If so, that is most likely your problem.
You are shorting out the Pi’s power rails and have most likely permanently damaged your Pi.
Even if you are not crossing the 3 and 5 volt pins, you are still likely drawing WAY too much current from the GPIO bus, and can easily damage the Pi that way as well.
The coils in the relays need a significant amount of current to work, and the Pi’s GPIO pins can not supply that kind of power.
You’ll need to power the low-side of the relays from a separate, dedicated PSU, and then only have the 4 GPIO signal wires and a ground wire that go from the relay board to the Pi’s GPIO.

Thanks for your reply!
What I have found, you can/should use 5 V for the JD-VCC, and that you can use the rpi´s 3.3 V (and optional the 5 V for the VCC)

I have tested with the relay module only connected to 5 V (JD-VCC and VCC bridged) also, same thing happens.

The thing is that when booting the rpi with the older version of Mycodo it runs as it should (indicating that I have not permanently damaged the pi)

I would suggest you familiarize yourself with Ohm’s Law if you haven’t already.
Also, you should always reference the official Raspberry Pi documentation before you believe what you see on a random youtube video. Raspberry Pi Documentation - Raspberry Pi hardware

I don’t care what some random youtube video tells you, I am telling you exactly what you need to know to fix your problem…
You can not cross the 5v and 3.3v pins on the pi, period.
You can not reliably run a 4 channel coil relay from the 5v or 3.3v pins of the Pi, period.
(if you were using a Solid State relay, it would probably be OK, but not a coil relay)

You MUST use a separate dedicated 5v power supply for the low-side voltage on the coil relay because the Pis maximum current draw from the 5v pin is only what your Pi’s power supply is MINUS what the Pi is already using… So if you have 2A power supply, and the Pi is already using about 1.5A, that only leaves 0.5A for all of the peripherals that you have plugged into the GPIO voltage pins… which is NOT enough to run your coil relay. Each coil on a 5v relay can use 60ma or more… so when all 4 coils are energized, that means your relay is pulling 240ma or more. And then you also have whatever sensors you have attached which are also drawing current.

You have made no mention of what your power supply is rated for… I would bet that it is maxed out when your relay is energized. Just because a power supply says it is rated for 2 amps, does not mean it can actually provide a full 2 amps constantly… if you run a PSU at or near it’s maximum rating, it will overheat, and quickly fail… and it will also suffer from current and voltage drops, which is what is causing your problem.

Also, you have not specified if the relay board you are using is high-level or low-level triggered. That is VERY important. Mycodo can use both types, but you need to make sure you have the correct settings for your relay board… and of course the high-level trigger will use more power from the Pis GPIO header. If you are using a Raspberry Pi to run Mycodo, you will need to use a high-level trigger relay board… low-level triggered relays do not work reliably with the Pi due to it’s low-level voltage output not being enough to turn off the relay once it is turned on.

As far as the older version of Mycodo working and the newer version not working… that can easily be caused by changes in the software that require more power from the hardware… for instance, a 32 bit OS will use less power than a 64 bit OS installed on the same machine.

Please use a separate 5v PSU to power your relay. If you look at the Raspberry Pi documentation, it will tell you the same thing… don’t power high-current draw hardware directly from the GPIO pins, always use a separate power supply for peripherals.

1 Like

I have the same problem with Mycodo 8.15.8, after powering the Pi the outputs start flickering. My relays are powered by an external 5V power supply and they are solid state relays so shouldn’t be a problem

Does the relay board use a low-level trigger, or high-level trigger?
What is the output startup state that you have set for those relays in Mycodo?
If you are using a low-level trigger relay, and you have the output state set to off in Mycodo, you might see this “flickering” behavior because the Raspberry Pi’s Low-Level voltage signal is not quite enough to set a low-level trigger relay to off.
Also, even if you are powering the relay board from it’s own dedicated PSU, you can still have signal problems if your Raspberry Pi is not using a good power supply or USB cable, or if there is too much power being drawn from the Pi’s PSU due to other peripherals that are attached to the GPIO.

I use 4x SSR-40DA solid state relays with high-level trigger. My power supply is a phoenix contact 5V//25W power supply, which should be enough because there are no consumers connected to it except the Pi.
The problem isn’t that just one output starts to flicker, but all of them are in sync at the same time

Regardless whether or not your PSU can handle it, it is still not recommended to power anything other than a few sensors directly from the Pi’s 5v or 3.3v pins.
You may want to try powering the relay board with a separate PSU from the Pi and see if it resolves the issue.
If you are absolutely sure you have eliminated all of the things previously discussed in this thread, and you are still seeing this behavior, then also make sure you don’t have any conflicting Functions or Actions that may be causing this. The only times I have witnessed similar behavior firsthand was due to conflicting Functions or Actions that were trying to access the relay at the same time. If not, then you may want to post this as an issue on the github page.

I use a 2.5 A Raspberry Pi PSU so there should be quite enough power.
I have only one channel connected to the relay and only a few sensors (temp, light)

I have now tried to use a separate PSU for the relay (at the JD-VCC) - Exactly the same thing happens! The relay (and my control-LED) flickers/flashes. Even if I disconnect the relay (as well as everything, including sensors) this continues after reboot. If inactivating sensors and methods in Mycodo and rebooting the system resets.

Might be best to post as an issue as you suggest.


Are you connecting and disconnecting these things while the Raspberry Pi is connected to power? If so, it’s very possible you have damaged your Raspberry Pi, which could be the reason you are seeing this behavior.

Have you tried enabling the “Log level:Debug” for each of your relay Outputs and then checking the daemon log for any errors?

Of course not, I shut down the system and unplug it before making any changes (and still: It works fine, relay and all, running on the older version of Mycodo, using a different sd-card)
Must admit that I am not that confident with checking daemon log for erros, will dig into that…

Sorry. Just trying to be thorough and eliminate all possible hardware faults before proceeding to possible software issues. If there is a software issue causing this behavior, it should show up in the daemon log, and if you have the “Log Level:Debug” checkbox ticked in all of your relay Outputs, then you should get more information if there is an actual error.

1 Like

No worries - just starting to get a bit “upset” with myself since I dont get it to work as I want it to…


Problem is the inducted current by energizing the relay coils.
I had this myself and it is a golden law in building machines to never power your peripherals from your controller. Just don’t, saves you from getting gray hair before turning 30 :wink:

That means hard and fair: you need money to buy a lot of different power supply, Stepdown-Regulators and sort of things. Buying in China is only an option if you know what you are buying.

And working with different voltages, polarities and also maybe deadly mains electricity needs to be done with absolute focus. 24 Volts kill your Raspberry Pi, 115/230V kills you (if you are lucky it is done quick). Sorry for hard words in my first post, but i really learned this stuff in RL :slight_smile:

better safe than sorry

liebe gruesse
Herr H