AnswerBun.com

Why is this relay turning on when booting up/down my raspberry PI?

Electrical Engineering Asked by kimv on November 4, 2020

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?

2 Answers

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.

Correct answer by Simon B on November 4, 2020

As an aside: you are using a relais module, with optocouplers on its inputs, so your schematics are a bit misleading.

Anyway: the Pi could be doing all sorts of things with its IO pins on start-up, I don't know the Pi well enough to tell you exactly what happens, but high-impedance is the most likely.

You need a pull-up resistor instead of a pull-down resistor to get the relais module to behave like you want, as a pull-down resistor will activate the relais when there is no other input (the module is active-low).

You want to pull up to the Pi's 3.3V logic level, not to 5V; I'm not sure where the 5V in your schematics comes from. If the relais module won't work properly with 3.3V logic levels then there is some more work to do.

Answered by ocrdu on November 4, 2020

Add your own answers!

Related Questions

Two different ways to open a project in IDE’s for MCUs

1  Asked on October 29, 2021 by homecloud

         

Relay and wifi module

1  Asked on March 4, 2021 by thaaoblues

     

MOSFET differential pair with feedback

1  Asked on February 28, 2021 by jtaft121

 

Newbie question about BMS boards and 18650 cells

1  Asked on February 28, 2021 by kercap

 

Schottky diodes as full bridge rectifier

1  Asked on February 27, 2021 by electronicsnoob

       

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP