0
# 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.

Dirk
  • 3,749
  • 3
  • 19
  • 27
ela kay
  • 19
  • 3

1 Answers1

1

In my case the current from my power supply to the relay module was not sufficient at 1.0 amps. I swapped it out with one rated at 2.0 amps and that got my relays switching. Thank you all.

ela kay
  • 19
  • 3