I am trying to design a circuit to control mains equipment using a microcomputer, probably a Raspberry Pi.

The requirement is:

  1. The main switch is open (up in the diagram) and (ideally) no current flows.
  2. When the main switch is closed (down in the diagram), the Pi boots up. The relay R1 must stay open so the load is isolated.
  3. Later, the relay R1 is closed by the Pi, under software control, so that the load is energised. The load stays on, even if the Pi shuts down.
  4. When the main switch is opened, the load goes off and the relay R1 is opened, ready for the next iteration.

Is there such a relay type, that would be normally open with no input power, and and then latch closed?

Alternatively, I am thinking of another relay at C1, to open R1 at step 4. Is this a sensible idea?

Please advise on the type of devices for R1 and C1 if appropriate.

I am confident of cabling the mains switch, load and relay. Please note that this not about the Raspberry Pi. There is plenty of information available about using the Pi with relays and relay modules. Conceptual design

  • \$\begingroup\$ yes; most relays in fact. And it's not clear what C1's job is. R1 will switch back to its original configuration upon loss of power. \$\endgroup\$ Commented Jun 1, 2019 at 16:00
  • \$\begingroup\$ If you only want it to latch while the main switch is on, then a latching relay by itself isn't going to do what you want. You want something like a ON/OFF self latching circuit that is often used to power a motor ON/OFF with 2 momentary buttons. It's been 30 years since I have seen the circuit, I will have to look it up. edit - like Transistors answer! \$\endgroup\$
    – Mattman944
    Commented Jun 1, 2019 at 16:53

3 Answers 3



simulate this circuit – Schematic created using CircuitLab

Figure 1. Pi-controlled latching relay.

How it works:

  • When SW1 is first closed RLY1 and RLY2 are off and both contacts are open.
  • When the Pi energises RLY1 (using one of those 3.3 V or 5 V relay modules rather than directly from the GPIO pin) it energises RLY2 and switches on the load.
  • Note that the left contact of RLY2 now feeds its own coil and maintains supply even if RLY1 switches off.
  • When SW1 is switched off everything resets.

You're looking for a 2-pole normally-open relay with mains voltage coil. (The normally closed contacts on RLY2 aren't used in this application so they're not required.)

  • \$\begingroup\$ In some industries, this is a well-known circuit. This website describes the circuit as an electrically latching relay, see the first figure. The "set" switch is replaced by a relay for your application. The latching circuit power can be anything convenient. You don't need the "reset" function, but since that is a NC relay contact, the path is necessary. The bottom relay contact powers your load. azatrax.com/latching-relay-circuits.html (not intending to take anything away from the answer, just reinforcing that this is a good answer) \$\endgroup\$
    – Mattman944
    Commented Jun 1, 2019 at 20:48
  • \$\begingroup\$ of course it's nor a direct onnection between the raspberry pi and the relay, a transistor is needed to boost the strenght of the signal. \$\endgroup\$ Commented Jun 1, 2019 at 23:28
  • \$\begingroup\$ I thought I had covered that in the second bullet point? \$\endgroup\$
    – Transistor
    Commented Jun 2, 2019 at 7:57
  • \$\begingroup\$ Thanks for a detailed explanation. \$\endgroup\$
    – Peter bill
    Commented Jun 5, 2019 at 8:47

There are latching relays that are turned on by a momentary application of power to one terminal and turned off by a momentary application of power to another terminal. If the application of power to either terminal is continuous, you could design a relay circuit that would disconnect the power automatically. There may be latching relays with that built in. You need to search to see what is available. You should be able to find products that are described in sufficient detail to allow the customer to understand the function. If a product is not well described, look elsewhere.


Is there such a relay type, that would be normally open with no input power, and and then latch closed?

I can't speak for your diagram, but I do know about relays. Relays use a coil and spring to stay on or off, when the coil is powered they switch positions. There are normally open relays and normally closed relays, the trick is to figure out how to wire the relay to function with or without power.

If you want the relay to open with no input power, then buy a normally closed relay. This means that it will be closed with no power. Once the coil is powered it will remain open.

Another thing to consider is latching relays which use a different mechanism to latch. They switch state if a pulse is applied, but you need power to change state.

There are some hobbyist relay boards available to make it easier to control from a raspberry pi. Or some available on ebay. Be careful when working with AC mains know and follow safety guidelines.

There are also some relays that are completely enclosed but I couldn't find any for 220V.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.