I am currently working on a script that will inject the temperature changes in your gcode. Check back after a while.
One part of 3D printer's calibration is finding the optimal printing temperature. This temperature can differ based on the hotend design, filament manufacturer, material type or even ambient temperature.
The easiest way to quickly test a range of temperatures is by printing a temperature tower. Unfortunately, setting the temperature changes isn't obvious or even impossible with some slicers.
We'll be using this temperature tower by Jan Petersen from Thingiverse. I recommend it because the sections are evenly spaced and it includes a stringing test. Besides retraction settings, stringing is dependent on printing temperature so you might as well test it at the same time.
For PLA, I recommend testing temperatures in the range from 190°C to 215°C. Try 210°C to 240°C for PETG and 220°C to 250°C for ABS.

When your tower is finished, examine the overhangs, bridging and stringing. The ideal temperature is the lowest where the layers are still bonded together strongly (try breaking it apart) and where you can notice the least amount of artefacts. Also, the lower the printing temperature the better bridging you can achieve.
In some cases, the entire tower might look nearly identical. This is usually a sign of a good quality filament. I recommend selecting the temperature in the middle of the range to begin with.
Let's see how you can set the temperature changes using different slicers.
Simplify3D
Simplify3D has a built-in tool for setting different properties at different heights. This is great for changing infill percentage, but it can also make changing the temperature very easy.
You will find it under the Tools menu and then Variable Setting Wizard.

For our case, you should split the model beginning at 12mm and then at every further 10mm (i.e. 22, 32, 42 and so on).
Once done, Simplify3D will create a new process for every height that you've entered. The first process is attached to the bottom section of the tower.
Double click on each process, go to the Temperature tab and then select the Extruder temperature. You should set a single temperature at Layer 1.

Repeat this for each process while changing the individual temperatures. When you're ready to slice it, be sure to select all of the processes before continuing.

Save the gcode and your tower is ready to be printed.
Cura
Cura doesn't have a built-in support for changing the temperatures, but there is a plug-in available that will help you do that. Best of all, it's already included with Cura.
Go to the Extensions menu and then select Post processing -> Modify G-Code:
Begin by adding a new script. The one we are looking for is called ChangeAtZ. Then simply enter the height of the change and select the Change Extruder 1 Temp. Enter your desired temperature in °C. Add a new script for every temperature change and repeat the above.
Slic3r
Unfortunately, Slic3r does not currently support changing temperatures in any way. You will have to manually change the gcode as explained in the next section.
Set changes manually
If your slicer doesn't support the temperature changes or if you prefer to do it yourself, then you can edit the gcode file and set the changes manually.
Gcode files are written in plain text, so you can open them in any text editor.
To set the temperature changes, you have to search for a certain height and insert the appropriate command there. Specifically, you should search for the G1 Z12.0
command, as we want the first temperature change to occur at the height of 12mm. Unfortunately, this is where things get complicated.
Different slicers have slightly different ways of creating the gcode file. For example, Simplify3D and Slic3r will insert only the individual command to change the height, which is easy to find. Cura, on the other hand, will combine the height change with XY movement as well and the gcode would look like this (they're also using G0
instead of G1
, but the end result is similar):
G0 X113.263 Y93.263 Z12.15
To further complicate things, if you have Lift-Z / Z-hop enabled, you might see a lot of commands that use the same height, but you need to find the one that actually changes the current layer.
Luckily, slicers also include human readable comments in the gcode, which helps greatly. All comments begin with the ; symbol at the beginning of the line.
In Simplify3D, the comment for layer height change looks like this and you should be able to find the actual G1
command right after it:
; layer 80, Z = 12.051
; feature inner perimeter
G1 Z12.051 F720
With Slic3r, it should look like this:
;AFTER_LAYER_CHANGE
;12.05
; PURGING FINISHED
G1 Z12.050
Cura only comments on the layer's number, but the G0
command should be right after that:
;LAYER:60
;MESH:Temperature_Tower.stl
G0 X113.263 Y93.263 Z12.15
You might notice the F command at the end of some G commands; that is simply the movement speed.
Once you've successfully found the correct position in the gcode, insert the temperature change command into a new line just after the height change. The command to change the temperature is:
M104 S215 T0
where S is the temperature in °C and T0 signifies the first extruder.

In a similar fashion, find all the other locations where you wish to change the temperature (G1 Z22.0
, G1 Z32.0
, etc.) and insert the M104
command afterwards.
With that done, save the gcode file and you're ready to print the modified temperature tower.