import RPi.GPIO as GPIO import time import sys # Use BCM GPIO numbering GPIO.setmode(GPIO.BCM) # Set GPIO pin 18 as output relay_pin = 18 GPIO.setup(relay_pin, GPIO.OUT) # Function to turn on the relay def turn_on_relay(): GPIO.output(relay_pin, GPIO.HIGH) # Function to turn off the relay def turn_off_relay(): GPIO.output(relay_pin, GPIO.LOW) # Check command line arguments if len(sys.argv) != 2: print("Usage: python3 control_relay.py ") sys.exit(1) command = sys.argv[1] if command == "on": turn_on_relay() print("Relay is ON") elif command == "off": turn_off_relay() print("Relay is OFF") else: print("Invalid command. Use 'on' or 'off'.") # Clean up GPIO settings #GPIO.cleanup()