Electrical – Why is this relay turning on when booting up/down the raspberry PI

raspberry pirelay

I bought this relay from amazon https://www.amazon.co.uk/gp/product/B06XK6HCQC/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&psc=1

I'm trying to use it to turn power on/off for a stepper motor I'm using. I've previously used a single channel relay for this which turned on when the signal was HIGH and off when the signal was LOW. It seems like this new relay works in exactly the opposite way. I'm guessing this is because the 4 channel relay is "active low".

It currently works if I just send LOW when I need to turn it on and HIGH when I need to turn it off, even if it seems counter intuitive to do it this way. My main concern is the relay is almost on when the raspberry pi is booting up for the first few seconds. By almost on I mean that the LED signalling me that the relay is in it's normal closed position is on, but not as bright as when I turn it on by sending the LOW signal to it. I don't think current is passing through it in this state. This almost on state also appears after I turn off the Pi with sudo shutdown now. As you can imagine, I would prefer the relay to be completely off in this state. Here's a diagram of how things are wired

enter image description here

I have also tried adding a pull-down resistor, although I'm not sure I'm doing it right. See diagram below. With this wiring, the almost on state mentioned above is turned into an on state, which is even worse because current is flowing through the relay from boot until I run the script and send a HIGH signal to the relay.
enter image description here

  1. How should I wire things so that the relay doesn't turn on when the pi boots up/the script is not running/ pi boots down?
  2. Less important: is there a way to turn on the relay by sending HIGH and turn it off by sending LOW?

Best Answer

If the relay module needs pulling high to turn it off, then you need a pull-up resistor to 3.3V, not a pull-down resistor to GND. I'm not sure what the 1K resistor is for.

On most microprocessors, a GPIO pin can be in one of three states:

  • Output low
  • Output high
  • Input, high impedance

(Because it's a GPIO pin, not a GPO pin).

On powering up, the safest option is the third - high impedance. That way, if the pin is intended to be inputting a signal from another system, the processor won't mess things up by pulling the GPIO pin high or low, and damaging either itself or the circuit that's driving it.