What is a relay

Relay (English name: relay) is an electrical control device, is when the input (excitation) of the change to meet the specified requirements, in the electrical output circuit so that the controlled quantity has a predetermined step change of an electrical appliance. It has the interaction between the control system (also known as the input loop) and the controlled system (also known as the output loop). Usually used in automatic control circuits, it is actually a small current to control the operation of a large current “automatic switch”. Therefore, it plays the role of automatic adjustment, safety protection and conversion circuit in the circuit.

Prepare the material

  1. Raspberry piezero wha

  1. 1 relay (Model JQC-3FF-S-Z)

  1. Disassembled USB data cable

  1. LED lights

The relay is connected to the raspberry PI circuit

  • relayVCCPick raspberries pie5v5
  • relayGNDPick raspberries pieGND
  • relayINPick raspberries pieGPIO18

Pay attention to distinguish VCC and GND, do not connect reverse!!

Relays, LED lights and power line connections

  • relayNOPick up the LEDThe anode
  • relayCOMConnect the power supplyThe anode
  • LED The cathodeConnect the power supplyThe cathode

As shown in the figure below

Physical connection diagram

Code to run

vim jdq.py
Copy the code

Write the following

# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
 
# BCM numbering method
GPIO.setmode(GPIO.BCM)
# Set [BCM no. 18] GPIO port to output mode
GPIO.setup(18, GPIO.OUT)
# open
GPIO.output(18, GPIO.HIGH)          
time.sleep(5)
# close
GPIO.output(18, GPIO.LOW)
GPIO.cleanup()
Copy the code

Execute the jdq.py code

python3 jdq.py
Copy the code

When you hear a click, it’s on, and the LED lights go on. When you hear a click, it’s off, and the LED lights go off.

Knowledge extension

Schematic diagram of relay

reference

Raspberry PI C programming to achieve relay control

Use the raspberry PI control relay