import RPi.GPIO as GPIOimport time
# GPIO Setup
GPIO.setmode(GPIO.BCM)
PELAY_PIN = 21
LED_PIN = 10
GPIO.setup(RELAY_PIN,GPIO.OUT)
GPIO.setup(LED_PIN,GPIO.OUT)
print("Relay + LED control started")
try:
while True:
GPIO.output(RELAY_PIN,GPIO.HIGH) #Relay ON
GPIO.output(LED_PIN,GPIO.HIGH) #LED ON
print("Relay ON | LED ON")
time.sleep(2)
GPIO.output(RELAY_PIN,GPIO.LOW) #Relay OFF
GPIO.output(LED_PIN,GPIO.LOW) #LED OFF
print("Relay OFF | LED OFF")
time.sleep(2)
except KeyboardInterrupt:
print("Program stopped by user")
finally:
GPIO.cleanup()