import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
RELAY_PIN = 22
LED_PIN =18
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()