Noise on GPIO Pins. Would Cat6 Cable help?

I have about 7 feet (2 meters) between some relays and my Raspberry Pi 3B+. The relays act as switches (taking the default to use internal pull-up resistors.) The cable between the relays and the GPIO pins is 18/7 solid copper thermostat cable.

Overall, they work most of the time, but there seems to be a lot of noise. Sometimes the switches will show closed and opened several times in the course of a second. Other times they don’t show the correct state of the relay.

Before I try to relocate the relays closer to the RPi, would replacing the thermostat cable with Cat6 cable reduce any induced noise?

You don’t really say whether your seeing the noise on the input or output of the relay. Assuming output I think the first thing I would try is putting some external pullups on the lines. The internal pullups can’t be that powerful. 10K to positive voltage should work. Also the contacts will chatter for some amount of time after a change.

1 Like

Thanks micque. Yes, it’s the “output” of the relay. The relay contacts are basically just a switch.

I think I read somewhere that the internal pull-up resistors are something like 50-65k Ohm. Adding 10K seems like a pretty big step, even if I disabled the internals. Granted, I’d only be burning an extra mA or two.

I could also change the bouncetime parameter to debounce better. These things should never cycle more than every few minutes, so something like a 1- or 2-second debounce would be fine.

But I got to thinking; a more reliable long-term solution might be to reduce the run of the wires, or replace them with something more resistant to noise. Which got me wondering whether Cat6 (which I have lying around) would be “better” than thermostat cable, which is neither shielded nor twisted.

Well certainly twisted and/or shielded would be more noise tolerant. I have typically used twisted/shielded cable for longer runs. Contact bouncing happens in 10’s or 100’s of milliseconds and I wouldn’t think more than 1/2 a second would be necessary but you should definitely debounce the relay. If you’re seeing voltage changes then that makes me think maybe bad ground, ground loop, poor pullups. Is the ground on the relay the same as your Raspberry Pi?

1 Like

Use twisted cable for long runs. Use debouncer on api for the debouncing effects of the relay or switch (It is already on arduino api but i am not sure on rpi). You can also use opto-couplers for noise elimination. A friend of mine is using opto-couplers with 30-40m cat5-cat6 runs on magnetic contact sensors and eliminated all noise issues with these opto-couplers. Let alone cat6 didn’t helped a lot.

1 Like

The rpi_gpio integration defaults to 50ms for debounce, which I will increase to 500 or more just to see if that problem goes away. I think that’s the least of my worries anyway. Even if the switch is “on” for a few extra seconds a day, it doesn’t really impact any of my calculations.

The relay coil is electrically totally separate from the contacts. No shared ground. There’s one wire from a “GND” GPIO pin to one contact, and from there jumpers to the one contact on each of the other relays. They’re all together on a rail. I’m using screw terminals on a GPIO break-out board, not a breadboard and pins. Same on the relay side. Contacts are all new and clean.

I’m hoping it’s not that bad. As I said, I’ve only got about a 2m run right now, and if it came to that, I could extend the relay coil wires and move the relay rail up next to the RPi. It’s much more convenient where it is now, but if that’s my best choice I’ll go with that before adding opto-couplers. Much as I’d love an excuse to buy some and play with them :wink:

Is the issue that your seeing the extra on/off for a second or so or that you’re seeing on/off for longer periods of time? If only for a short time then that’s likely debounce issues not noise.

Both. The extra on/offs (4-6 of them over the span of a second or two) aren’t always associated with a “real” on/off event. I think there are also times when “real” on/offs don’t go through, or don’t go through right away, as well. It’s all very hard to pin down since it’s not consistent. I’m also going to wait a few days and do some analysis on the logs to see if any patterns emerge.

Ok so with regards to ground you need to have a common ground between the output of the relay and your rpi. In other words, on the relay output, one side should be connected to rpi ground the other side connected to rpi pin. If you don’t have a common ground then your rpi has no way to judge hi from low voltage.

1 Like

Input to the relay is irrelevant to ground issue. It could share same ground but doesn’t have to.

The wires running off your pi are not perfect super conductors of course so to some extent they will act as resistors, antennas and inductors. Your noise could be coming from a lot of places so you can address it in a few ways. Twisted pairs of wires tend to pick up the same noise so it can cancel out. Shielded cables will pick up less interference. Probably worth $10 to sacrifice a shielded network cable to the cause. :slight_smile:

1 Like

Right. That’s what I’ve got. We are just saying it differently. It’s far easier with a picture, but think of an electrical schematic. For the purposes of this side of the circuit, the normally open contacts of the relay are a switch. One side is connected to GND, the other to GPIO##.

That’s pretty much my theory. I do have some Cat6 laying around, no need to cut anything that’s already fabricated. Right now I want to gather some more data as to exact symptoms and their frequency. Then I’ll be able to say with some confidence whether changing out the cable helps.

Sounds like you are right. More investigation is required.

Update: I added “bouncetime: 5000” to the rpi_gpio platform definition in configuration.yaml. That seems to have eliminated the multiple on/off events. I may bring that back to a more reasonable debounce interval. Five seconds is probably overkill. But for now it allows me to focus on the other issue; getting incorrect on/off values.

Yesterday, I heard the heat come on in the zone I was in, but no event triggered in HA. Today, another zone triggered “on” but didn’t go “off” when the cycle ended and the relay opened (switch “off.”) So far these are the only two errors I’ve caught. Most of the time it seems to be working well, but then again, if I’m not home and actively watching, I may never notice.

I’ll continue to monitor to see if there’s any pattern, and find a way to shorten up or replace the signal wires the next chance I get.