How to use a relay module with your Raspberry Pi, BeagleBone or Arduino

Today I’ll just upload a short how-to article, explaining how to use a relay module. Some time ago I bought a dirt cheap relay module for controlling high power LEDs with a Raspberry Pi on Amazon. One of these modules cost about 2$ (shipping included), which is a fantastic price, so I ordered 5 modules. In this very short article, I want to explain how you can use such a module in one of your projects.

But what is a relay? It is a simple magnetic switch. If it’s supplied with a voltage, a little coil in the relay’s housing will get magnetic and close a contact and therefore it will also close the electrical circuit, just like your light switch. So you could say that a relay is an automatic switch. But what makes it special? Most relays have a way higher voltage and amperage rating than let’s say transistors. My relay module comes with two independent relays on one board. The PCB has some male headers on the right side and one PCB screw-terminal with three ports per relay:

51FGxOPkFoL
Figure 1: The relay module with it’s connections

Most of the connections should be pretty self-explanatory, but here comes a complete table with the descriptions of each terminal/header:

Pin-Name Function
VCC +5V supply voltage for the relay. Might differ if you have a different relay/board, refer to your relay’s datasheet if you are uncertain about your relays supply voltage.
GND Ground
INx Input x for controlling the relay, where x is a whole number. My board has two relays so, for example, IN1 is for controlling relay 1. Pull this PIN low to close the relay’s output.
NOx Normally Open (NO) contact of the relay. If the relay’s IN pin is high, no current will flow on this terminal.
COMx The ground line of the voltage supply for the consumer.
NCx Normally Closed (NC) contact of the relay. Current will flow through this terminal if the relay’s IN pin is high.

Let me give you an example. If you want a 12V motor to turn whenever your first relay’s contacts are closed, you connect one of the motor’s inputs to NO1, your 12V supply’s ground line to COM1 and the IN1 to whatever controls your relay (Let’s say a Raspberry Pi’s GPIO). Afterward, you connect the VCC and GND pins to a 5V power supply (or in this example your Raspberry Pi) and the motor’s other input to the positive pin of the 12V power supply. Now whenever you pull the relay’s IN1 pin low, the relay’s contacts will be closed and your motor will turn.

Table of contents

How to use a relay module (You are here)
How to use an ethernet module
How to use an EEPROM
How to use the ESP8266 for wireless communication

comment-banner

10 thoughts on “How to use a relay module with your Raspberry Pi, BeagleBone or Arduino

  1. My brother suggested I may like this website.
    He used to be entirely right. This publish actually made my day.
    You can not consider just how much time I had spent for this information! Thanks!

    Liked by 1 person

    1. Hello! This month will not be many articles because I’m currently working on some larger projects (Don’t worry, I’ll write about them here later) and because during the summer months I expect less traffic on the site, because people are on vacations etc, so I’m saving the articles for later. However I might write some short ones, but I don’t want to guarantee anything. In the second half of September I’m planning to go back to the known cycle (A new article every 4-5 days).

      Liked by 2 people

Leave your two cents, comment here!

This site uses Akismet to reduce spam. Learn how your comment data is processed.