Relay Module(SONGLE) raspberry pi 4 Testing

The Raspberry Pi is a series of credit card-sized single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in schools and developing countries.

Post Reply
User avatar
/RaspberryPi
Corporate
Posts: 2449
Joined: Wed Jun 05, 2019 1:29 am

Relay Module(SONGLE) raspberry pi 4 Testing

Post by /RaspberryPi »


hi need some help on relay modules(Songle brand) on my raspberry pi. The relay module operates on 5v but most youtube video shows to connect into 3.3v. So i have done some work by connecting to 3.3v but it doesnt work however when connecting to 5v it works. But here comes another issue, the relay is turned on constantly. I tried using python to program it but alternating the relay turn off and turn on but to no avail. Once code runs, the relay is continuously even when its time to time off. I have to terminate the program to stop the relay. Please advised thank you so much.

Relay VCC: connecting to 5v of raspberry pi (pin 2)
Relay IN: connecting to GPIO 18 (pin 12)
Relay Gnd: Ground pin (pin 14)



Code:

import RPi.GPIO as GPIO
from time import sleep
# Set up GPIO mode
GPIO.setmode(GPIO.BCM)
# Define the GPIO pin connected to your relay
relay_pin = 18
# Set up the GPIO pin as an output
GPIO.setup(relay_pin, GPIO.OUT)
try:
# Loop indefinitely
while True:
# Turn the relay on
GPIO.output(relay_pin, GPIO.HIGH)
print("Relay turned ON")

# Wait for 5 seconds
sleep(5)

# Turn the relay off
GPIO.output(relay_pin, GPIO.LOW)
print("Relay turned OFF")

# Wait for 5 seconds
sleep(5)
# Clean up GPIO on program exit
except KeyboardInterrupt:
GPIO.cleanup()

Thanks!


submitted by /u/PuzzleheadedSwing618
[link] [comments]

Source: https://www.reddit.com/r/raspberry_pi/c ... 4_testing/
/RaspberryPi
Post Reply

Return to “Raspberry Pi Forum”