Maker Pro
Maker Pro

Controlling a UK mains supply from a Raspberry Pi Piface

Tom Arnautovic

Mar 25, 2015
7
Joined
Mar 25, 2015
Messages
7
I have a current setup whereby I use a R-Pi with a Piface Digital to control a magnetic door lock. I want to use this same 5v signal from the PiFace to switch on and off a UK mains supply (230V 5-13amp). The 5v signal will not be continuous but the mains power state should remain until another signal is received to switch it off. I believe the correct approach would be to use a bistable flip-flop relay or latching relay (are they the same thing?). I have not been able to find a suitable relay despite a lot of searching so am asking you if you can help point in in the right direction? Many thanks.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Hello
How do you want to turn the relay off?
Thanks
Adam
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
The relay you select to switch the mains will depend on what kind of load it switches: resistive, inductive, incandescent lamps, switching power supply (e.g. computer), etc. The type of load affects the type of contacts used. The relay manufacturer's datasheet should specify the type of load the relay contacts are designed to switch.

For heavy loads, toward the 13 A end of your range, a contactor may be more appropriate. A contactor is a form of relay but usually with special arc-breaking contacts essential for inductive motor loads. Contactor current ratings start at around 10 A and go up from there. You might have difficulty finding a contactor with 5 VDC coil, but you can energize a contactor coil from another relay that does have a 5 VDC coil.

There are mechanically latched relays, really two relays with an interlocking mechanism such that if you alternately pulse the two coils the relays change states: one "pulls in" and the other "drops out". Mostly just a curiosity now with microprocessors controlling everything, and they may be difficult to find and purchase.

A bistable flip-flop can be wired to change states each time it receives a "clock" pulse, but you need to be careful that the pulses are "clean," without any bounce.

A latching relay is typically constructed from a multi-pole relay, for example DPDT, by wiring power for the coil to a normally-open set of contacts and connecting the other contact of the normally-open pair to the coil. When the coil is energized (from a separate path), the normally-open contacts close and apply power to the coil so it remains energized. To make the relay de-energize you must interrupt power to the coil. This can be in the form of a normally-closed switch or a normally-closed contact on another relay that supplies power to both the coil and the latching contacts of the first relay. Briefly energizing this second relay (or actuating the switch) will interrupt current to the coil of the first relay, causing its normally-open contacts to open, and the relay thereafter remains de-energized until its coil is pulsed on again. Clearly all this requires two relays and two sources of pulses. It is possible to design a relay circuit that operates from a single pulsed source, but the circuit is not as simple as either a flip-flop or using two pulse sources.

How much electronics experience do you have? Are you comfortable working with CMOS digital integrated circuits on a prototyping board?
 

Tom Arnautovic

Mar 25, 2015
7
Joined
Mar 25, 2015
Messages
7
Hello
How do you want to turn the relay off?
Thanks
Adam
Hi Adam,

I would want the pulse from the PiFace digital to both turn the relay on and off. Basically a user presents a smart card reader attached to a Raspberry Pi, this checks on a remote database if they're a valid user, if they are it turns the lights and a plug socket on at a work pod/desk. Thanks for you your help.

Tom
 

Tom Arnautovic

Mar 25, 2015
7
Joined
Mar 25, 2015
Messages
7
The relay you select to switch the mains will depend on what kind of load it switches: resistive, inductive, incandescent lamps, switching power supply (e.g. computer), etc. The type of load affects the type of contacts used. The relay manufacturer's datasheet should specify the type of load the relay contacts are designed to switch.

For heavy loads, toward the 13 A end of your range, a contactor may be more appropriate. A contactor is a form of relay but usually with special arc-breaking contacts essential for inductive motor loads. Contactor current ratings start at around 10 A and go up from there. You might have difficulty finding a contactor with 5 VDC coil, but you can energize a contactor coil from another relay that does have a 5 VDC coil.

There are mechanically latched relays, really two relays with an interlocking mechanism such that if you alternately pulse the two coils the relays change states: one "pulls in" and the other "drops out". Mostly just a curiosity now with microprocessors controlling everything, and they may be difficult to find and purchase.

A bistable flip-flop can be wired to change states each time it receives a "clock" pulse, but you need to be careful that the pulses are "clean," without any bounce.

A latching relay is typically constructed from a multi-pole relay, for example DPDT, by wiring power for the coil to a normally-open set of contacts and connecting the other contact of the normally-open pair to the coil. When the coil is energized (from a separate path), the normally-open contacts close and apply power to the coil so it remains energized. To make the relay de-energize you must interrupt power to the coil. This can be in the form of a normally-closed switch or a normally-closed contact on another relay that supplies power to both the coil and the latching contacts of the first relay. Briefly energizing this second relay (or actuating the switch) will interrupt current to the coil of the first relay, causing its normally-open contacts to open, and the relay thereafter remains de-energized until its coil is pulsed on again. Clearly all this requires two relays and two sources of pulses. It is possible to design a relay circuit that operates from a single pulsed source, but the circuit is not as simple as either a flip-flop or using two pulse sources.

How much electronics experience do you have? Are you comfortable working with CMOS digital integrated circuits on a prototyping board?

Wow thanks for all that information. The situation is I already have a Raspberry Pi with PiFace digital which has a 5v relay which should be used with loads of greater than 20v. This is currently used to open a magnetic door lock when a user presents a valid NFC card to the attached reader. I now want to use this same setup (so no more programming) so that when a valid card is presented to the reader, it turns on a light and plug socket at a pod / desk. When the user presents the card again, it logs them out and cuts the power. Perhaps 13amp is then not required as the socket only needs to power perhaps a monitor and a laptop and also the LED light.

I don't have a great deal of electronics experience but do am happy to do a bit of soldering if required (I have a background in computer programming and network support). Do you think a prototyping board is the way forward? - Ideally a ready made relay would be ideal but I can't find one that seems to fulfil these requirements.

Very grateful for your time and help.

Thanks. Tom
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Hi Adam,

I would want the pulse from the PiFace digital to both turn the relay on and off. Basically a user presents a smart card reader attached to a Raspberry Pi, this checks on a remote database if they're a valid user, if they are it turns the lights and a plug socket on at a work pod/desk. Thanks for you your help.

Tom

Ok dumb questions, why can't you latch the relay on and then off just using the pin from the PI. Why pulse it?
Cheers
Adam
 

Tom Arnautovic

Mar 25, 2015
7
Joined
Mar 25, 2015
Messages
7
Ok dumb questions, why can't you latch the relay on and then off just using the pin from the PI. Why pulse it?
Cheers
Adam

No good questions - basically the software for these Pi have already been setup using the Piface to momentarily open a magentic door look - ideally we can use exactly the same setup/software for the power supply without having to change anything - make sense...?
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
I don't see how this works. If you toggle the lights each time the lock is opened, wouldn't the lights go out when a second person enters the room?

Bob
 

Tom Arnautovic

Mar 25, 2015
7
Joined
Mar 25, 2015
Messages
7
I don't see how this works. If you toggle the lights each time the lock is opened, wouldn't the lights go out when a second person enters the room?

Bob
I didn't explain myself too well. I will be using a Pi similar to the one I use for the door to operate a working pod. The door and the pod are entirely separate with both having their own Pi operating them.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Okay. But it seems to me that a trivial software change could save you having to make extra specialized hardware. Are you unable to make changes to the program?

Bob
 

Tom Arnautovic

Mar 25, 2015
7
Joined
Mar 25, 2015
Messages
7
Okay. But it seems to me that a trivial software change could save you having to make extra specialized hardware. Are you unable to make changes to the program?

Bob
Hi Bob, is the extra complication caused by using a pulsed signal? Would it be more simple if there was a continuous control signal either +5v or -5v - I guess that would negate the need for a bistable relay. Have to say this all seems rather complicated to me!!!
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Yes, if the Pi could provide a continuous 5V signal for the entire time the lights should be on, then all you need is a relay to control the lights.

Bob
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
Hi Bob, is the extra complication caused by using a pulsed signal? Would it be more simple if there was a continuous control signal either +5v or -5v - I guess that would negate the need for a bistable relay. Have to say this all seems rather complicated to me!!!
Yes, pulsed ON followed by pulsed OFF is an extra complication. The whole idea behind moving hardware functions to software functions is the ability to make minor changes in software, which should be less expensive than creating new hardware solutions. Not saying it can't be done, but why go to the trouble if a few lines of code will make it happen?

I can understand the need to pulse a solenoid door latch to release the lock mechanism... most of these solenoids are rated for intermittent duty, so can't be energized continuously. It sounds like you want to use an existing NFC system to enable a workstation without re-programming the system. Maybe your lock system is proprietary and you can't easily program it.

Whatever, let's see what we can come up with as a hardware solution, something like those touch-on, touch-off lamps that appear to be popular (I have several!). The LAST thing you need is a circuit that is susceptible to spurious operation that shuts down the workstation (removes power) unexpectedly, even if the user can turn it on again with a simple pass swipe. So, allow some of the wizards here to think about this and propose a robust but inexpensive and simple solution.

I will also see what I can devise in my spare time. I am thinking along the lines of a CMOS flip-flop with a level-triggered (rather than edge triggered) clock input that changes states each time it receives a +5 V pulse. The flip-flop output drives a small on-board relay whose contacts switch the mains power to a receptacle. The input pulses would be optically isolated from the "real world" to avoid spurious triggering.

Ideally, you would build a small circuit board into a small metal box with a power cord, a receptacle, and appropriate fusing... maybe adapt an ordinary outlet strip to this purpose. Tuck the whole thing behind the desk and connect a pair of wires to your NFC reader to get pulses. The most expensive part of this project would be the power supply for the CMOS flip-flop and relay, but a 5 VDC, 100 mA, wall-wart would be more than adequate for power. Total cost in parts would probably not exceed £10.00. Someone living in the UK would be better able to estimate costs and find a source for parts than I can.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
No good questions - basically the software for these Pi have already been setup using the Piface to momentarily open a magentic door look - ideally we can use exactly the same setup/software for the power supply without having to change anything - make sense...?

Yes ok.
Adam
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Yes, pulsed ON followed by pulsed OFF is an extra complication. The whole idea behind moving hardware functions to software functions is the ability to make minor changes in software, which should be less expensive than creating new hardware solutions. Not saying it can't be done, but why go to the trouble if a few lines of code will make it happen?

I can understand the need to pulse a solenoid door latch to release the lock mechanism... most of these solenoids are rated for intermittent duty, so can't be energized continuously. It sounds like you want to use an existing NFC system to enable a workstation without re-programming the system. Maybe your lock system is proprietary and you can't easily program it.

Whatever, let's see what we can come up with as a hardware solution, something like those touch-on, touch-off lamps that appear to be popular (I have several!). The LAST thing you need is a circuit that is susceptible to spurious operation that shuts down the workstation (removes power) unexpectedly, even if the user can turn it on again with a simple pass swipe. So, allow some of the wizards here to think about this and propose a robust but inexpensive and simple solution.

I will also see what I can devise in my spare time. I am thinking along the lines of a CMOS flip-flop with a level-triggered (rather than edge triggered) clock input that changes states each time it receives a +5 V pulse. The flip-flop output drives a small on-board relay whose contacts switch the mains power to a receptacle. The input pulses would be optically isolated from the "real world" to avoid spurious triggering.

Ideally, you would build a small circuit board into a small metal box with a power cord, a receptacle, and appropriate fusing... maybe adapt an ordinary outlet strip to this purpose. Tuck the whole thing behind the desk and connect a pair of wires to your NFC reader to get pulses. The most expensive part of this project would be the power supply for the CMOS flip-flop and relay, but a 5 VDC, 100 mA, wall-wart would be more than adequate for power. Total cost in parts would probably not exceed £10.00. Someone living in the UK would be better able to estimate costs and find a source for parts than I can.

Yes Hop good idea I was thinking flippy flop, logic gate latch or resettable BJT SCR latch , simple and reliable.
Adam
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
I think I would add a de-bounced push button switch, wire-or'ed with the optical isolator, to allow manual toggling of the flip-flop without using the NFC device. This just for test purposes, perhaps mounted on the circuit board, concealed by the metal case, and operated by a straightened-out paper clip inserted through a small (concealed?) hole in the case. Of course a semi-public workstation in which the mains switching does not occur within the receptacle box (inconvenient to install) is subject to being bypassed by just removing the plug from the NFC switched outlet (the one we are designing here) and plugging directly into a non-switched wall outlet. How would you propose to handle that situation, @Tom Arnautovic ?
 

shumifan50

Jan 16, 2014
579
Joined
Jan 16, 2014
Messages
579
It sounds like this device is going to be used in public office space in the UK. If this is the case you will need certification (at least CE) otherwise you could be liable for serious law suits if anybody gets injured while using the box. This would also apply for the door switch, but injury is much less likely in the case of the door switch.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
It sounds like this device is going to be used in public office space in the UK. If this is the case you will need certification (at least CE) otherwise you could be liable for serious law suits if anybody gets injured while using the box. This would also apply for the door switch, but injury is much less likely in the case of the door switch.

Yes you will if your selling it. The low voltage directive will need to be considered.
Adam
 

Tom Arnautovic

Mar 25, 2015
7
Joined
Mar 25, 2015
Messages
7
Thanks for all your advice and suggestions. We have taken this on board and have decided that we going for a totally different approach using a wireless controlled power socket - so no messing with mains electricity or relays - you may have just averted a serious accident.
 
Top