Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8013

Python • Re: Controlling Relay Module - Can't turn it off

$
0
0
Start with simple code. No json code to test.
Turn it on.
Wait a few seconds.
Turn it off.
Wait a few seconds.
Repeat.

Edit: I can't tell by the pic if that unit has an optoisolator. If not, you have a current problem
The datasheet on the blue cube states it takes 70ma to activate.
The GPIO pins can supply 12ma source or sink.

Edit2: I found your unit on AliExpress. It appears to have a transistor to drive the relay.
Try simple code.
It is possible the transistor is not turning off when the GPIO pin is HIGH.

.

i tried this code , it turn on but it doesn not turn off only when program is exited and cleanup is performed

Code:

import RPi.GPIO as GPIOimport time# GPIO setupGPIO_PIN = 21GPIO.setmode(GPIO.BCM)GPIO.setup(GPIO_PIN, GPIO.OUT)def control_loop():    try:        while True:            print("Turning on")            GPIO.output(GPIO_PIN, GPIO.HIGH)                        print("Waiting...")            time.sleep(2)  # Wait 2 seconds                        print("Turning off")            GPIO.output(GPIO_PIN, GPIO.LOW)                        print("Waiting...")            time.sleep(2)  # Wait 2 seconds                except KeyboardInterrupt:        print("\nProgram stopped by user")    finally:        GPIO.cleanup()  # Always cleanup GPIO on exitif __name__ == "__main__":    control_loop()

Statistics: Posted by medved.timotej — Wed Oct 30, 2024 11:09 am



Viewing all articles
Browse latest Browse all 8013

Trending Articles