1

I am trying to turn a relay on and off using a python script. The below script is realy simpel, turn the relay on and after 5 seconds turn it off.

The thing is, it dooesn't turn off. i thought it did because i had the cleanup() in there. But no...

It is probably something realy dumd that i am forgetting.

#!/usr/bin/env python

import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

GPIO.setup(27, GPIO.OUT)
GPIO.setup(26, GPIO.OUT)

GPIO.output(27, GPIO.LOW)
GPIO.output(26, GPIO.LOW)

time.sleep(5)

GPIO.output(27, GPIO.HIGH)
GPIO.output(26, GPIO.HIGH)

print("wegwgwegweg")

time.sleep(10)
GPIO.cleanup()

The relay bnoard that i am using is: https://www.kiwi-electronics.nl/nl/16-kanaals-5v-relais-module-4322 16CH relay board

Note that i am only using 3 relay's currently to limit the power usage of the 5v line on the PI

8
  • 3
    Relays are usually active-low, so turn the pin low to deactivate. Sep 14, 2021 at 18:13
  • 1
    The GPIO.LOW Turns the relay on. How would you suggest doing it?
    – ggiinnoo
    Sep 14, 2021 at 19:03
  • 2
    You have the wrong relay. It probably needs 5V logic to operate.
    – joan
    Sep 14, 2021 at 19:39
  • 4
    You should know that there are many different types of relays and electrical specifications. With no information on which relay you're using, it will be very difficult for anyone here to help you much. Please edit your question, add some details on your relay, and perhaps describe what it is you're trying to accomplish. This is not a difficult question if you can provide a few details.
    – Seamus
    Sep 14, 2021 at 20:56
  • 1
    Sorry I meant turn the pin high to deactivate. The logic would be the opposite to what you'd expect. Sep 14, 2021 at 23:56

0

Your Answer

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

Browse other questions tagged or ask your own question.