In [ ]:
# Load libraries
import RPi.GPIO as GPIO
import time

In [ ]:
# set GPIO and output pin
GPIO.setmode(GPIO.BCM)
PIN = 18
GPIO.setup(PIN, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN)

In [ ]:
# Close relay (> closing the circuit > current starts to flow)
GPIO.output(PIN, GPIO.HIGH)

In [ ]:
# Open relay
GPIO.output(PIN, GPIO.LOW)

In [ ]:
# Activate and deactivate the relay 10 times in a row
for i in range(10):
    GPIO.output(PIN, GPIO.HIGH)
    time.sleep(0.2)
    GPIO.output(PIN, GPIO.LOW)
    time.sleep(0.3)

In [ ]: