zepol
Posts: 12
Joined: Thu Nov 09, 2017 1:43 am

Connecting Raspberry 3 to 16 relay board

Thu Nov 09, 2017 1:48 am

Hey all,

I'm new to raspberry and I'm trying to do my own Christmas light show, I'm using Falcon Player (FPP) on my RB3 , I tried to connect it to my 16 relay board using jumper cables but it doesn't work, it seems as long I connected it, it stopped working, I connected both ground and 5V too, my relay board has power source too (12 V) , so does anyone know what are the equivalents of each pin, I'm basically using all GPIOs from left side.

User avatar
DougieLawson
Posts: 37073
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Connecting Raspberry 3 to 16 relay board

Thu Nov 09, 2017 7:41 am

Most of the cheapo Chinese relay boards are ACTIVE LOW. You need a GPIO connected to one of the relay pins, you need GND connected to RPi GND. The JC-Vcc to Vcc jumper MUST BE REMOVED. The 12V supply connects to GND and Vcc.

The you pull the GPIO low to activate the relay.

Code: Select all

import RPi.GPIO as GPIO
from time import sleep     
GPIO.setmode(GPIO.BCM)     # set up BCM GPIO numbering
GPIO.setup(25, GPIO.IN)    # set GPIO25 as input (button)
GPIO.setup(24, GPIO.OUT)   # set GPIO24 as an output (relay)

try:
    while True:            
        if GPIO.input(25): # if port 25 == 1
            print "Port 25 is 1/HIGH/True - RELAY active"
            GPIO.output(24, 0)        
        else:
            print "Port 25 is 0/LOW/False - RELAY OFF"
            GPIO.output(24, 1)       
        sleep(0.1)         # wait 0.1 seconds

finally:                   
    GPIO.cleanup()       
That python program will activate the relay on pin#18 (GPIO24) when pin#22 (GPIO25) goes high.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
davidcoton
Posts: 4531
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Connecting Raspberry 3 to 16 relay board

Thu Nov 09, 2017 9:51 am

DougieLawson wrote:
Thu Nov 09, 2017 7:41 am
The JC-Vcc to Vcc jumper MUST BE REMOVED.
Correct.
DougieLawson wrote:
Thu Nov 09, 2017 7:41 am
The 12V supply connects to GND and Vcc.
Possibly wrong. My guess is that the 12V is for the relay contact side, to drive the lights? The relay coils will probably need 5V, and the input opto-isolators 3V3 (anything else risks damaging your Pi). I'm not sure from memory which of JC-Vcc and Vcc is which (Be certain to get it right -- otherwise your Pi may be damaged) -- do you have a weblink to your relay board?
DougieLawson wrote:
Thu Nov 09, 2017 7:41 am
Then you pull the GPIO low to activate the relay.
Once the supply connections are sorted out, you can test the relays by corefully connecting the input to 3V3 or ground, instead of a GPIO pin. That will determine whether your board needs active high or active low inputs.

+1 on pinout.xyz for GPIO usage info.
Signature retired


zepol
Posts: 12
Joined: Thu Nov 09, 2017 1:43 am

Re: Connecting Raspberry 3 to 16 relay board

Fri Nov 10, 2017 1:50 am

The JC-Vcc to Vcc jumper MUST BE REMOVED.
this relay board doesnt have the jumper, I could send you the pic of it but it's just the same as the one in the link I posted

User avatar
DougieLawson
Posts: 37073
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Connecting Raspberry 3 to 16 relay board

Fri Nov 10, 2017 2:15 am

OK, so it's one of the newer ones where the board designer has eliminated the (somewhat confusing) JC-Vcc to Vcc jumper.

It needs 12V to drive the relay coils and a 5V GPIO signal to drive the on-board opto-isolators. The 3.3V GPIOs on the Raspberry may not work as a HIGH signal on the input to those opto-isolators (it depends on the forward voltage of the LED in the isolator).

If your RPi can't drive those you'll either need to use a BJT/MOSFET transistor as an additional switch for each GPIO or connect a MCP23017 to your RPi's I²C bus and run that chip at 5V. It's relatively easy to program an MCP23017 with python.

https://www.raspberrypi-spy.co.uk/2013/ ... pi-part-1/
https://www.raspberrypi-spy.co.uk/2013/ ... pi-part-2/
https://www.raspberrypi-spy.co.uk/2013/ ... pi-part-3/
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

pcmanbob
Posts: 7936
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Connecting Raspberry 3 to 16 relay board

Fri Nov 10, 2017 10:51 am

If you have a read of this thread viewtopic.php?f=63&t=190608&hilit=16+relay

It gives details of how to test if your card is high or low active and if low how to drive it using two ULN2803A chips as an interface between the relay board and the pi.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

zepol
Posts: 12
Joined: Thu Nov 09, 2017 1:43 am

Re: Connecting Raspberry 3 to 16 relay board

Mon Nov 20, 2017 2:52 am

DougieLawson wrote:
Fri Nov 10, 2017 2:15 am
OK, so it's one of the newer ones where the board designer has eliminated the (somewhat confusing) JC-Vcc to Vcc jumper.

It needs 12V to drive the relay coils and a 5V GPIO signal to drive the on-board opto-isolators. The 3.3V GPIOs on the Raspberry may not work as a HIGH signal on the input to those opto-isolators (it depends on the forward voltage of the LED in the isolator).

If your RPi can't drive those you'll either need to use a BJT/MOSFET transistor as an additional switch for each GPIO or connect a MCP23017 to your RPi's I²C bus and run that chip at 5V. It's relatively easy to program an MCP23017 with python.

https://www.raspberrypi-spy.co.uk/2013/ ... pi-part-1/
https://www.raspberrypi-spy.co.uk/2013/ ... pi-part-2/
https://www.raspberrypi-spy.co.uk/2013/ ... pi-part-3/
Hey thank you so much for your replies, sorry for late response I was out of internet, to be honest I dont know if I have the time to do this, also bc I'm kinda new to this stuff, basically what I'm doing is :
- Powering the relay board with a 12V charger
- Matching 5 v from RB
-Matching GND from RB
- Matching GPIOs to each pin of the relay (16)

I'm using FPP but to be honest I dont know what kind of configuration I have to do there, in the ouputs setup , I was trying with the E1.31 and I tried to played a sequence but it didnt work

pcmanbob
Posts: 7936
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Connecting Raspberry 3 to 16 relay board

Mon Nov 20, 2017 1:10 pm

I'm using FPP but to be honest I dont know what kind of configuration I have to do there, in the ouputs setup , I was trying with the E1.31 and I tried to played a sequence but it didnt work
So what is FFP ? and what is E1.31 ?

did you read the post I linked to ? you should have been able to test your relay board using the instructions to determine if it was high or low activation.

for code try this simple python2 program .

you just need to replace the ? with a GPIO number of one of the GPIO's you are using to control your relays.

Code: Select all

import RPi.GPIO as GPIO
import time

# enter your gpio number

pin = ?

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

GPIO.setup(pin, GPIO.OUT)

GPIO.output(pin, GPIO.LOW)
print pin, "output low"
time.sleep (5)
GPIO.output(pin, GPIO.HIGH)
print pin, "output high"
time.sleep (5)
GPIO.output(pin, GPIO.LOW)
print pin, "output low"
time.sleep (5)
GPIO.output(pin, GPIO.HIGH)
print pin, "output high"
time.sleep (5)
if your relay card can be driven using the GPIO directly ( which I suspect it may not ) then you should see the relay switch on and off
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

zepol
Posts: 12
Joined: Thu Nov 09, 2017 1:43 am

Re: Connecting Raspberry 3 to 16 relay board

Tue Nov 21, 2017 1:48 am

pcmanbob wrote:
Mon Nov 20, 2017 1:10 pm
I'm using FPP but to be honest I dont know what kind of configuration I have to do there, in the ouputs setup , I was trying with the E1.31 and I tried to played a sequence but it didnt work
So what is FFP ? and what is E1.31 ?

did you read the post I linked to ? you should have been able to test your relay board using the instructions to determine if it was high or low activation.

for code try this simple python2 program .

you just need to replace the ? with a GPIO number of one of the GPIO's you are using to control your relays.

Code: Select all

import RPi.GPIO as GPIO
import time

# enter your gpio number

pin = ?

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

GPIO.setup(pin, GPIO.OUT)

GPIO.output(pin, GPIO.LOW)
print pin, "output low"
time.sleep (5)
GPIO.output(pin, GPIO.HIGH)
print pin, "output high"
time.sleep (5)
GPIO.output(pin, GPIO.LOW)
print pin, "output low"
time.sleep (5)
GPIO.output(pin, GPIO.HIGH)
print pin, "output high"
time.sleep (5)
if your relay card can be driven using the GPIO directly ( which I suspect it may not ) then you should see the relay switch on and off
FPP is Falcon Pi Player, that's the "OS" I'm using, and the E3.1 is basically the ouput configuration in FPP where I'm planning to do the setup, I'm gonna check out if I can run python code in the FPP because I'm not sure about it.

Thanks

pcmanbob
Posts: 7936
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Connecting Raspberry 3 to 16 relay board

Tue Nov 21, 2017 8:57 am

I have never seen that OS nor have I seen it mentioned on this forum , so you may not get much help.

does it not have its own support forum ?
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

zepol
Posts: 12
Joined: Thu Nov 09, 2017 1:43 am

Re: Connecting Raspberry 3 to 16 relay board

Sat Dec 02, 2017 10:13 pm

pcmanbob wrote:
Tue Nov 21, 2017 8:57 am
I have never seen that OS nor have I seen it mentioned on this forum , so you may not get much help.

does it not have its own support forum ?
Yeha they have but it' not pretty useful so I'm still trying to figure that out, I supposed to have all the connection right, but it doesnt work, I thought it was because of the relay but the relay has Optocoupler so I'm thinking is either I'm connectign the pins or the way I'm exporting the sequences from vixens

Pictures below is basically what I got so far:

GPIOS configuration in FPP
https://www.screencast.com/t/Pbz48SYSb

https://www.screencast.com/t/2uu79o4fWj

And Vixen configuration

https://www.screencast.com/t/TAmo5BLLj

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12585
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Connecting Raspberry 3 to 16 relay board

Sat Dec 02, 2017 10:54 pm

Read this it should answer Your questions.viewtopic.php?f=91&t=83372&p=1225448#p1225448

pcmanbob
Posts: 7936
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Connecting Raspberry 3 to 16 relay board

Sun Dec 03, 2017 11:35 am

zpeol
DO NOT USE THIS DIAGRAM FOR YOUR RELAY BOARD SEE BELOW.


I think you problem is more likely to be hardware related, did you read the post I posted a link to and test your relay card.

As your relay card is 12v powered for the relays you would need to add a connetion from the 5v pin on the gpio to power the opto-isolators and the ULN2803A's

Image

you could also check you are actually driving the pins you think you are by replacing the relay board with 1K resistor and LED wired in series connected to each gpio pin and ground in turn to test the output of your program.
Last edited by pcmanbob on Mon Dec 04, 2017 11:46 am, edited 2 times in total.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

zepol
Posts: 12
Joined: Thu Nov 09, 2017 1:43 am

Re: Connecting Raspberry 3 to 16 relay board

Sun Dec 03, 2017 10:42 pm

pcmanbob wrote:
Sun Dec 03, 2017 11:35 am
I think you problem is more likely to be hardware related, did you read the post I posted a link to and test your relay card.

As your relay card is 12v powered for the relays you would need to add a connetion from the 5v pin on the gpio to power the opto-isolators and the ULN2803A's

Image

you could also check you are actually driving the pins you think you are by replacing the relay board with 1K resistor and LED wired in series connected to each gpio pin and ground in turn to test the output of your program.
Hey , I'm doing the test with the leds and the resistors right now, also I did what you said, the pins from pi (5v) are connected to the 5V on the relay , since the relay has them integrated(octocoupler) I assume it powers them

https://www.screencast.com/t/y61ho2amyiV

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12585
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Connecting Raspberry 3 to 16 relay board

Sun Dec 03, 2017 11:08 pm

a picture of the relay board is nice, but we actually need a schematic of it. this one seems to have a switching regulator, but we do not know what it does, or how the optocouplers are wired.

zepol
Posts: 12
Joined: Thu Nov 09, 2017 1:43 am

Re: Connecting Raspberry 3 to 16 relay board

Sun Dec 03, 2017 11:20 pm

mahjongg wrote:
Sun Dec 03, 2017 11:08 pm
a picture of the relay board is nice, but we actually need a schematic of it. this one seems to have a switching regulator, but we do not know what it does, or how the optocouplers are wired.
This is the information the seller sent to me about the relay
http://wiki.sainsmart.com/index.php/101-70-103

One question, currently I'm using the NO ports, those ones are the ones getting the 110V supply , could it be the reason? I mean that it has to be NC (Normally closed terminals)

pcmanbob
Posts: 7936
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Connecting Raspberry 3 to 16 relay board

Mon Dec 04, 2017 11:43 am

So looking at the supplied information about your relay board, it looks like the opto-isolators are being supplied by an on board 5v regulator powered from the 12v input to the board.

so to activate a relay you need to connect a ground to the IN pin on the board and a high of 5v to switch the relay off or just remove the ground connection. if you read through the link post it explained how to test your relay board to prove its operation.
If you have a read of this thread viewtopic.php?f=63&t=190608&hilit=16+relay

It gives details of how to test if your card is high or low active and if low how to drive it using two ULN2803A chips as an interface between the relay board and the pi.
so with all jumpers in place ( if there are any ) as the board was supplied you can control the board using the pi gpio using 2 ULN2083A chips as I said wire like this.

Image

As your relay board has an onboard 5v regulator we can use that to power the opto-isolators and just provide a ground via the ULN2083A chips.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

zepol
Posts: 12
Joined: Thu Nov 09, 2017 1:43 am

Re: Connecting Raspberry 3 to 16 relay board

Mon Dec 04, 2017 6:49 pm

pcmanbob wrote:
Mon Dec 04, 2017 11:43 am
So looking at the supplied information about your relay board, it looks like the opto-isolators are being supplied by an on board 5v regulator powered from the 12v input to the board.

so to activate a relay you need to connect a ground to the IN pin on the board and a high of 5v to switch the relay off or just remove the ground connection. if you read through the link post it explained how to test your relay board to prove its operation.
If you have a read of this thread viewtopic.php?f=63&t=190608&hilit=16+relay

It gives details of how to test if your card is high or low active and if low how to drive it using two ULN2803A chips as an interface between the relay board and the pi.
so with all jumpers in place ( if there are any ) as the board was supplied you can control the board using the pi gpio using 2 ULN2083A chips as I said wire like this.

Image

As your relay board has an onboard 5v regulator we can use that to power the opto-isolators and just provide a ground via the ULN2083A chips.
Do I really need two use two additional ULN2083A , since they are already integrated on the board?

pcmanbob
Posts: 7936
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Connecting Raspberry 3 to 16 relay board

Mon Dec 04, 2017 8:48 pm

The problem is the pi can't drive the relay board because you need a high of 5v to switch the relay off after you use a low to switch it on. The pi gpio 3.3v can't do this.
There are no ULN2803A chips on your relay board, only opto-isolators but they are set up to work at 5v.

The other option is to use a level shifter between each gpio pin and the relay inputs so you could drive it at 5v.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

zepol
Posts: 12
Joined: Thu Nov 09, 2017 1:43 am

Re: Connecting Raspberry 3 to 16 relay board

Tue Dec 05, 2017 3:24 am

pcmanbob wrote:
Mon Dec 04, 2017 8:48 pm
The problem is the pi can't drive the relay board because you need a high of 5v to switch the relay off after you use a low to switch it on. The pi gpio 3.3v can't do this.
There are no ULN2803A chips on your relay board, only opto-isolators but they are set up to work at 5v.

The other option is to use a level shifter between each gpio pin and the relay inputs so you could drive it at 5v.
Okay thanks, tomorrow I'm buying them and doing that wiring I'll let you know how it goes, I was checking the other thread you told me and i wanna try the part when you said: "So if you have a reading of 5v then try connecting one of the pins to gnd pin and see if the relay activates, if it does not then try connecting the same number pin to the 5v pin and see if it activates." this means connecting only one pin from the pi to the relay either GND or the 5v right? and then executing the script to activate it? or do I have to wire any other pin, also what if this doesn't work?

klricks
Posts: 6775
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Connecting Raspberry 3 to 16 relay board

Tue Dec 05, 2017 5:13 am

zepol wrote:
Tue Dec 05, 2017 3:24 am
pcmanbob wrote:
Mon Dec 04, 2017 8:48 pm
The problem is the pi can't drive the relay board because you need a high of 5v to switch the relay off after you use a low to switch it on. The pi gpio 3.3v can't do this.
There are no ULN2803A chips on your relay board, only opto-isolators but they are set up to work at 5v.

The other option is to use a level shifter between each gpio pin and the relay inputs so you could drive it at 5v.
Okay thanks, tomorrow I'm buying them and doing that wiring I'll let you know how it goes, I was checking the other thread you told me and i wanna try the part when you said: "So if you have a reading of 5v then try connecting one of the pins to gnd pin and see if the relay activates, if it does not then try connecting the same number pin to the 5v pin and see if it activates." this means connecting only one pin from the pi to the relay either GND or the 5v right? and then executing the script to activate it? or do I have to wire any other pin, also what if this doesn't work?

As a test you should be able to manually operate the relay by connecting to the full time power pins. NO SCRIPT

A ground wire must be connected between the RPi and relay board at all times. Pin 39 or 25 etc.

First test the 3V3 by connecting a second wire from the relay 1 control to a full time 3V3 power pin (1) on the RPi. Move the same wire to ground (pin 6) and then back. If you can manually operate the relay this way then it should also work with a programmable GPIO without any hardware modifications.

If the relay does not operate at 3V3 then try the same test using the full time 5V pin 2 on the RPi.
If it now works then you must add external circuits such as level shifters when using the GPIO to control the relay.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

User avatar
DougieLawson
Posts: 37073
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Connecting Raspberry 3 to 16 relay board

Tue Dec 05, 2017 8:48 am

One thing to note is that the MCP23017 can run at 5V without risking the 3V3 I2C bus on your RPi. That gives you 16 GPIO per chip that can all drive a 5V relay controller.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

pcmanbob
Posts: 7936
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Connecting Raspberry 3 to 16 relay board

Tue Dec 05, 2017 12:52 pm

So if you have a reading of 5v then try connecting one of the pins to gnd pin and see if the relay activates, if it does not then try connecting the same number pin to the 5v pin and see if it activates
the test was to determine what activates the relay, 5v or ground you don't need the pi at all for this test you have a 5v pin and a ground pin on the relay board along side the In1 to In16 pins, so you use them.

Your board looks exactly the same as the one that was in the linked post so you will probably find that putting a connection from ground to In1 will activate relay 1, but connecting 5v pin to In1 will result in no activation.

hence the low enable for this type of relay board, but to switch a relay off you need to go from low to high but the high needs to be 5v, by using the ULN2803A you do away with the need to apply 5v as it just applies or removes the ground, it also means that now a high output on the gpio activates the relay which is what most people and software would expect which may explain why your program is not working as it is probably outputting a high to turn the relay on.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

zepol
Posts: 12
Joined: Thu Nov 09, 2017 1:43 am

Re: Connecting Raspberry 3 to 16 relay board

Wed Dec 06, 2017 2:42 am

pcmanbob wrote:
Tue Dec 05, 2017 12:52 pm
So if you have a reading of 5v then try connecting one of the pins to gnd pin and see if the relay activates, if it does not then try connecting the same number pin to the 5v pin and see if it activates
the test was to determine what activates the relay, 5v or ground you don't need the pi at all for this test you have a 5v pin and a ground pin on the relay board along side the In1 to In16 pins, so you use them.

Your board looks exactly the same as the one that was in the linked post so you will probably find that putting a connection from ground to In1 will activate relay 1, but connecting 5v pin to In1 will result in no activation.

hence the low enable for this type of relay board, but to switch a relay off you need to go from low to high but the high needs to be 5v, by using the ULN2803A you do away with the need to apply 5v as it just applies or removes the ground, it also means that now a high output on the gpio activates the relay which is what most people and software would expect which may explain why your program is not working as it is probably outputting a high to turn the relay on.
Hey there I already bought the two ULN2803, I have the circuit like you describe it on the picture, I tried with one single GPIO trying to activated but it doesn't work yet ( I use a LED with a resistor before the ULN and it works), I attached a pic of what I'm working with

The white wire is GND , the green one is the 5v, the one I'm testing is the first pin on the ULN on the right

Also I'm checking the voltage and before the ULN is either three or zero, but after it, it changes, I think it should be 5 right?

https://www.screencast.com/t/vfHDJhFAs

Return to “Troubleshooting”