Controlling the relay using the Raspberry Pi
To start with, we will control only the relay from the Raspberry Pi connected to it. This will be done using GPIO pins. First, we need to connect the relay to our Raspberry Pi in the correct way. The following table shows the connection scheme:
Wire (color |
GPIO pin |
Relay pin |
Red |
3.3V (pin 1) |
Power/VCC (+) |
Black |
GND (pin 6) |
GND (-) |
Yellow |
GPIO 17 (pin 11) |
IN (Signal/S) |
When this scheme is physically applied, it will look like the following figure. Remember that the exact order of the relay pins might look different between different models.
When the connection to the relay is complete, we can continue with next step: turning on or off the small LED connected to the relay. Most relays have a small LED attached to them. If your relay doesn't have an LED indicator, don't worry; we will look at some methods of checking from the command line...