Introduction: Turn Your 3D Printer On/off Using Octoprint

About: Passionate maker

Octoprint is a great solution for controlling your 3D printer. However, it's missing one key function. You can't turn the 3D printer on and off. I often have to run to my basement just to turn the 3D printer on then I give it few minutes to heat up before it can start printing. Well, today I'll show you how you can turn your 3D printer on and off using Octoprint and a relay.

There are multiple ways of doing this. Both for the software and hardware but I'll be showing a very simple solution that is compatible with almost any 3D printer. I've also made a video tutorial which I'd highly suggest watching as well.

Step 1: Components

I assume you already have your Octoprint set up and running as I won't be covering any of that here. If you don't you can check the official guide here. You'll also need a relay module board. The ones used for Arduino will work just fine. Something like this. I'll be building my own module but that's just because I'm still waiting for the ones I ordered to arrive. If you want to build one yourself too I'd suggest checking out this instructable.

You'll also need a power cord that will be cut but you can use the one your printer came with. Lastly, We'll make a cable connecting the raspberry pi and the relay module.

Before building anything I'd suggest making checking if the relay module will work with 3V3. Power the relay board with 5V and use 3V3 signal to trigger it. You should hear click and the COM and NO pins should be shorted. If nothing happens you need to make a slight modification. It's just a matter of add single resistor. I'd suggest checking this instructable which talks about it in step 6. Once the relay is working you can move on.

Step 2: Cutting the Power

In order to turn the printer on or off we'll be using a relay to control the mains voltage. Since you'll be working with the mains voltage you need to be really careful. I'm not responsible for any injury or damage you may cause.

First, we need the power cord for the 3D printer. It should be the one shown in the picture. It might look slightly different but that's fine. If you have power brick instead they usually have power cord like this as well. Or you can simply follow the instructions and replace the power cord with your DC power cable which is even better.

Make sure the power cord is unplugged from the wall and remove about 5cm / 2inch of insulation about 20cm / 8inch from the end that plugs into the printer. I've used x acto knife to remove the insulation. All of my cuts were very shallow to assure I wouldn't damage any of the wires inside. Simple make a shallow cut and then rip the insulation. After removing the insulation you'll see 3 wires inside. Make sure their insulation is ok if not you'll need to get a new power cord. Cut the brown(black if it's US plug) wire right in the middle and strip both ends.

These two ends need to be screwed in a terminal on the relay board. One must be connected to the common pin(labeled COM) and the other to either the NC or NO pin. NC stands for normally closed and NO for normally open. I've used NC which means the printer is only on when the relay is energized.

Step 3: Connecting Pi

With the power cord hooked up, it's time to connect the raspberry pi. The relay module has 3 pins: 5V, GND, and signal. Intuitively the 5V and GND will be connected to the corresponding pins on the pi while the signal can be connected to any GPIO pin. We'll define the pin in the software later.

You can make your own cable to connect the pi and the relay module like did. An easier solution would be to simply use jumper wires. I would suggest using pins 3,4 and 6 as they are right next to each other yet they provide power and GPIO. I've personally used pins 17,18 and 20 since my relay needs just 3V instead of 5V.

Step 4: Software

Fortunately installing the software is really easy as we'll be using a pre-existing plugin. Open the Octoprint in your browser and log in. Next, click the settings icon and choose the plugin manager on the left-hand side. You'll see a list of plugins but you need to select the get more button on the bottom. Then simply search for PSU. At this point, you should see PSU control plugin submitted by Shawn Bruce. Go ahead and install it. It will take few minutes and afterward you'll be prompted to restart your Octoprint.

After the reboot, the plugin is installed and you'll see lightning bolt icon on the top bar. We are not done yet, few things need to be set up. Go to settings and on the left-hand side select the new PSU control option. Choose switching method to GPIO pin and GPIO mode to BOARD. If you used the pins 3,4 and 6 on your pi as I suggested then for the On/Off GPIO Pin enter 3. If you used any other pins then here you'll select which pin is being used as the signal for the relay. Do NOT enter the number after the GPIO but the number of the pin. For example, if you're using GPIO21 you'll enter 40 because GPIO21 is on pin 40.

The remaining setting can be left at default.

Step 5: Enclosure

We're almost done. Now would be a good time to see if you can control the relay. Leave the power cord unplugged and simply have the relay module connected to the pi. From the web interface turn the power on and off couple of times and you should hear the relay click each time. If not check the wiring and make sure the relay module is working. you can also check if the GPIO pin voltage is changing.

Last but not least is to add cover for the relay module. Don't even think about plugging the power cord in without any sort of cover. There is exposed mains voltage on the board. I have designed this simple enclosure that will house relay module and neatly route the cord. The STL files are available here and also on Thingiverse. If you're building this I'm sure you have a 3D printer so it shouldn't be a problem. Make sure to add zip ties on the cable as I did in the picture. These will act as a strain relief.

Now you can cross you fingers plug the power cord in and hope nothing blows up. If you did everything right you'll be able to turn your 3D on and off with Octoprint. Another first world problem solved. You're welcome :D If you find this useful please check out my youtube channel where I build cool stuff.