Using the Raspberry Pi to Control an ATX Power Supply




I’m really enjoying my new 3d printer, but I just can’t leave my laptop connected to the printer all the time. I know that i could simply use SD cards or use another host computer, but there are better options. In order to untether myself from the printer I am using a Raspberry Pi and the OctoPrint printer host. This allows me to take g-code that I have generated and upload it to the Pi. Now I can start a print, check on the status, and view the printer through an attached webcam. The webpage also works well on the iPhone so I can keep track of what is going on from anywhere. I can also easily abort failed prints without having to come home to find a stringy mess. As great as that is I don’t like to leave the printer powered on if I’m not using it and I don’t like to leave the lights on when I’m not home.

Step 1: Circuit Layout

The solution that I came across was to leverage the different power modes of the ATX power supply (see Ugifer's Arduino treatment of the topic at Instructables). ATX power supplies have a standby mode that allows them to supply 5v at 2.0A while not fully on. This is the ‘standby power’ mode that most PCs use to sense the button press that turns them on. It provides more than enough power to run the Pi and still have the printer off. The printer runs off the 12V power rail when the power supply is in full power mode. The only issue to contend with is that the Pi’s GPIO pin that I want to use to turn on the power supply is 3.3V and the ATX supply needs to sink 5v to turn on. Using just a 2n3904 transistor and a couple of 1k ¼ watt resistors I am able to turn on the powersupply from the Pi.

Step 2: Physical Layout

The lights that I am using are some 12v white LED panels that came from Ebay. They are inexpensive, less than a dollar each, and are common in automotive world for interior car bulb replacements. They can be wired to any black and yellow connector on the ATX supply.

I didn’t want to have a separate board with the components on it or have to buy an ATX connector so I put the parts inline with the wiring and then sealed them in tape and heat shrink tubing.

To get a good connection to the ATX header I pulled some pins off a broken motherboard and put them on the ends of my wires. To hold them in place I just used nylon zip ties around the connector.

Step 3: Software: Wiring Pi and OctoPrint Configuration

To control the GPIO pins on the Pi I installed WiringPi. This library makes it easy to read and set GPIO pins. I chose pins 5 and 6 on the Pi so that I could have a GPIO right next to GND.

The Pi will default to Input mode on GPIO pins so the first step was to issue a command to set the pin mode to Output. (note that the WiringPi pin numbers are different from the physical pin locations on the Pi. The ‘gpio readall’ command will provide a chart of software to software pin mappings. Pin 5 on the board is really 9 in software) From the command line:

‘gpio mode 9 out’

To make this change permanent I added ‘/usr/local/bin/gpio mode 9 out’ to my ‘/etc/rc.local’ file before the ‘exit 0’. (rc.local requires the full path to gpio)

To test the setup:

‘gpio write 5 0’ (set the pin LOW)

‘gpio write 5 1’ (set the pin HIGH)

If the wiring is correct the ATX power supply fan will come on, the printer will turn on, and the lights turn on.

Octoprint config:

Adding the buttons to the OctoPrint system menu to turn the printer on and off is straight forward. The new commands ‘Printer On’ and ‘Printer Off’ are added to the ~/.octoprint/config.yaml in the ‘system:’ section as follows:



- action: shutdown

command: sudo shutdown -h now

confirm: You are about to shutdown the system.

name: Shutdown

- action: reboot

command: sudo shutdown -r now

confirm: You are about to reboot the system

name: Reboot

- action: restart

command: sudo service octoprint restart

confirm: You are about to restart OctoPrint

name: Restart OctoPrint

- action: Printer on

command: gpio write 9 1

name: Printer On

- action: Printer off

command: gpio write 9 0

name: Printer Off

Restart the Octoprint host software and the new buttons should show up

2 People Made This Project!


  • Colors of the Rainbow Contest

    Colors of the Rainbow Contest
  • Pets Challenge

    Pets Challenge
  • Classroom Science Contest

    Classroom Science Contest

12 Discussions


Question 8 months ago on Step 3

Can we get the making it permanent part and the adding it to octopi in slightly more lay man's terms. Do you do it through putty? On a PC? I'm a noob to linux


1 year ago

Tried this on a pi3 and it almost works.. I turn on the PSU and everything powers up.. as soon as I get to the step of gpio mode 9 out, it powers everything off then gpio write doesn't turn it back on. I tried the up/down/tri options with no effect. Also, I think you have a typo in the article it says gpio write 5 1 in one part then gpio write 9 1 in another part.

1 reply

Reply 1 year ago

Swapped out the 1K resistor to ATX for a lower one and it's working now.


4 years ago on Introduction

wow, exactly what i was looking for for nearly 2 weeks now!

I tried it out immediately, unfortunatley it does not work. I used a bc547c transistor instead of the 2n3904 you used.

When i set up gpio and write the output high, it switches on, stays on for 10 seconds and then powers off again. I know that ATX PSUs need a load connected, i have that, it workd fine before when i just shorted the power on.

Any idea what i am doing wrong?

4 replies

Reply 1 year ago

You might want to change the resistenta on the base to 330 ohm. U / I = R.
3.3 / 0.01. = 330


Reply 4 years ago on Introduction

i tried another gpio, which fixed the error temporarily.

somehow i think the values of the resistors might be off? could it be?


Reply 4 years ago on Introduction

I wouldn't be surprised at all if the 1k that connects to the ATX is too low. Some people have trouble with the ATX switching off if there isn't enough load. Try and increase the value and see what happens.


Reply 4 years ago on Introduction

Weird. I'm not sure about the characteristics of that transistor, but they look suitable. To troubleshoot it I would try to connect the base of the transistor directly to the 5v standby power on the ATX supply. If the power stays on then either 3.3v is not enough for the transistor or something is up with the Pi.

As a note the Pi has internal pull up/down resistors on each GPIO. They can be up, down, or tri(none). They can be set with 'gpio mode 9 up/down/tri' The settings don't have any effect on my setup, but they might have some impact with a different transistor.

Let me know what you find out and thanks for checking out my instructible.


2 years ago

For anyone struggling with the transistor circuit, or if you want to avoid some soldering, why not try an SSR (Solid State Relay) module designed to be used by Rasberry Pi or Arduino? The 2 relay modules are only a couple of dollars on Anazon or eBay. I haven't tried it yet myself, but it is on my list of things to do.

1 reply

Reply 1 year ago

Because gpio pins output 3.3v at 20ma. Only arduinos ouput 5v at 100ma.


4 years ago

I want a 3d printer do u recommend anything

1 reply

Reply 2 years ago

anet a8, i have that and the community around it is massive.

Best price/quality you can get.