Need script to make scheduled 8 channel relay outputs
Ask QuestionAsked todayActive todayViewed 4 times1
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
#!/usr/bin/python import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) # 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 try: GPIO.output(10, GPIO.LOW) print ("OZONE") time.sleep(SleepTimeL); GPIO.output(9, GPIO.LOW) print ("PUMP") time.sleep(SleepTimeL); GPIO.cleanup() print ("Good bye!") # End program cleanly with keyboard
gpiopythonrelayShareEditFollowClose 1Flagedited 39 mins agoMilliways48.4k2323 gold badges7979 silver badges159159 bronze badgesasked 59 mins agoGcprince1 New contributor
- 1This is a question on how to program. – Milliways 37 mins ago
Ah, this is a very good program, so flexible to scale up. I would suggest the following changes.
- 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]
- To change operation delay from two seconds to three seconds, say, change the following first statement to second.SleepTimeL = 2SleepTimeL = 3
- 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") time.sleep(SleepTimeL)
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 mins agoanswered 34 mins agotlfong013,67433 gold badges88 silver badges2222 bronze badges
- @Gcprince, please report bugs here. Cheers. – tlfong01 23 mins 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 3 mins ago Edit
Leave a Reply