Raspberry Pi on/off toggle circuit design - Page 1
Forum section: electronics / projects

author: Racer_Rob
author_rank: Newbie
timestamp: March 12, 2017, 12:45:41 pm
content: Hello, I'm trying to design a circuit to turn a Raspberry Pi (RPi) on/off using a single toggle switch.For those unfamiliar with the RPi, it'll turn on immediately power is supplied but shutdown must be initiated in the software by the user and the shutdown procedure must complete before power is disconnected.The basic operating principle of my circuit is a follows:Toggle switch closed:The transistor activates and closes the 3V relay; the RPi powers up.The capacitor is charged.A RPi GPIO pin is held high. The voltage is set by the 20k/30k voltage dividerToggle switch opened:The GPIO pin immediately goes low. This triggers a script on the RPi to initiate shut downThe capacitor discharges, holding the transistor closed and the RPi powered long enough for shut down to be completed.This is the first circuit I've truly designed from scratch so I'm looking for feedback on a few points, as well as any general comments:Is the general operating principle sound?Are any additional components needs for protection? (e.g. I included a flyback diode)How do I select a model of transistor to use?Should I use a polarized (electrolytic) capacitor?Please keep in mind I'm an inexperienced (but very willing to learn hobbyist), so go easy!

author: retrolefty
author_rank: Super Contributor
timestamp: March 12, 2017, 12:59:44 pm
content: QuoteFor the we (the few I guess) that don't do Pi, What is the reason for this? What if a unplanned power outage happens anyway?Thanks

author: fcb
author_rank: Super Contributor
timestamp: March 12, 2017, 01:04:45 pm
content: I've recently developed a product for a customer that uses RPI3 (against my advice) - we have no controlled shutdown procedures or anything vaguely like that - haven't had any problems in the field so far.

author: Racer_Rob
author_rank: Newbie
timestamp: March 12, 2017, 02:04:34 pm
content: Quote from: retrolefty on March 12, 2017, 12:59:44 pmThe RPi has an SD card which provides the initial storage for the Operating System and files, it's recommended in the documentation (see item 4) that the board is shutdown before powering off or the card may be corrupted.https://www.raspberrypi.org/documentation/installation/sd-cards.mdI've seen the advice repeated on numerous websites. How important itreallyis to follow it I don't know but I wanted to challenge myself to devise a solution anyway.

author: tombi
author_rank: Regular Contributor
timestamp: March 14, 2017, 03:34:58 pm
content: I made something like this recently but rather than a fixed wait I got the Pi to notify the power control when shutdown is complete. Using the dt-overlay stuff you can choose a GPIO pin you want to go high when it shuts down and then you can use that to make your power control turn off the power.Other ideas - use a P channel MOSFET instead of a relay. Also I used a two colour LED to indicate standby/on modes.Tom

author: lwatts666
author_rank: Unknown
timestamp: March 14, 2017, 09:51:12 pm
content: Have a look at the URL Below. It seems to cover all the bases, but still requires software to complete the shutdown:http://www.mosaic-industries.com/embedded-systems/microcontroller-projects/raspberry-pi/on-off-power-controller

author: Racer_Rob
author_rank: Newbie
timestamp: March 18, 2017, 10:34:10 am
content: Thanks for the suggestions folks, it looks like I've got a few things to work through but I'll post an update when I get thereI like the idea of including an indicator LED. I'm not too familiar with MOSFETs and I imagine (other than perhaps cost and physical size) in this application there's no negative in sticking with the relay. I'll take a look at them anyway but I want to be able to walk before I run!

author: Racer_Rob
author_rank: Newbie
timestamp: March 26, 2017, 11:31:05 am
content: In the end I did include a P-channel MOSFET...When the toggle switch is in the lower position power is supplied directly to the Raspberry Pi through the switch.The UART TX pin of the Pi is high when the board is on and this, via the NPN transisitor, also allows power to be supplied through the P-channel MOSFET.(Luckily I don't require the UART for this project)When the toggle switch is switched to the off position, a GPIO pin on the Pi goes high, triggering the software to start shutting down.Power continues to be supplied to the board via the MOSFET until the UART TX pin goes low which happens when the board has finished shutting down.Power is then disconnected from the Pi.I've tried this on a breadboard with a dummy load instead of the Pi and it seems to work ok. Can anyone see any flaws, additional protection I could add, areas to improve, general comments?

author: LukeW
author_rank: Frequent Contributor
timestamp: March 27, 2017, 02:09:50 am
content: http://www.mosaic-industries.com/embedded-systems/microcontroller-projects/raspberry-pi/on-off-power-controllerYou'll find this interesting to read.http://www.uugear.com/product/wittypi2/This is an off the shelf product which does the sort of thing you're looking for - but I'm not sure if they provide schematics or anything like that.

author: tombi
author_rank: Regular Contributor
timestamp: March 27, 2017, 02:14:14 pm
content: I suggest putting it into LTSPICE. If you google a bit you can find models for the MOSFET.Then you can check all your numbers including power dissipation.Tom