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?