Introduction: Raspberry Pi Cheap DIY ATX-Power Switch.

Ok, so it doesn't look like much.... But why would you need one?
Well you don't, it is helpful if your pi is powered by a supply that also powers other things. A 3D Printer in my case.
Also included is a separate shutdown button which powers down the Pi.

After the Pi cleanly shuts down then power is removed from the Pi completely.

In a nutshell:

A relay controls power to the Pi, one of the Pi's GPIO pins powers a transistor which keeps the relay on until shutdown. Simple enough? Ok, read on for the circuit...

Step 1: The Circuit.

Here is the sketch of the circuit.

Parts you will need are:

  • Some Vero/Proto/Bread Board
  • Resistors (1/8Watt will do) 3k3,4k7 & 10K
  • Transistor 2N2222
  • Relay JRC-21F
  • Capacitor 1000uF
  • An LED
  • 2 Push button switches
  • Some Wire
  • Connectors (I used JST's)

Power to the Pi can be fed through either the GPIO 5V & Ground PINS or you can splice and re solder a micro USB cable.

Once you have assembled the circuit you will need to add some monitoring software to the Pi before wiring it up...That is the next step.

Step 2: The Software on the Pi.

Put these scripts below in the home folder of the Pi. Note the GPIO pins used ... Board PIN 16 is used as the shutdown PIN. Board PIN 18 is used as the Transistor power PIN.

On the pi from a shell script run the command:

sudo crontab -e

and add at the bottom of the file:

@reboot sh /home/pi/pishutdown.sh

Test it working... before you connect the circuit you made boot up the Pi with the software you just uploaded.Either run the python script manually or if you reboot it should run on startup (Note I tested this on a raspbian based OS).

  • With a volt meter (or an led with a suitable resistor) check that PIN 18 is producing 3.3V out.
  • Connecting PIN 16 to Ground should call the shutdown script and the Pi should shutdown.

Step 3: Powering ON.

Press and hold the button that closes the power circuit on the Pi, and the Pi should boot up. Depending on your setup and what you have installed it may take up to 10s to boot and power the GPIO pins. Once the Transistor pin is powered you can hear the relay "click" and the LED light up. Power button can be released.

Step 4: Shutting Down.

To shutdown the Pi, either use your own software to run the shutdown command, or press the shutdown button and that will initiate the shutdown command.

When the Pi powers down the GPIO the capacitor will start to discharge, with this setup allowing almost 8 Seconds till the capacitor discharges and then the relay is powered off.

Step 5: The Math...

The Relay used is a JRC-21F. According to its datasheet its coil needs 0.22W of Power @5V to operate. So around 44mA of current.

The 2N2222 Transistor has an HFE (gain) of around 56 at 5V and at 60mA current drain. (Figures taken from the datasheet and interpolated between tables)

The Pi is setup with a 3k3 Ohm resistor, with its output at 3.3V the current is 0.001A or 1mA.

1mA fed to the Transistor with a gain of 56 gives us 56mA of current therefore enough to power the coil requiring 44mA.

Capacitor Discharge - this is a little more complicated to put in text. Initial Current drawn is at 1mA, as voltage drops current draw increases. Using an online calculator, discharge time is at 7.9 Sec.

Step 6: Limitations.

With this setup you will not manage a reboot as it may cut the power half way through the boot sequence.

If you want to have this feature you can increase the Capacitor size to 2500uF or larger depending on the reboot time of your setup.

Comments

author
radoslav006 (author)2017-01-12

Very poor designed schematic, it need to be improved.

1.
It is bad idea to connect Pi GPIO directly to the capacitor, becouse it
acts like a short-circuit in transient conditions (a very long
transient with such a big capacity).

2. You should always use diode connected anti-paralell to the relay coil to protect the circuit from spikes.

3. S3 switch should be rated to handle more current that typical tact-switch.

author
illiac4 (author)2016-07-19

Hi. Can you please add a pohoto of upper and bottom side of the board so also non eletrician can build it by visual inspecting it. TNX in advance

author
ptabone (author)illiac42016-07-22

Here is the bottom, top is available in the images further up. I doubt that looking at this will help thou. Follow the schematic and it'll work :)

temp_-991336574.jpg
author
ptabone (author)2015-09-13

Thanks for the suggestion. I see what you made there, I'll test it out and see what results I get by varying R3.
D1, yes good idea too.

author
technovative (author)2015-09-12

Nice work. This is a good design. I have the following suggestions:

In my schematic, C1, LED1, and R2 form a bypass circuit. When the transistor switches on to energize the relay coil, a surge current flows through C1 as it charges, this is enough to actuate the switch. Once C1 is charged current stops flowing through it. Now the smaller current flowing through LED1 and R2 should be enough to hold the switch. This reduces the continuous power consumption of the circuit.

This allows for R3 to be added so that the switch off delay can be adjusted for a longer delay time.

A tact switch is shown for S3 in the article. Tact switches are typically only rated for 50mA. I suggest that S1 in my schematic be a momentary switch rated for at least 1Amp.

I added D1 across the relay coil to snub out the high voltage spike that occurs when the coil is de-energized.

Variant.jpg

About This Instructable

14,800views

181favorites

License:

More by ptabone:Raspberry Pi Cheap DIY ATX-Power Switch.Proximity IR SwitchPower to your Living room via Raspberry Pi
Add instructable to: