Lesson 4 Relay Module

Share for us

Introduction to Relay Module

A relay module is a device that is used to provide a connection between two or more points or devices in response to the input signal applied. It is suitable for driving high-power electrical equipment, such as light bulbs, electric fans, and air conditioning. You can use a relay to control high voltage with low voltage by connecting it to Raspberry Pi.

1-Channel DC5V Relay Module

Required Components

 1 * Raspberry Pi

– 1 * Breadboard

– Several Jumper wires

– 1 * Relay module

– 1 * Dual-color LED module

– 2 * 3-Pin anti-reverse cable

Experimental Principle

Relay Module

– There are 5 parts in every relay:

1. Electromagnet – It consists of an iron core wounded by coil of wires. When electricity is passed through, it becomes magnetic. Therefore, it is called electromagnet.

2. Armature – The movable magnetic strip is known as armature. When current flows through them, the coil is it energized thus producing a magnetic field which is used to make or break the normally open (N/O) or normally close (N/C) points. And the armature can be moved with direct current (DC) as well as alternating current (AC).

3. Spring – When no currents flow through the coil on the electromagnet, the spring pulls the armature away so the circuit cannot be completed.

4. Set of electrical contacts – There are two contact points:

  • Normally open – connected when the relay is activated, and disconnected when it is inactive.
  • Normally close – not connected when the relay is activated, and connected when it is inactive.

5. Molded frame – Relays are covered with plastic for protection.

Connect the SIG pin of this module to GPIO pin. When we make GPIO pin output high level (3.3V) by programming, the transistor will conduct because of current saturation. The normally open contact of the relay will be closed, while the normally closed contact of the relay will be broken; when we make it output low level (0V), the transistor will be cut off, and the relay will recover to initial state.

The schematic diagram of the module is as shown below:

Experimental Procedures

Step 1: Build the circuit.

Raspberry PiGPIO Extension BoardRelay Module
Dual-color LED ModuleGPIO Extension BoardRelay Module
R*Normal Open
G*Normal Close

For C Users:

Step 2: Change directory. 

    cd /home/pi/SunFounder_SensorKit_for_RPi2/C/04_relay/

Step 3: Compile.

    gcc relay.c -lwiringPi

Step 4: Run.

    sudo ./a.out

For Python Users:

Step 2: Change directory. 

    cd /home/pi/SunFounder_SensorKit_for_RPi2/Python/

Step 3: Run.

    sudo python3 04_relay.py

Now, you may hear the ticktock. That’s the normally closed contact opened and the normally open contact closed. You can attach a high voltage device you want to control, like a 220V bulb, to the output port of the relay. Then the relay will act as an automatic switch.