# import GPIO and datetime
import RPi.GPIO as GPIO
import datetime
# set GPIO numbering mode and define output pins
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(37,GPIO.OUT) #Relay 1
GPIO.setup(35,GPIO.OUT) #Relay 2
GPIO.setup(33,GPIO.OUT) #Relay 3
GPIO.setup(31,GPIO.OUT) #Relay 4
GPIO.setup(32,GPIO.OUT) #Relay 5
GPIO.setup(36,GPIO.OUT) #Relay 6
GPIO.setup(38,GPIO.OUT) #Relay 7
GPIO.setup(40,GPIO.OUT) #Relay 8
# Turn lights on and off based on the time
try:
while True:
now = datetime.datetime.now().time()
if now.hour == 9 and now.minute == 5:
print(now)
GPIO.output(40,True)
else:
GPIO.output(40,False)
finally:
# cleanup the GPIO before finishing :)
GPIO.cleanup()
I have a separate power supply for the relay with 5v to JD-vcc, GND to GND and vcc to 3.3v on raspberry pi.
print(now)gives me the current system time but nothing on the relay. all i want for now is to switch the relays on and of at specific times. I am new to this any help is appreciated.
(b) "Rpi GPIO 5V Relay Problem": https://raspberrypi.stackexchange.com/questions/99988/rpi-gpio-controlling-5v-relay-problem/100021#100021.
– tlfong01 Mar 28 '20 at 08:48