8 channel relay python program

Need script to make scheduled 8 channel relay outputs [closed]

Ask QuestionAsked todayActive todayViewed 17 times1Closed. This question is off-topic. It is not currently accepting answers.

This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center.

Closed 4 hours ago by MilliwaysDirkjoanDougieGhanima.

(Viewable by the post author and users with the close/reopen votes privilege)Edit question

This script fires my relays, but I don’t know how to change duration and need it to fire daily to run pump and ozonator for an iso float tank. I’m currently only using GPIO 9 and 10

import RPi.GPIO as GPIO
import time


# init list with pin numbers

pinList = [10, 9]

# loop through pins and set mode and state to 'low'

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

# time to sleep between operations in the main loop

SleepTimeL = 2

# main loop

  GPIO.output(10, GPIO.LOW)
  print ("OZONE")
  GPIO.output(9, GPIO.LOW)
  print ("PUMP")
  print ("Good bye!")

# End program cleanly with keyboard

gpiopythonrelayShareEditFollowReopenFlagedited 23 hours agoMilliways48.4k2323 gold badges7979 silver badges159159 bronze badgesasked 23 hours agoGcprince1111 bronze badge New contributor

Add a comment

1 Answer


Ah, this is a very good program, so flexible to scale up. I would suggest the following changes.

  1. To scale up from 2 relays to 8 relays, change the following first statement to second:pinList = [10, 9]pinList = [10, 9, 8, 7, 6, 5, 4, 3]

  1. To change operation delay from two seconds to three seconds, say, change the following first statement to second.SleepTimeL = 2SleepTimeL = 3

  1. To scale up two relay operations to eight, change the following 6 line segment to the for loop after.GPIO.output(10, GPIO.LOW)print (“OZONE”)time.sleep(SleepTimeL)GPIO.output(9, GPIO.LOW)print (“PUMP”)time.sleep(SleepTimeL)

for pin in pintlist:

    GPIO.output(pin, GPIO.LOW) 

    print ("OZONE") 


There is 99% chance the my suggested changes create bugs. Don’t worry. Report your bugs as a comment below my answer. Everybody would come to help.

ShareEditDeleteFlagedited 23 hours agoanswered 23 hours agotlfong013,67433 gold badges88 silver badges2222 bronze badges

  • @Gcprince, please report bugs here. Cheers. – tlfong01 23 hours ago    
  • @Gcprince, I would also suggest you to debug your nice little code in Rpi built in Thonny python IDE, which is very newbie friendly and helps to locate errors in its newbie friendly GUI (Graphics User Interface) console window, showing which line makes trouble, and leading you to that exact line where it is, and waits for you to correct it and immediately run it to retry your luck. It is so Pachinko like game fun!. Happy programming. Cheers. – tlfong01 22 hours ago    

Add a comment

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.