How to use the Raspberry Pi relay module Python

0. First

If you want to see how the things you make this time work, please see here (youtube video).

1. Connect the Raspberry Pi and the relay module

Polish_20200601_154923646.jpg I will connect the wire to this relay module at once. IMG_20200601_154117.jpg GND (green) IN1 (blue) IN2 (red) IN3 (ash) IN4 (white) VCC (black) IMG_20200601_155921.jpg GND (green) >> Pin.6 IN1 (blue) >> Pin.11 GPIO 17 IN2 (red) >> Pin.7 GPIO 4 IN3 (ash) >> Pin.5 GPIO 3 IN4 (white) >> Pin.3 GPIO 2 VCC (black) >> Pin.2 5V IMG_20200601_155936.jpg

2. Write a program

relay.py


import RPi.GPIO as GPIO
import time

#GPIO.setwarnings(False)
#If you get an error like a pin is being used, add this and it will work.
GPIO.setmode(GPIO.BCM)
pinlist = [2,3,4,17]

for i in pinlist:
    GPIO.setup(i,GPIO.OUT)
    GPIO.output(i,GPIO.HIGH)

try:
    for i in pinlist:
        GPIO.output(i,GPIO.LOW)
        time.sleep(2)
    finally:
        print("End of Program!")
        GPIO.cleanup()

When you do this, the lights on the relay module will light up in sequence.

Finally

How to use this relay module is also explained in Youtube, so please have a look if you like it. If you have any questions, please use the comment section of the video or the comment section of this article. Also, if you like it, please subscribe to the channel (https://www.youtube.com/channel/UCDYbu9aViDvkubFcwgbbKDA).

Recommended Posts

How to use the Raspberry Pi relay module Python
How to use Raspberry Pi pie camera Python
How to use the optparse module
How to use the ConfigParser module
Use python on Raspberry Pi 3 to illuminate the LED (Hello World)
How to use the C library in Python
[Algorithm x Python] How to use the list
python3: How to use bottle (2)
How to use the generator
[Python] How to use list 1
Use python on Raspberry Pi 3 to light the LED with switch control!
How to use Python argparse
Python: How to use pydub
[Python] How to use checkio
[Python] How to use input ()
How to use the decorator
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
[Python] How to use the graph creation library Altair
[Introduction to Udemy Python3 + Application] 27. How to use the dictionary
[Introduction to Udemy Python3 + Application] 30. How to use the set
How to use the model learned in Lobe in Python
Try to use up the Raspberry Pi 2's 4-core CPU with Parallel Python
Python: How to use async with
How to use the zip function
Use vl53l0x with Raspberry Pi (python)
[Python] How to use Pandas Series
How to use Requests (Python Library)
How to use SQLite in Python
How to use Python's logging module
How to get the Python version
[Python] How to import the library
[Python] How to use list 3 Added
How to use Mysql in python
How to use OpenPose's Python API
How to use ChemSpider in Python
How to use FTP with Python
Python: How to use pydub (playback)
How to use PubChem in Python
How to use python zip function
[Python] How to use Typetalk API
[Raspberry Pi] Changed Python default to Python3
[python] How to use the library Matplotlib for drawing graphs
How to use the __call__ method in a Python class
[Hyperledger Iroha] Notes on how to use the Python SDK
I didn't know how to use the [python] for statement
Tips for Python beginners to use the Scikit-image example for themselves 7 How to make a module
[Python] Summary of how to use pandas
[Introduction to Python] How to use class in Python?
How to use the Spark ML pipeline
[Python] How to display random numbers (random module)
How to install and use pandas_datareader [Python]
python3 How to install an external module
[python] How to use __command__, function explanation
[Linux] How to use the echo command
How to use the Linux grep command
[Python] How to use import sys sys.argv
I want to run the Python GUI when starting Raspberry Pi