AlexanderAlexander
Posts: 3
Joined: Wed Jan 30, 2019 3:49 pm

I'm having trouble with my code turning my relays on and of repeating any suggestions?

Tue Jun 04, 2019 2:55 am

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

# Relay pin numbers
pinList = [2, 3, 4, 17, 27, 22, 10, 9, 11, 5, 6, 13, 19, 26, 21, 20]

#Turn ON relays in the start

for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.LOW)

# Time after which relays will turn OFF i have set it to 5 seconds.

SleepTimeL = 1

try:
while True:

time.sleep(SleepTimeL);
for i in pinList:
GPIO.output(i, GPIO.HIGH)

time.sleep(SleepTimeL);
for i in pinList:
GPIO.output(i, GPIO.LOW)

# End program with ctrl+C with keyboard
except KeyboardInterrupt:
print " Quit"


I figured out print and quit and I turn it on with sudo python relay but when they all turn on they wont turn off I want them to fire repeatedly any help

ghp
Posts: 1352
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: I'm having trouble with my code turning my relays on and of repeating any suggestions?

Tue Jun 04, 2019 4:06 am

Identation is important in python. Please re-edit your post and add Code-Tag viewtopic.php?f=32&t=84477

Which relay-board are you using and how are the connections between RPi and the board ?

pcmanbob
Posts: 6224
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: I'm having trouble with my code turning my relays on and of repeating any suggestions?

Tue Jun 04, 2019 6:32 am

Your relay board is probably active low and its control circuit is probably running at 5v , so the problem is caused by the 3.3v gpio .

see this explanation : viewtopic.php?f=91&t=83372&p=1225448#p1225448

if you tell us which relay board you have ( post a link to were you purchased it from or its data sheet ) we can help with an interface circuit to make it work.

some other points

you don't need sudo to run your example code

please use code tags when posting code to preserve the indentation

Add [code] at the top

code goes here

and [/code] at the bottom.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Python”