Controlling a 3D Printer's Power Supply with OctoPrint

5 min read

Controlling a 3D Printer's Power Supply with OctoPrint

This will probably be the first in a series of posts about my journeys tinkering with my stock Creality Ender 3 printer. One of the first things I wanted to do after buying the Ender 3 back in August 2020 was the ability to power on/off the printer via the OctoPrint interface. Luckily there is a robust PSU Control plugin that already exists. I just needed to figure out the hardware. I was also able to find this Raspberry Pi enclosure for the Ender 3 on Thingiverse which I’ve remixed to add a hole for a female barrel connector.

There are various other tutorials about similar setups but none that match exactly what I was looking to do. Hopefully this can help others looking to do the same. Having said that this is by no means the right or best way to do this. It is just the way that worked best for me after a few iterations.


  • Keep the Raspberry Pi always powered on
  • Turn the printer on/off via OctoPrint interface via PSU Control plugin
  • Ability to easily physically disconnect and remove the RPi when needed
  • Compact footprint and cable management


  • Creality Ender 3 (but could work with any printer running OctoPrint)
  • Raspberry Pi running OctoPrint
  • IoT Power Relay (Amazon, Adafruit)
  • 1ft Power Cord (Amazon)
  • Printed Pi Enclosure (Thingiverse)
Top view of printed enclosure, a Raspberry Pi 4, and the IoT Power Relay


  • A. Dupont 2-pin female connector
  • B. 18-22 AWG wire (Amazon)
  • C. Heat shrink (Amazon)
  • D. Female barrel connector (Amazon)
  • E. Male barrel connector (Amazon)
  • F. Wire ferrules (optional) (Amazon)
  • G. Relay screw terminal (Included with IoT Power Relay)
  • Double sided tape (Amazon)
Top view of all the listed parts



Mains power is provided to the IoT Power Relay. The “Always On” outlet provides constant power to the Raspberry Pi. By plugging the power cord from the printer’s power supply into the “Normally Off” outlet power will not be provided until the Raspberry Pi sends a 3.3v signal to the IoT Power Relay via the wiring we set up.

A diagram showing the wiring connections between the Raspberry Pi 4 and IoT Power Relay


1. Create wire connections

For the connection between the RPi and the printed enclosure we need a short length of relatively short wire (about 50cm)[^b]. Ground should be soldered to the larger terminal on the female barrel connector [^d] and power to the smaller terminal. Wrap them in heat shrink[^c]. On the other end of the wire crimp and connect the 2-pin Dupont connector[^a].

For the connection between the printed enclosure and the PSU controller we again need to solder the ground wire to the larger terminal and power to the smaller terminal of the male barrel connector[^e]. Again covering both in heat shrink[^c]. The other end can be either crimped with ferrules[^f] or plugged right into the PSU connector[^g].

Wiring between Raspberry Pi 4 dupont connector and female barrel connector
Wiring between female barrel connector and IoT Relay screw terminal

2. Add barrel connector to print enclosure

Feed the dupont end of the wire through the hole in the print enclosure until the ring of the female barrel connector sits flush with the printed enclosure. Slide the washer and locking nut over the wire and hand tighten until the barrel connector feels snug.

Fit the Pi into the case and plug the dupont connector into the GPIO header. Physical pin 37 for red and physical pin 39 for black.

Back of the printed enclosure with the female barrel connector installed
Top view of the Raspberry Pi 4 in the printed enclosure and the female barrel connector installed

3. Install Power Relay

I just used some double stick tape to adhere the Power Relay to my Ender 3’s power supply. This allowed me to have the shortest possible lengths for both the wire from the Raspberry Pi to the power relay and the cord from the power relay to the power supply.

The Pi enclosure slides into the aluminum extrusion of the Ender 3 and then wire connections can be made.

Side view of the Ender 3 with IoT Power Relay stuck to the side of the Ender 3's PSU

4. Configure OctoPrint PSU Plugin

Install the following two plugins to your OctoPrint instance.

Settings > (Plugins) PSU Control

  • Set Switching Method to GPIO
  • Set On/Off GPIO Pin to 26
  • Check Enable switching with G-Code commands.
  • Set On G-Code Command to M80
  • Set Off G-Code Command to M81
  • Set Sensing Method to Plugin
  • Set Sensing Plugin to PSU Control - RPI.GPIO
  • Set Polling Interval to 1
Screenshot of the PSU Control plguin for OctoPrint

Settings > (Plugins) PSU Control - RPI.GPIO

  • Set GPIO MODE to BCM
  • Set Switching > Pin to 26
  • Set Sensing > Pin to 26 Float
Screenshot of the PSU Control - RPI.GPIO plguin for OctoPrint

Save your settings and refresh OctoPrint. You should now have a lightning bolt icon in the top nav bar that you can use to turn on and off your printer.

Screen shot of OctoPrint's top navigation bar with the PSU plugin's lightning bolt icon green signifying power on

You should be all set now. Again, this might not be the right or best way to do it. However it is what works for me. If you have any comments or questions feel free to reach out to me via email johnzanussi [at]

Disclosure: Some of the links above are affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you click through the link and finalize a purchase.

Found the above useful? Have a question? Thought of something I didn't?

Consider leaving a comment below or send me an email at

You can also buy me a coffee. Cheers!

Buy Me A Coffee