Search code examples
raspberry-pipython-3.7raspberry-pi4

connect a pi Raspberry to a relay


hello I have a Raspberry pi 4 and wanted to connect to a relay but I can not find information on how to connect a Raspberry pi 4 and the relay equal to the photo someone can me I will then program in python, someone can help me. Thank you very much!

enter image description here


Solution

  • Assuming you already have built your relay and setup all the wiring you can just create a simple python script to use the relay:

    #!/usr/bin/env python
    
    import time
    
    import RPi.GPIO as GPIO
    
    
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(17, GPIO.OUT)
    GPIO.output(17, GPIO.LOW)
    
    time.sleep(0.25)
    
    GPIO.output(17, GPIO.HIGH)
    GPIO.cleanup()