suicidal_orange
Posts: 217
Joined: Sun Mar 16, 2014 10:56 am

Relays and the like

Sat Apr 19, 2014 10:28 am

Sorry if this is the wrong place but it seems like the most hardware oriented section :)

I'm trying to make a Pi power on and off using one momentary switch and a powerbank which has a momentary on/off button. What I need to achieve is very simple in words but I'm not entirely sure what component(s) I need.

All I want is when the Pi is off the button press goes to the powerbank, but when the Pi is on it goes to the Pi.

So is this just a SPDT relay triggered by a GPIO I set high (using 5v so as to not blow my Pi)? Seems like like the easiest option, but a waste of power being as the relay will always be on.

Or I could use a latching relay which is great until the powerbank runs out of power, when the button will be stuck in Pi mode and there will be no way to turn it on...

Is there a third option I'm missing? Most Pi power circuits seem to involve an optocoupler, should I be looking at one of them?

Thanks for any thoughts.
Last edited by suicidal_orange on Sat Apr 19, 2014 11:15 am, edited 1 time in total.

johndough
Posts: 254
Joined: Sun Jan 13, 2013 2:00 pm

Re: Relays and the like

Sat Apr 19, 2014 10:55 am

suicidal_orange wrote:Sorry if this is the wrong place but it seems like the most hardware oriented section :)

I'm trying to make a Pi power on and off using one momentary switch and a powerbank which has a momentary on/off button. What I need to achieve is very simple in words but I'm not entirely sure what component(s) I need.

All I want is when the Pi is off the button press goes to the battery, but when the Pi is on it goes to the Pi.

So is this just a SPDT relay triggered by a GPIO I set high (using 5v so as to not blow my Pi)? Seems like like the easiest option, but a waste of power being as the relay will always be on.

Or I could use a latching relay which is great until the battery dies, when the button will be stuck in Pi mode and there will be no way to turn it on...

Is there a third option I'm missing? Most Pi power circuits seem to involve an optocoupler, should I be looking at one of them?

Thanks for any thoughts.
Hi

Not sure what parts are involved.

Pi
Battery
Switch
POWERBANK???

If you have a voltage source and want to ......

suicidal_orange
Posts: 217
Joined: Sun Mar 16, 2014 10:56 am

Re: Relays and the like

Sat Apr 19, 2014 11:14 am

Ah sorry I changed name half way through, I'll correct it :oops: The powerbank is a battery, but it's a pre-made unit that handles charging and has a power button rather than just a battery which needs to be disconnected.

I have a physical switch, if there is power (the Pi is on) I would like the relay(?) to switch the switch to register on the GPIO pin but if the power is off the switch needs to go to the powerbank/battery (to turn it on)

Relays seem to be designed to be power switches for bigger things rather than redirecting switches - I don't need massive isolation or the ability to run mains through it, just an electronic switch switcher :lol:

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Relays and the like

Sat Apr 19, 2014 12:44 pm

Here's how i would do this with a physical switch (3 pole), a transistor, a relay and two GPIO pins.

First setup a 5v relay triggered by a GPIO pin (as demonstrated here) except using a relay with both normally open and normally closed contacts. (SPDT: single position dual throw)

Now we simply wire the output of the momentary switch to the common of the relay, if the Pi is on the relay will be energised and the normally open contact will send a signal to another GPIO pin. If the pi is off the relay will be de-energised and the momentary switch will instead go to the powerbank.
Doug.
Building Management Systems Engineer.

suicidal_orange
Posts: 217
Joined: Sun Mar 16, 2014 10:56 am

Re: Relays and the like

Sat Apr 19, 2014 1:26 pm

BMS Doug wrote:Here's how i would do this with a physical switch (3 pole), a transistor, a relay and two GPIO pins.

First setup a 5v relay triggered by a GPIO pin (as demonstrated here) except using a relay with both normally open and normally closed contacts. (SPDT: single position dual throw)

Now we simply wire the output of the momentary switch to the common of the relay, if the Pi is on the relay will be energised and the normally open contact will send a signal to another GPIO pin. If the pi is off the relay will be de-energised and the momentary switch will instead go to the powerbank.
Thanks Doug, that was what I was thinking but there are a couple of extra components :)

I am puzzled by your selection of a 3 pole switch though, not even sure I've seen a 3 pole momentary? Hopefully it's a typo, if not please can you explain how it would be wired?

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Relays and the like

Sat Apr 19, 2014 1:44 pm

had, well, the thing is that I originally thought that you were doing something else, them I realised what you were doing but I didn't revise the materials list...

After a bit of research I think you may be able to achieve your goal with a depletion mode FET.

Use the RPi GPIO output to switch the FET to prevent the momentary switch signal from reaching the powerbank while the RPi is on.
Doug.
Building Management Systems Engineer.

suicidal_orange
Posts: 217
Joined: Sun Mar 16, 2014 10:56 am

Re: Relays and the like

Sat Apr 19, 2014 2:07 pm

Thanks for clearing that up, I'm now happy with the relay option. But what about this FET...

The first useful result when I searched for "depletion mode mosfet raspberry" was
plugwash wrote:Avoid depletion mode mosfets if you value your sanity, they need weired voltage combinations to drive.
here :lol:

I'll have to search a bit more!

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Relays and the like

Sat Apr 19, 2014 4:33 pm

I'm so out of practice with transistors, 22 years since I really studied electronics but reading more about depletion mode mosfet does show that they are hard to setup.

The relay is certainly the easier option and it's power consumption is only about half a Watt so it shouldn't bankrupt you to have it on all the time while the RPi is on.

So to answer your original question:

the first option will definitely work;
the second option could be made to work but will eat your powerbank battery while waiting for the signal;
the third option is depletion mode mosfet which is very complicated to design into a circuit.
Doug.
Building Management Systems Engineer.

suicidal_orange
Posts: 217
Joined: Sun Mar 16, 2014 10:56 am

Re: Relays and the like

Sat Apr 19, 2014 5:58 pm

Glad it's not just me being stupid trying to read about mosfets, I'll get the relay. Thanks Doug :)

johndough
Posts: 254
Joined: Sun Jan 13, 2013 2:00 pm

Re: Relays and the like

Sun Apr 20, 2014 11:24 am

suicidal_orange wrote:Ah sorry I changed name half way through, I'll correct it :oops: The powerbank is a battery, but it's a pre-made unit that handles charging and has a power button rather than just a battery which needs to be disconnected.

I have a physical switch, if there is power (the Pi is on) I would like the relay(?) to switch the switch to register on the GPIO pin but if the power is off the switch needs to go to the powerbank/battery (to turn it on)

Relays seem to be designed to be power switches for bigger things rather than redirecting switches - I don't need massive isolation or the ability to run mains through it, just an electronic switch switcher :lol:
Hi

Still not with the lingo.

Are you looking for a BBU (Battery Back Up) to keep your Pi running if the mains should fail? Almost a UPS?

If so I normally monitor the supply to the battery, connect a relay across it.

So it is always energised.

Then I would connect the Pi to the common pair.
The Battery to the N/C pair.
The supply to the N/O.

When supply drops out so does the relay, and the battery connects. A small hold up capacitor could be added across the Pi common pair to keep things going for the 200 milliseconds the relay takes to drop out.

No GPIO pin monitoring at all.

No switches, no transistors and no buttons.

suicidal_orange
Posts: 217
Joined: Sun Mar 16, 2014 10:56 am

Re: Relays and the like

Sun Apr 20, 2014 1:31 pm

johndough wrote:Are you looking for a BBU (Battery Back Up) to keep your Pi running if the mains should fail? Almost a UPS?
The powerbank already is a UPS except for the "shutdown when battery is low" part, which I don't need. But as well as wanting to be able to transport it while in use I need a shutdown switch because it will be turned off overnight and at the weekend :)


Is there any reason not to use a 5v 370ohm relay (such as this one) directly from the 5v on the Pi? It's only drawing 13.5mA if I'm doing the maths correctly...

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Relays and the like

Sun Apr 20, 2014 8:05 pm

suicidal_orange wrote:Is there any reason not to use a 5v 370ohm relay (such as this one) directly from the 5v on the Pi? It's only drawing 13.5mA if I'm doing the maths correctly...
Yes, surge protection.
Relays use electromagnets, when you break the supply you can sometimes generate a back emf with higher voltage, don't cook your pi.
Doug.
Building Management Systems Engineer.

suicidal_orange
Posts: 217
Joined: Sun Mar 16, 2014 10:56 am

Re: Relays and the like

Mon Apr 21, 2014 9:13 am

Thanks Doug but I think I said it wrong again :oops:

I wasn't meaning without the diode etc but I was wondering why most relays are 100ohm or less if you can simply up the impedance and lower the power usage - surely that's what everyone wants?

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Relays and the like

Mon Apr 21, 2014 10:14 am

suicidal_orange wrote:... but I was wondering why most relays are 100ohm or less if you can simply up the impedance and lower the power usage - surely that's what everyone wants?
If I can stick my oar in here ...
A relay is just a coil of copper wire to make a magnetic field.
For the same field, you could use more turns, and you'd need less current
- But to fit it all in the same space, you'll need thinner wire
- - And that means higher resistance
- - - which means higher voltage
So power-wise you're back where you started

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Relays and the like

Mon Apr 21, 2014 2:57 pm

suicidal_orange wrote:Thanks Doug but I think I said it wrong again :oops:

I wasn't meaning without the diode etc but I was wondering why most relays are 100ohm or less if you can simply up the impedance and lower the power usage - surely that's what everyone wants?
A reversed voltage isn't the only possible outcome, it's also possible that the relay could generate an increased voltage of the same polarity. (Not likely, but possible).
Doug.
Building Management Systems Engineer.

suicidal_orange
Posts: 217
Joined: Sun Mar 16, 2014 10:56 am

Re: Relays and the like

Mon Apr 21, 2014 11:54 pm

Burngate wrote:If I can stick my oar in here ...
A relay is just a coil of copper wire to make a magnetic field.
For the same field, you could use more turns, and you'd need less current
- But to fit it all in the same space, you'll need thinner wire
- - And that means higher resistance
- - - which means higher voltage
So power-wise you're back where you started
Please do :)

So one of the most expensive relays that just happened to have the highest impedance was due to the complexity of needing a longer thin wire in the coil rather than any real world benefit (except perhaps size)? Sounds like I'd be better off with four cheap standard impedance ones than one of these. Just as well as they're out of stock :lol:

Return to “Automation, sensing and robotics”