chuckdubs
Posts: 5
Joined: Wed Aug 15, 2018 4:10 pm

Bounce issues after connecting 24DC power to relays

Sat Aug 18, 2018 2:12 am

I wrote a program to control some relays that switch electrical components like valves and motors on and off. I have buttons that send signal to raspi, then raspi switches the 5v relays.

I am using npm 'onoff' to control the gpios and debounce the buttons. I have the buttons hooked up to common on one side, and signal on the other, with raspi internal pull-up resistors turned on.

The program works fine, and the buttons function as expected, switching the relays on when the relative button is pressed.

Once I connect the 24DC power to the other side of the relays, the buttons start behaving differently. Now when I press a button and hold it down, the raspi gets the '1' signal repeatedly, at exactly the rate that the debounce is set. For example, if I have debounce set to 50ms, the relay will switch every 50ms as long as I hold down the button.

What can be causing this and how can I troubleshoot?

wh7qq
Posts: 1450
Joined: Thu Oct 09, 2014 2:50 am

Re: Bounce issues after connecting 24DC power to relays

Sat Aug 18, 2018 8:52 pm

Does the 24VDC for the relays and the RPi share a common ground or power supply? The Relays should isolate the RPi from the output contacts. The RPi and the power to the relay coils should be isolated from each other and be on separate power supplies. Do you have anti-flyback diodes across the relay coils? It sounds like the valves/motors may be pulling some current spikes when activated that are getting back into the RPi supply. Are you driving the relay coils directly from the GPIO or using one of the commercial boards that have an opto-isolator on the low voltage input? Best to go that route to maximize isolation.

chuckdubs
Posts: 5
Joined: Wed Aug 15, 2018 4:10 pm

Re: Bounce issues after connecting 24DC power to relays

Thu Aug 23, 2018 11:33 pm

Adding the flyback diode fixed the problem, thank you! Responses below for future users that land on this post.
wh7qq wrote:
Sat Aug 18, 2018 8:52 pm
Does the 24VDC for the relays and the RPi share a common ground or power supply? The Relays should isolate the RPi from the output contacts. The RPi and the power to the relay coils should be isolated from each other and be on separate power supplies.
Yes they have separate power supplies, but the commons are connected in a breadboard since the relay board only has one GND pin, but separate 5v pins to power the relays and signal.
wh7qq wrote:
Sat Aug 18, 2018 8:52 pm
Do you have anti-flyback diodes across the relay coils?
I did not, but after adding these diodes the feedback issue stopped.
wh7qq wrote:
Sat Aug 18, 2018 8:52 pm
It sounds like the valves/motors may be pulling some current spikes when activated that are getting back into the RPi supply. Are you driving the relay coils directly from the GPIO or using one of the commercial boards that have an opto-isolator on the low voltage input? Best to go that route to maximize isolation.
Just using the GPIO pins directly to the relays. Trying to stay away from the commercial boards so I can learn more about how the circuits work.

Brandon92
Posts: 870
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: Bounce issues after connecting 24DC power to relays

Fri Aug 24, 2018 5:29 am

chuckdubs wrote: Just using the GPIO pins directly to the relays. Trying to stay away from the commercial boards so I can learn more about how the circuits work.
So, you driving a relay coil directly from a single GPIO pin? This is not the best idea. And you are lucky that those spikes didn't kill you pi. To give you a small example. A couple years back I tested a bc547 to drive a relay with a 12v coil. When I switch the relay of. Those spikes go up to 200v! And killed some I'm my transistors, as expected.

What for kind of relay are you using and what is the maximum current draw.

User avatar
DougieLawson
Posts: 39296
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Bounce issues after connecting 24DC power to relays

Fri Aug 24, 2018 9:55 am

How noisy is your 24V supply? I've had a load of trouble with a 12V supply causing noise on GPIO pins. One of my friends who's a retired hardware engineer suggested sticking a 4700μF capacitor across the supply to clean it up a bit.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Brandon92
Posts: 870
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: Bounce issues after connecting 24DC power to relays

Fri Aug 24, 2018 1:37 pm

What for power supply are you using by the way. Some (switching) power supply's require a minimum load to maintain a stable output voltage.

wh7qq
Posts: 1450
Joined: Thu Oct 09, 2014 2:50 am

Re: Bounce issues after connecting 24DC power to relays

Fri Aug 24, 2018 6:03 pm

ust using the GPIO pins directly to the relays. Trying to stay away from the commercial boards so I can learn more about how the circuits work.
The commercial relay board mfgrs (SainSmart, etc.) don't use opto isolators just to inflate the parts count. They protect the outputs of the RPi or whatever else is driving from exactly that kind of spike...surprising you have not fried the RPi but you have really dodged a bullet here. You can learn all you like from those schematics (which also include anti-flyback protection).

Return to “Troubleshooting”