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ā€¦Raspberry Pi Cheap DIY ATX-Power Switch.

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.Raspberry Pi Cheap DIY ATX-Power Switch. schematic

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.

 

For more detail: Raspberry Pi Cheap DIY ATX-Power Switch.


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top