I have Raspberry Pi B+ and i just bought 8 channel relay. i successfully connected but i really need a simple code to run it to trun on and off the channel relay?
would you please help me
I have Raspberry Pi B+ and i just bought 8 channel relay. i successfully connected but i really need a simple code to run it to trun on and off the channel relay?
would you please help me
Simsim,
#!/usr/bin/python import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) # init list with pin numbers pinList = [17, 23] # 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(17, GPIO.LOW) print "ONE" time.sleep(SleepTimeL); GPIO.output(23, GPIO.LOW) print "TWO" time.sleep(SleepTimeL); GPIO.cleanup() print "Good bye!" # End program cleanly with keyboard except KeyboardInterrupt: print " Quit" # Reset GPIO settings GPIO.cleanup()
This code assumes two relays are used and wired to BCM pin 17 and 23. If you wire differently, change pinlist and the two output as well.
Clem
Simsim,
#!/usr/bin/python import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) # init list with pin numbers pinList = [17, 23] # 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(17, GPIO.LOW) print "ONE" time.sleep(SleepTimeL); GPIO.output(23, GPIO.LOW) print "TWO" time.sleep(SleepTimeL); GPIO.cleanup() print "Good bye!" # End program cleanly with keyboard except KeyboardInterrupt: print " Quit" # Reset GPIO settings GPIO.cleanup()
This code assumes two relays are used and wired to BCM pin 17 and 23. If you wire differently, change pinlist and the two output as well.
Clem