It's my first project in electrical engineering and I am not very sure about what I'm doing.

I would like to drive a relay thanks to a Rpi and a RTC clock that has a alarm feature (ds3231 with high-z/active low) ... relay that will itself drive the raspberry pi. To sum up:

  1. The RTC send a signal that turn on the Relay and thus the RPI
  2. The RPi reset the RTC alarm to it previous state and configure it to
    trigger again in a determined time
  3. The Rpi do what it has to do
  4. The Rpi shut down and everything is back to normal I have to keep in mind to keep the current consumption as low as possible during the "sleep" phases

So far: I intended to use NPN transistor like on my scheme. in

  1. Both the Rpi and Ds3231 are High-z so the 5 V pull up and there is 5 V both in the base and emitter of the NPN => It doesn't let the current go. 2)The DS2132 become on open drain .. the NPN lets the current go
  2. the Rpi turn on and also become on open drain

enter image description here

My main preoccupation is: would this circuit work (and if not why?). I have of course to add a diode on the relay

Ps: A GPIO pin is in an high impedance state when no current is applied to Rpi, isn't it?

enter image description here


1 Answer 1


Assuming you want to turn the relay on if either an RTC brings an open drain output low or the Raspberry Pi provides a certain logic state, the below circuit would do this:


simulate this circuit – Schematic created using CircuitLab

The Rpi GPIO should be brought high to keep the relay in, and it should be push-pull, not open drain.

The Rpi outputs are not guaranteed 5V tolerant so they cannot be pulled up to 5V reliably. You need a catch diode across the relay, as shown. Further, it is unlikely that either the RTC or the Raspberry Pi will be very happy directly driving a relay- in your circuit about all the relay current goes through the Raspberry Pi or RTC.

  • \$\begingroup\$ Thanks a lot ! It all more clear in my head now. I just have an hard time to visualise what happen when the Rpi gpio is high and the Rtc is high impedance ? \$\endgroup\$
    – Simon Lang
    May 10, 2015 at 13:16
  • \$\begingroup\$ Then the relay is powered. The logic is that the relay is powered if the open-drain output is low or the GPIO is high. \$\endgroup\$ May 10, 2015 at 13:18
  • 1
    \$\begingroup\$ This diagram works like a charm ! Just tested it with a mosfet instead of the relay ( without the diode) and still seem fine for the moment. (Gate to the PNP, Source to ground and Drain to the device to control and 5v) \$\endgroup\$
    – Simon Lang
    May 13, 2015 at 21:45
  • \$\begingroup\$ Your solution would work as well, if the Rpi/R2 and the DS3231 can each sink enough current to drive the relay coil. Spehro's approach will work with a lower drive requirement. Also, D1 isn't addressed, but it's vital for preventing damage to your drive transistor from the field collapsing in the relay coil. \$\endgroup\$ Oct 12, 2023 at 15:47

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.