2

I am trying to control a 4-Relay module with my Raspberry Pi 4. I tried to do that by writing this script:

import RPi.GPIO as GPIO
import time


GPIO.setmode(GPIO.BOARD)
relais_1 = 8
relais_2 = 10
relais_3 = 12

GPIO.setup(relais_1, GPIO.OUT)

GPIO.output(relais_1, GPIO.HIGH)

time.sleep(5)
GPIO.output(relais_1, GPIO.LOW)

However, the relay does not turn off after that. By changing it to this setting:

GPIO.output(relais_1, GPIO.LOW)

time.sleep(5)
GPIO.output(relais_1, GPIO.HIGH)

It now works. But that does not make sense, does it?! Hopefully someone will be able to explain this behavior so I can learn something..

Thanks a lot in advance!

3

Most relays are Active LOW - the relay is ON when the input is LOW and OFF when the input is HIGH.

The specification for your relay board should state this.

  • 1
    Ohh, right, thank you so much! In retrospective this was quite a stupid question I guess. But I really appreciate it. There was no information in the specification.. – Vincenzo Köstler Jan 16 at 18:33
  • 1
    However, it is still behaving a bot oddly without cleanup() at the end, every time I start it again it says "this channel is already in use" and it also turns on automatically even if I leave the "low" command out of it. – Vincenzo Köstler Jan 16 at 19:21
  • That is also normal just use GPIO.setWarnings(False) sourceforge.net/p/raspberry-gpio-python/wiki/BasicUsage – CoderMike Jan 16 at 19:26
  • 1
    I see, thank you very much! – Vincenzo Köstler Jan 16 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.