Page 1 of 2
Relays
Posted: Sat Sep 23, 2017 3:28 pm
by SwannC
Hi all,
I must be doing a rooky mistake. I am trying to control some valves with a raspberry pi (3). Valves opens when puged with 12V, when the pi can only deliver 5V. To overcome that, I am using relays.
Please see the picture below of how I have plugged things.
- IN: GPIO. 7
- GND: Ground (from the pi)
- VCC: 5v (physical pin 2)
russian image upload
Outputs of the relay: not really sure, but based on the back of the component (see below), I should have:
- COM: central pin (plugged to +12V power supply)
- GnD: one of the two (gnd of my 12V power supply)
- LIVE: pne of the two (the + of my valve)
I have then plugged the - of my valve to the 12V power supply ground.
Issue: it does not trigger the relay (switch state) when I change value on my GPIO. 7. What I have done wrong?
Many thanks,
Swann
Re: Relays
Posted: Sat Sep 23, 2017 4:19 pm
by rpdom
It looks like you have an LED wired between GPIO4 (pin7) and IN. Why is that?
Also, how are you controlling the GPIO?
Re: Relays
Posted: Sat Sep 23, 2017 4:25 pm
by gordon77
DON'T connect the +12v and gnd to the relay output, you will short the supply.
Connect 12v in to the centre contact and the 12v feed to the valve to an outer contact, whether it's normally open or closed will determine which.
I modified a similar relay to make it work
viewtopic.php?f=45&t=186210&p=1176810#p1176810
Re: Relays
Posted: Sat Sep 23, 2017 4:43 pm
by SwannC
@rpdom: for now I controll it via the terminal. The LED is there just to see if there's power or not.
@Gordon: thanks. Is there a way I can use it as it and not modify it? As I don't have a soldering iron to hand...
Many thanks,
Swann
Re: Relays
Posted: Sat Sep 23, 2017 4:59 pm
by gordon77
SwannC wrote: ↑Sat Sep 23, 2017 4:43 pm
@rpdom: for now I controll it via the terminal. The LED is there just to see if there's power or not.
@Gordon: thanks. Is there a way I can use it as it and not modify it? As I don't have a soldering iron to hand...
Many thanks,
Swann
Do you have a Web link to the relay you bought?
This looks like it
http://www.dx.com/p/1-channel-12v-low-l ... caU0R_TXMI
But l baffled how an Arduino can switch a 12v relay.
It looks like a 12v model so the 5v from the pi won't switch it. I expect you will need an alternative relay.
Re: Relays
Posted: Sat Sep 23, 2017 5:09 pm
by SwannC
Re: Relays
Posted: Sat Sep 23, 2017 5:10 pm
by gordon77
Your link shows a5v relay, yours is 12v, so l don't expect it to work, see above comments.
I wouldn't trying connecting 12v to the vcc without having a circuit diagram to see how it works, and review comment...
"first of all these are not optocoupling, trigger signal is not isolated from the transistor and relay. " doesn't look promising.
Re: Relays
Posted: Sat Sep 23, 2017 5:18 pm
by SwannC
Hi Gordon,
Thnaks. So let's go back to what I want to achieve. I want to open/close electro valves that are powered at 12V. Since Raspberry PI can only supply 5V, I thought of relays. At a glance: if there is a "up" on one of the pin of the pi, then the valve should open.
Can I achieve it with my current setting (knowing that I have an independent 12V supply) or not?
Many thanks,
Swann
Re: Relays
Posted: Sat Sep 23, 2017 5:28 pm
by gordon77
You are right to think of using a relay. You just need the right board, with opto-isolator and 5v relay, to be powered from the pi.
I have found these 'arduino' boards don't always work with an input from the pi hence my mod.
Maybe others can suggest a suitable board.
Re: Relays
Posted: Sat Sep 23, 2017 5:30 pm
by SwannC
So just to be sure: my assumptions are correct, but the relays are not suitable. Right?
May I achieve the same result with some MOSFET?
Many thanks,
Swann
Re: Relays
Posted: Sat Sep 23, 2017 7:10 pm
by QMESAR
Hi ,
I would do the following to use what I have as hardware and at least can check my SW and the functionality
if you can get a BC337 NPN Transistor (they cost almost nothing) wire the transistor between the RPI pin and the relay and power the relay with the same 12V as the value and the switch the relay with your RPI pin, I dont know the relay however a 470 Ohm - 1K resistor should be fine to protect the pin and drive the Transistor sufficiently to switch on .
I apologize] if I understood the problem incorrectly and probably giving wrong advise here.
Kind Regards
QMESAR

- 1.jpg (22.03 KiB) Viewed 2985 times
Re: Relays
Posted: Sat Sep 23, 2017 7:18 pm
by SwannC
Hi QMESAR,
Tu be sure I got it right, physically with my relay:
- IN: 12V ?
- GND: Ground but in the transistor: will be connected only if GPIO 7.0 is up?
- VCC: 12v
Outputs:
- COM: central pin (plugged to +12V power supply)
- LIVE: pne of the two (the + of my valve)
With the "-" on my valve connected to the ground. Is it correct?
One of the outputs remains unplugged.
Many thanks,
Swann
Re: Relays
Posted: Sat Sep 23, 2017 7:24 pm
by QMESAR
SwannC wrote: ↑Sat Sep 23, 2017 7:18 pm
- GND: Ground but in the transistor: will be connected only if GPIO 7.0 is up?
- VCC: 12v
The Transistor will only switch when the Pin is High (Pin 7)
you also need to have the RPI ground and the 12V ground connected in a Common ground connection
Re: Relays
Posted: Sat Sep 23, 2017 7:28 pm
by SwannC
Ok cool. Just to be clear, the GPIO (via the transistor) shall be plugged to the IN pin of the transistor right?
Sorry I just want to ensure I am not heading in the wrong direction...
Re: Relays
Posted: Sat Sep 23, 2017 7:31 pm
by QMESAR
Hi Also for protection I would run a free wheeling Diode as shown specially in then case where you switch the relay off
a 1N4001 should work

- 1.jpg (21.87 KiB) Viewed 2968 times
Re: Relays
Posted: Sat Sep 23, 2017 7:34 pm
by QMESAR
SwannC wrote: ↑Sat Sep 23, 2017 7:28 pm
Ok cool. Just to be clear, the GPIO (via the transistor) shall be plugged to the IN pin of the transistor right?
You can say like that however the GPIO pin connects to the Base of the transistor through the Resistor the Collector goes to the 12V+ and the emitter to ground
Re: Relays
Posted: Sat Sep 23, 2017 10:34 pm
by boyoh
Pi 5v+---------- ( Relay )-------------( c Transistor e )---------0v- Pi
Pi 3.3v GPIO O/P-------(-260r)------------( b )-----------------0v- Pi
Transistor 2n2222 using as a switch
12v+------------common / / NO---------Valve-----------0v- (12v supply)
common / / NO (normally Open on Relay)
Re: Relays
Posted: Sat Sep 23, 2017 11:40 pm
by davidcoton
QMESAR's second circuit is the way to start -- although I would prefer to see an opto-isolator between Pi and transistor just to be sure the 12V never gets to the Pi.
QMESAR wrote:
You can say like that however the GPIO pin connects to the Base of the transistor through the Resistor the Collector goes to the 12V+ through the relay coil and the emitter to ground
The bit I've added in red is important -- wiring the transistor straight across 12V will give it a very short life.
Always remember that the Pi GPIOs are 3.3V, the Pi powerr supply is 5V, and your relay and valve are at 12V. Mixing these supplies is a recipe for damaging you Pi.
I think you should spend some time reading some basic electric circuit theory, including how to use relays, and simple transistor switches, before trying any more experiments. It may save you from having to buy another Pi.
Re: Relays
Posted: Sun Sep 24, 2017 9:19 am
by gordon77
gordon77 wrote: ↑Sat Sep 23, 2017 4:25 pm
DON'T connect the +12v and gnd to the relay output, you will short the supply.
Connect 12v in to the centre contact and the 12v feed to the valve to an outer contact, whether it's normally open or closed will determine which.
I modified a similar relay to make it work
viewtopic.php?f=45&t=186210&p=1176810#p1176810
I would suggest just buying this relay l linked to, and doing the resistor mod. It's basically the same type of circuit and uses an opto-isolator.
Re: Relays
Posted: Sun Sep 24, 2017 9:51 am
by Burngate
It might be worth looking at this other thread:
viewtopic.php?f=91&t=193908
Re: Relays
Posted: Sun Sep 24, 2017 2:05 pm
by QMESAR
@davidcotton
Thank you for helping out with the correct wording

I did not realize to avoid confusion that i should actually specifically say through the relay coil to 12V+
I have no experience with RPI(BCM) chip however this made me curious
I would prefer to see an opto-isolator between Pi and transistor just to be sure the 12V never gets to the Pi.
as in my experiences with PIC micro controllers and confirmation from Microchip the PORT pins has a clamping diode internally and when voltages above the 3.3V or 5V.3 (3.3 and 5V micro' respectively) the clamping diode clamps the Voltage if there is a resistor in the pin line which limits the current the pin(equal or smaller than pin source current spec) will not be destroyed, in this case if the transistor for some reason causes the 12V to reach the PIC micro pin nothing will happen as the base resistor is limiting the current to the pin. I = +/- 12mA ) in this case and it is well below the 20mA sink/source capability of the PIC pin
Do you guys have any idea or information on the BCM chip PORT pin circuitry from all the post here regarding the opto - isolator I suspect the PORT pins does not contain internal clamping diodes .
Just for interest . Although I can only agree with you on isolating the pin from the 12V circuits it is the most secure

.
Re: Relays
Posted: Sun Sep 24, 2017 2:48 pm
by gordon77
Re: Relays
Posted: Sun Sep 24, 2017 3:34 pm
by QMESAR
Hi
Thank you very much for the link to this very valuable document for Rpi.
It confirms my speculation that in the case of an over voltage at the pin provided that there is a Resistor to limit the current flow nothing will happen to the pin.
May be I just understand all of this incorrectly

Re: Relays
Posted: Sun Sep 24, 2017 3:41 pm
by pcmanbob
Hi SwannC
As you already have your 12v relay board and a 12v solenoid valve I would suggest you just use an opto-isolator to drive your existing relay board and keep the 12v isolated from the pi GPIO as 12v connected to the GPIO will almost certainly not be good for the pi.
you only need a 4n25 or a 4n35 opto-isolator and a 470 ohm resistor.
all connected like this

Re: Relays
Posted: Sun Sep 24, 2017 3:43 pm
by davidcoton
The GPIO pins are clamped. It is not clear what capacity the clamp diode and 3V3 supply has for current from excess (or negative) voltage, probably not as much as 16mA (guesswork).
A while back there were some very controversial experimental results which seemed to show that at least one Pi was tolerant of GPIO conditions way out of spec. IO don't intend to try to repeat those experiments. In other cases Pi GPIOs appear to have died from connection to 5V (without a resistor). So yes, a resistor (highest possible value consistent with delivering enough current in normal use) should be enough protection. Using an optoisolator (especially to drive a local relay which itself provides isolation) is definitely "belt and braces". It is difficult to balance to extra complexity of protection (and consequent risk of wiring errors) against a less well protected KISS approach, my advice tends to be at the extra protection end of the spectrum.
From the above posts it is worth noting:
- the lack of actual quantified abuse (clamp diode) limits
- the different limits for inputs and outputs
- the difference between source/sink capability in normal voltage range, and clamp diode operation