Introduction: Raspberry Pi DIY Relay Board

Picture of Raspberry Pi DIY Relay Board

For some projectes with raspberry and the smaller arduinos I need to switch some relays. Because of the GPIO outputlevel (3,3V) its hard to find some relays that are able to switch larger loads and can operated directly with the given 3,3 volts.

So i decided to build my own relay-board. The 5Channel one i build here is around 10€ for the pieces. In addition you only need a soldering iron, solder and some tools to cut the wires and bend the legs of the components.

This is my first instructable here (and also a very short one), so I hope you can follow my steps.


Step 1: Parts and Layout

Picture of Parts and Layout

So at first the partslist for a 5 channel board, if you need more feel free to scale it:

• 5 relays (or how much you need) with max 5V coil-voltage (I used the JS-12MN-KT-V3, switches max 150VDC /400VAC)
• 5 diodes - UF 4007 (if you want more relays, you also need more of these)
• 5 NPN Transistors - 2N3904
• 7 Pin male or female header (I used both)
• some silver-wire to solder jumbers
• 100mm x 100mm stripboard
• 5 1kOhm resistors
• 5 Screw Terminals (make sure they fit on your stripboard)

Then you also need the following tools:

• Soldering iron
• solder
• sharp knife
• pliers to bend the legs and cut the wires
• a drill to interrupt the strips on the back on the stripboard

Then we have to make some thoughts about the layout. You also can use another pcb without the strip-grid for this project, but i prefer the stripboards. If you want to use the others, here is the schematic attached. To make the layout for the stripboard i just make a copie of it with 200% size, so i can draw the parts on it. Unfortunately I forgot to draw the inputlines from the relays, so you have to add 4 wires more, from the top lane to each one of the relay inputs.

Some thougts on the schematic:

The relay is an inductive load. So it produces an voltage spike when switched off. To prevent damage on the transistor we add the diode parallel to the input from the relay.

Because of the given voltage of the GPIO-ports we can't switch the relay directly. So we use the transistors to switch the relays with the 5V they need. The 5V are provided by the raspberry itself or an external power source.

To connect the board with an arduino or raspi we need some headers. I used male an female headers because i want to use it with arduino and the raspberry. For the 5Ch board we need 7 headers (5 for each realy and two for the 5V input and ground).

Step 2: Solder It All Together

Picture of Solder It All Together

When you have finished your own layout you only need to put it all together. We will work from the smaller pieces to the biggest.

You can easily start with the diodes and the resistors. Put it all on the right places on your board and turn it around. So you can solder them. Be careful to put the diodes in the right way. On the strips where the resisors are, we have to disrupt the strips on the board.

Then you can make the jumpers. Pay attention not so solder the strips together, this can damage your parts or even your controller. Solder the jumpers as close as it possible to the board.

Then we continue with the the transistors. We connect the middle pin, the base, to the header. The Collector is conntected to the relay, the emitter to ground. Here we have to disrupt the strip between the collector and the emitter too.

At least we put the relays and the headers on the board. You have to bend the legs of the relay a bit so that it fits in the grid of the stripboard. Remember do disrupt the strips between the legs of the relays. Depending on what you want to switch with these relays, you can remove the two strips between the legs of the relay to insulate them better from each other (remember the specs of the relay, they can switch quite a lot). To make it easier to connect some devices to it, you can solder some screw terminals to the relay-outputs.

Step 3: Finish an Checking the Board

Picture of Finish an Checking the Board

To check if you had done it all right, we can now connect the board to the RPI. Connect the first pin with 5V and the last with the GND pin of your RPI. Depending on how much relay you have build on the board, you have to connect each pin with one of the GPIO-pins of the RPI. I used the 5th pin as my first but you can choose every one you want, or is free.

To switch the relay you have to give a high-signal to the pin where the relay is connected to. In addition you have to install wiringPi.

Here for example the code for the fifth pin (direct in the shell):

First set the pin to output: gpio -g mode 5 out (with -g you can access the pin from the rpi-layout not from the wiring layout)

Then generate a high signal on the pin 5: gpio -g write 5 1

To turn the relay off you have to delete the high signal: gpio -g write 5 0

When you had done everything rightyou should hear some klicking sounds from the relays. You can also connect a small circuit (eg. battery, led, resistor) to visualise that the relay works.

If you want to build it in something in, make sure you have enough space between the relay board and the case you build it in. For safety reasons: if you want to switch big (DC) loads, make sure they are in the range given by the specs of the relay and you have enough space to isolate the strips and wires to each other.

Hope you enjoyed it, have fun!


oliveira.igorm (author)2017-09-23

are the diodes necessary?

JB95 (author)2016-10-13

Good instructable :) The only thing that confuses me is the fritzing diagram; to me it looks like both sides of the first relay's coil are connected to ground unlike in the hand drawn diagram.

Andri Syarifuddin (author)2016-10-11

thanks for sharing, i will made it

grayl (author)2016-10-10

If the cheap 5 volt relay modules are too tempting, you can buy an
8-bit logic level shifter for less than 2$ to do your relay actuation -
3.3 volts on one side and 5 volt on the other.

germancasteli (author)2016-10-10

This is amazing, thanks for sharing with us.

About This Instructable




More by Campers death:Raspberry Pi DIY relay board
Add instructable to: