OctoPrint TM 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 attic 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 TM 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 assume you already have your OctoPrint TM set up and running as I won’t be covering any of that here. If you don’t you can check my blog here. You’ll also need a relay module board. The ones used for Arduino will work just fine.
You’ll also need a power cord that will be cut but you can use the one your printer came with. Lastly, We’ll need 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 3.3V. Power the relay board with 5.0V and use 3.3V signal to trigger it. You should hear click and the COM and NO pins should be shorted. Once the relay is working you can move on.
Cutting the PowerCord
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.
NOTE: Make sure the power cord is unplugged from the wall!
Remove about 5cm / 2inch of insulation. I’ve used Stanley 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 C or COM) and the other to either the NO pin. NO stands for normally open. I’ve used NO which means the printer is only on when the relay is energized.
Connecting the Raspberry 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 Raspberry 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 Rapberry Pi and the relay module or an easier solution would be to simply use jumper wires, like I did. I would suggest using pins 3 (Signal | GPIO2), 4 (5V) and 6 (GND) as they are right next to each other yet they provide power and GPIO. If you need other pins you can used pins 17 (3.3V) ,18 (GPIO24) and 20 (GND). Pin 17 is 3V instead of 5V, depending on your relay you can use this one or Pin 2 or 4 If you need 5V.
|I2C ID EEPROM||ID_SD||27||●||●||28||ID_SC||I2C ID EEPROM|
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.
Note: 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.
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.
TESTING THE Octoprint – PSU Control HARDWARE