Raspberry Pi – Turning Lights on and off Using Relay Board

In this post, we will be learning about connect 4 Channel relay board to Raspberry Pi. If you haven’t done the RPi setup then please read Raspberry Pi – Introduction and Setup.

What is a relay?
A relay is an Electrical Switch which is used to open or close a circuit with an electromechanical relay or electronically. It is generally used to switch lower current. It changes their states when energies, from No( Normally Open) to Close or from NC ( Normally Close) to Open.

We will need following things:
1. Raspberry Pi (I am using RPi 3 Model B)
2. Jumper Wires
3. Relay Board (I am using 4 Channel relay board)
4. Batteries
5. LED Light Lamp (You can take any LED strip. I just fetched out my LED light lamp’s strip.)

Connecting Relay board to RPi:
4 Channel relay has 6 lines.
GND, VNC, IN1, IN2, IN3, IN4

Note: If you have 2 or 8 channel relay. VNC and GND will be same but counts of INput pins will be different.

Pin Configuration:
GND goes to RPi’s Ground
VNC goes to RPI’s 5V
IN1, IN2, IN3, IN4 goes to RPi’s GPIO pins.

I have only one lamplight. I am attaching it to the first channel.

Are all devices connected?

Coding Part:
I created 3 programs for our demo.
1. TunrOn.py: It will be used for turn on the light. (Turning on one channel)
2. TunrOff.py: It will be used for turn off the light. (Turning off one channel)
3. BlinkAll.py: It will be used for turn on and off all the channels.

See code on GitHub.

Get some GPIO programming knowledge here.

Now save all these 3 files on RPi. Now run these files one by one using a terminal (cmd):
python TurnOn.py
python TunrOff.py
python BlinkAll.py



1 thought on “Raspberry Pi – Turning Lights on and off Using Relay Board”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s