How to Program a 3D Printer With Marlin and Arduino

Introduction: How to Program a 3D Printer With Marlin and Arduino

Marlin is an Arduino project meant to be configured so it can run almost any 3D printer with the exception the 3D printer must have an Arduino on board it. You may download it here.

In order to configure it to your 3D printer you must adjust variables and comment or uncomment code in the Configuration.h file. This tutorial will explain all about that.

Step 1: Configuration.h and Arduino

So your next step is to open Marlin.ino located in the zip file I showed you in the previous step. It should be under Marlin-1.1x/Marlin/Marlin.ino. Then Marlin.ino and a whole bunch of classes should open.

Select on Configuration.h to view that file. We will be using that file throughout all of the next steps in the tutorial.

Step 2: #define BAUDRATE #

Depending on your computer and your motherboard the Baudrate will vary. If you don't know what this should be leave it alone. You can always change it in the future. You will find this in configuration.h on line 114. Baudrate can only equal either 2400, 9600, 19200, 38400, 57600, 115200, 250000, 500000, or 1000000. It can only equal one number.

Step 3: #define MOTHERBOARD "(Your Motherboard From Boards.h)"

Replace the default definition of #define MOTHERBOARD with your motherboard. It's default value is BOARD_RAMPS_14_EFB but it can be anything from boards.h in Arduino. Change it to the value of your motherboard from Boards.h. This line of code is on line 122. EFB stands for the setup up you can have with Ramps 1.4 motherboard that has one extruder, one fan, and one heated bed like most Prusa i3 variants. Here are the values you could change it to.


BOARD_RAMPS_13_EFB // RAMPS 1.3 (Power outputs: Hotend, Fan, Bed) #define BOARD_RAMPS_13_EEB // RAMPS 1.3 (Power outputs: Hotend0, Hotend1, Bed) #define BOARD_RAMPS_13_EFF // RAMPS 1.3 (Power outputs: Hotend, Fan0, Fan1) #define BOARD_RAMPS_13_EEF // RAMPS 1.3 (Power outputs: Hotend0, Hotend1, Fan) #define BOARD_RAMPS_13_SF // RAMPS 1.3 (Power outputs: Spindle, Controller Fan)

#define BOARD_RAMPS_14_EFB // RAMPS 1.4 (Power outputs: Hotend, Fan, Bed) #define BOARD_RAMPS_14_EEB // RAMPS 1.4 (Power outputs: Hotend0, Hotend1, Bed) #define BOARD_RAMPS_14_EFF // RAMPS 1.4 (Power outputs: Hotend, Fan0, Fan1) #define BOARD_RAMPS_14_EEF // RAMPS 1.4 (Power outputs: Hotend0, Hotend1, Fan) #define BOARD_RAMPS_14_SF // RAMPS 1.4 (Power outputs: Spindle, Controller Fan)

BOARD_RAMPS_PLUS_EFB // RAMPS Plus 3DYMY (Power outputs: Hotend, Fan, Bed) BOARD_RAMPS_PLUS_EEB // RAMPS Plus 3DYMY (Power outputs: Hotend0, Hotend1, Bed)

BOARD_RAMPS_PLUS_EFF // RAMPS Plus 3DYMY (Power outputs: Hotend, Fan0, Fan1) BOARD_RAMPS_PLUS_EEF // RAMPS Plus 3DYMY (Power outputs: Hotend0, Hotend1, Fan) BOARD_RAMPS_PLUS_SF // RAMPS Plus 3DYMY (Power outputs: Spindle, Controller Fan)

BOARD_3DRAG // 3Drag Controller

BOARD_K8200 // Velleman K8200 Controller (derived from 3Drag Controller)

BOARD_K8400 // Velleman K8400 Controller (derived from 3Drag Controller)

BOARD_BAM_DICE // 2PrintBeta BAM&DICE with STK drivers

BOARD_BAM_DICE_DUE // 2PrintBeta BAM&DICE Due with STK drivers

BOARD_MKS_BASE // MKS BASE 1.0 BOARD_MKS_13 // MKS v1.3 or 1.4 (maybe higher) #define BOARD_MKS_GEN_L // MKS GEN L

BOARD_ZRIB_V20 // zrib V2.0 control board (Chinese knock off RAMPS replica)

BOARD_FELIX // Felix 2.0+ Electronics Board (RAMPS like)

BOARD_RIGIDBOARD // Invent-A-Part RigidBoard

BOARD_RIGIDBOARD_V2 // Invent-A-Part RigidBoard V2

BOARD_SAINSMART_2IN1 // Sainsmart 2-in-1 board BOARD_ULTIMAKER // Ultimaker BOARD_ULTIMAKER_OLD // Ultimaker (Older electronics. Pre 1.5.4. This is rare)

BOARD_AZTEEG_X3 // Azteeg X3

BOARD_AZTEEG_X3_PRO // Azteeg X3 Pro

BOARD_ULTIMAIN_2 // Ultimainboard 2.x (Uses TEMP_SENSOR 20)



BOARD_MAKEBOARD_MINI // MakeBoard Mini v2.1.2 is a control board sold by MicroMake

BOARD_CNCONTROLS_11 // Cartesio CN Controls V11

BOARD_CNCONTROLS_12 // Cartesio CN Controls V12

BOARD_CHEAPTRONIC // Cheaptronic v1.0

BOARD_CHEAPTRONIC_V2 // Cheaptronic v2.0

BOARD_MIGHTYBOARD_REVE // Makerbot Mightyboard Revision E


BOARD_MEGATRONICS_2 // Megatronics v2.0

BOARD_MEGATRONICS_3 // Megatronics v3.0

BOARD_MEGATRONICS_31 // Megatronics v3.1

BOARD_RAMBO 301 // Rambo


BOARD_MINIRAMBO_10A // Mini-Rambo 1.0a

BOARD_ELEFU_3 // Elefu Ra Board (v3)

BOARD_LEAPFROG // Leapfrog #define BOARD_MEGACONTROLLER 310 // Mega controller #define BOARD_SCOOVO_X9H // abee Scoovo X9H

BOARD_GT2560_REV_A // Geeetech GT2560 Rev. A

BOARD_GT2560_REV_A_PLUS 75 // Geeetech GT2560 Rev. A+ (with auto level probe)

BOARD_MINITRONICS // Minitronics v1.0/1.1

BOARD_SILVER_GATE // Silvergate v1.0

BOARD_SANGUINOLOLU_11 // Sanguinololu < 1.2

BOARD_SANGUINOLOLU_12 // Sanguinololu 1.2 and above


BOARD_MELZI_MAKR3D // Melzi with ATmega1284 (MaKr3d version)

BOARD_MELZI_CREALITY // Melzi Creality3D board (for CR-10 etc)

BOARD_STB_11 // STB V1.1

BOARD_AZTEEG_X1 // Azteeg X1

BOARD_GEN3_MONOLITHIC // Gen3 Monolithic Electronics


BOARD_GEN6 // Gen6

BOARD_GEN6_DELUXE // Gen6 deluxe

BOARD_GEN7_CUSTOM // Gen7 custom (Alfons3 Version)

BOARD_GEN7_12 // Gen7 v1.1, v1.2

BOARD_GEN7_13 // Gen7 v1.3

BOARD_GEN7_14 // Gen7 v1.4

BOARD_OMCA_A // Alpha OMCA board

BOARD_OMCA // Final OMCA board BOARD_SETHI // Sethi 3D_1

BOARD_ANET_10 // Anet 1.0 (Melzi clone)

// // Teensyduino - AT90USB1286, AT90USB1286P //


BOARD_PRINTRBOARD // Printrboard (AT90USB1286)

BOARD_PRINTRBOARD_REVF // Printrboard Revision F (AT90USB1286)

BOARD_BRAINWAVE // Brainwave (AT90USB646)

BOARD_BRAINWAVE_PRO // Brainwave Pro (AT90USB1286)


BOARD_TEENSY2 // Teensy++2.0 (AT90USB1286) - CLI compile: HARDWARE_MOTHERBOARD=84 BOARD_5DPRINT // 5DPrint D8 Driver Board

Step 4: #define EXTRUDERS #

On line 137 in Configuration.h is the variable EXTRUDERS which should be equal to a number between 1-5. Change it to the number of extruders there are on your printer. If there is one leave it to your default value.


On line 140 in Arduino you see a variable known as DEFAULT_NOMINAL_FILAMENT_DIA. Change the number to the filament diameter of your printer. If it is 3mm leave it be. If you don't know what your filament diameter is research what it is for your printer. Most printers use 1.75mm or 3mm.

Step 6: #define TEMP_SENSOR_# #

Your 3D printer should have thermistors. Thermistors are variable resistors that change resistance with temperature. Hence why they are used for measuring temperature in 3D Printing. There are 5 variables on lines 289 - 294 used for declaring thermistors in each hotend. Value 0 is for the first hotend, value 1 is for your second hotend if you have one, and so on. The value on line 295 is for the heated bed. Set them accordingly to whatever thermistor you are using. The thermistors values are listed below.

-3 : thermocouple with MAX31855 (only for sensor 0)

-2 : thermocouple with MAX6675 (only for sensor 0)

-1 : thermocouple with AD595

0 : not used

1 : 100k thermistor - best choice for EPCOS 100k (4.7k pullup)

2 : 200k thermistor - ATC Semitec 204GT-2 (4.7k pullup)

3 : Mendel-parts thermistor (4.7k pullup)

4 : 10k thermistor !! do not use it for a hotend. It gives bad resolution at high temp. !!

5 : 100K thermistor - ATC Semitec 104GT-2 (Used in ParCan & J-Head) (4.7k pullup)

6 : 100k EPCOS - Not as accurate as table 1 (created using a fluke thermocouple) (4.7k pullup)

7 : 100k Honeywell thermistor 135-104LAG-J01 (4.7k pullup)

71 100k Honeywell thermistor 135-104LAF-J01 (4.7k pullup)

8 : 100k 0603 SMD Vishay NTCS0603E3104FXT (4.7k pullup)

9 : 100k GE Sensing AL03006-58.2K-97-G1 (4.7k pullup)

10 : 100k RS thermistor 198-961 (4.7k pullup)

11 : 100k beta 3950 1% thermistor (4.7k pullup)

12 : 100k 0603 SMD Vishay NTCS0603E3104FXT (4.7k pullup) (calibrated for Makibox hot bed)

13 : 100k Hisens 3950 1% up to 300°C for hotend "Simple ONE " & "Hotend "All In ONE"

20 : the PT100 circuit found in the Ultimainboard V2.x

60 : 100k Maker's Tool Works Kapton Bed Thermistor beta=3950 *

66 : 4.7M High Temperature thermistor from Dyze Design *

70 : the 100K thermistor found in the bq Hephestos 2 *

75 : 100k Generic Silicon Heat Pad with NTC 100K MGB18-104F39050L32 thermistor * * 1k ohm pullup tables - This is atypical, and requires changing out the 4.7k pullup for 1k. * (but gives greater accuracy and more stable PID) *

51 : 100k thermistor - EPCOS (1k pullup) *

52 : 200k thermistor - ATC Semitec 204GT-2 (1k pullup) *

55 : 100k thermistor - ATC Semitec 104GT-2 (Used in ParCan & J-Head) (1k pullup) * *

1047 : Pt1000 with 4k7 pullup * 1010 : Pt1000 with 1k pullup (non standard) * 147 : Pt100 with 4k7 pullup * 110 : Pt100 with 1k pullup (non standard) * * Use these for Testing or Development purposes. NEVER for production machine. *

998 : Dummy Table that ALWAYS reads 25°C or the temperature defined below. *

999 : Dummy Table that ALWAYS reads 100°C or the temperature defined below. *

Step 7: PID Tuning

On lines 258 - 260 in configuration.h is the PID tuning variables. Change them if you know what to change them to. If you don't you are going to have to wait until your 3D printer is all configured except for those lines of code. Setting them to the wrong values can be dangerous and lead to something breaking or catching on fire. Chances are if something is wrong your printer will stop itself but not always. For more information on how to figure out what to change them to when your printer is configured follow this tutorial.

Step 8: #define PIDTEMPBED

Uncomment line 386 if you have a heated bed. If you don't it will be extremely dangerous to run your printer for your heated bed will not be easily controlled. Lines 402 - 404 are your bed's PID settings. Change them if you know them if not like I said before wait until your printer is fully configured. Then follow this tutorial.

Step 9: Endstops

Min endstops are enabled by default. Lines 473 - 478 are to enable or disable your max or min endstops. Comment out to disable or uncomment to enable the max or min endstops.

Lines 495 - 501 are for inverting your endstop's logic. Do this if you know what you are doing. If not you can invert them later if they don't work as planned.

Step 10: Inverting Axis Directions If Necessary

If you don't know what you are doing for this step don't do anything unless something is moving inverted or you know to invert something.

Lines 751 - 753 are for inverting each axis while lines 761 - 765 are for inverting each extruder if you have one. Only change these if you know what you are doing or if you have something inverted.

Step 11: LCD

If you don't have an LCD ignore this step. If you do check online if your LCD is Ultra LCD or Dog LCD because depending on if it is or isn't you will have to uncomment lines 1322 - 1323 accordingly. Uncomment to enable those lines for your LCD. Don't enable both of them at once.


If you don't have an LCD display or don't have an input for a sd card don't worry about this step. If you do uncomment line 1332 to enable sd card support.

Step 13: Uncomment Your LCD Screen to Enable It

Depending on what your lcd screen is it will vary upon which location it will be in marlin. Search for your lcd screen with find or replace and uncomment it. You can press CTRL + F to use it. Good luck!

Step 14: Conclusion

If there is something in here you would like to learn about in Marlin drop a comment below. Chances are I might be able to answer it. If there are any problems with this tutorial let me know. I will probably be able to help you.

You hopefully learned in this tutorial how to configure marlin in this tutorial. Good luck and let me know what you think of this tutorial. I could use some helpful criticism.

Microcontroller Contest

Participated in the
Microcontroller Contest

Be the First to Share


    • Big and Small Contest

      Big and Small Contest
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Make It Bridge

      Make It Bridge



    Question 1 year ago on Step 14

    Hello, I followed this with a custom 3d printer that I built. I had a few issues though, first ,the hotend temperature needs to be at 230 (I am printing ABS filament) but in the pronterface app (that is what I am using with my printer) the hotend only shows getting to 199.77 degrees maximum. also, the extruder motor I have chosen to use (I am pretty sure it is the nema 17) will occasionally vibrate, but other than that, it doesn't do anything. Any help would be greatly appreciated.


    Question 1 year ago

    Hello Sir,
    In the latest release of the firmware of marlin there are only 4 files in the 'marlin' folder.
    Is it okay? or should I download older versions of firmware?

    Screenshot from 2021-10-13 17-54-48.pngScreenshot from 2021-10-13 17-54-40.pngScreenshot from 2021-10-13 17-53-37.png

    Question 1 year ago

    Hello Sir,
    First of all, Thank you for your help. I want to program an arduino Mega with RAMPS 1.4. In my application, there is no need for heating bed, or any heating technology. Can you please help me with this? If I remove the thermal parameters in this program will it be ok or there are other changes that I have to make that I am not aware of ??


    Answer 1 year ago

    I forget what the value you set it to but you can change the thermistor values of the heated bed so it is not used. Therefore you won't trigger a thermal runaway from not having a heated bed on board and you won't need to use a heated bed. I hope this helps. I think the value is "0" if I remember correctly or "-1". Good luck!


    1 year ago

    I am embarking on a different project. I am making a motorized microscope that has XYZ motors, and two limit switches. I have already made a manual controller with joysticks, etc, running on an Arduino Mega. However, I want to convert to a Ramps board with Marlin software to be controlled by a computer. The trouble is, I dont know how to do that. I am a complete newbe to Ramps and Marlin.

    1. I need to set the motor current (much smaller motors than 3D printers)
    2. I don’t need all the temp sensors and fans, and extra motors
    3. I would like to use all the TMC chip features for setting current, acceleration, etc. (now using hard wired jumpers)
    4. Need to enable two limit switches.
    5. how to make HOME work

    The list goes on, but I will stop here. Is there a recommended board and Marlin version? Any help would be appreciated.



    Reply 1 year ago

    Marlin is not suitable for this. Yes it has XYZ functionality but it also is much different. Like you would have to trick the motherboard into thinking it has thermistors on it just to be able to use marlin with it unless you rewrite the marlin firmware. Sounds like you would be better off writing your own code using your own code versus marlin. Good luck!


    Reply 1 year ago

    Thanks for the info. We have written code for manual Joysticks and buttons to run our Mega with CNC v3 shield. What we havent been able to do is create a computer GUI (like all the slicer apps) to run the motors from a keyboard. We would also like to change motor stepping and accelerations through the app. We thought the printer/slicer route might give us some clues.


    2 years ago

    The author screwed up in the first sentence in the Instructable:

    "So your next step is to open Marlin.ino located in the zip file I showed you in the previous step..." (previous step?)"

    Since this comment was POSTED in Step 1, one has to wonder if there is, lol, a Step 0!

    After that error, I noticed that there is little mention of calibrating the printer. Calibrating the printer is the same as configuring it. E.g., where's configuring: homing direction? Movement bounds? Stepper drivers? Stepper movement (jerk, acceleration)? Serial port used? Extruder parking? The list goes on and on.

    If you want to know where to configure your printer for Marlin just go here:


    Question 2 years ago on Step 10

    what if we want to increase the build volume in inches to produce 10 meter product what should we change in merlin settings


    Answer 2 years ago

    some settings are changeable in Slic3r. your build volume is able to adjust there. other settings could include your start and end code. those are Gcode alterations and not printer settings


    2 years ago

    Old thread I know, but you never mentioned how to get that arduino programme onto the MKS - how do I connect the MKS to the PC to transfer the programme.


    Reply 2 years ago

    Arduino communicates by means of serial through a USB port on your pc. Arduino has tons of documentation on how to do this and it is super easy. Good luck!


    Question 2 years ago

    Hi I am new to 3d printing. I tried to install marlin firmware on my creality cr10s pro and it won't boot up. If I use the firmware from creality it boots up. Also it is not detecting when to change the filament when I am trying to do a multicolored print. Please help


    Answer 2 years ago

    Creality printers don't have bootloaders on them. Look up how to install bootloader onto the cr-10. It's easy if you know what you are doing and have a spare arduino uno or nano. Good luck!


    Question 3 years ago

    hey I did the changes as directed by you in this tutorial but I am unable to compile the sketch. when ever I try to compile I get the following error I am unable to find out the cause of this error please help me and thank you in advance.

    the error:-
    Arduino: 1.8.9 (Windows Store (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
    Build options changed, rebuilding all
    sketch\ultralcd.cpp: In function 'menu_edit_float52':
    sketch\ultralcd.cpp:4886:3: internal compiler error: Segmentation fault
    DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52, 100);
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <; for instructions.
    lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status
    compilation terminated.
    c:/program files/windowsapps/arduinollc.arduinoide_1.8.21.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed
    collect2.exe: error: ld returned 1 exit status
    exit status 1
    Error compiling for board Arduino/Genuino Mega or Mega 2560.
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

    Question 3 years ago on Step 14

    Hi , Thank you for incredible guide!
    I add to Mks gen L "External SD Card Slot Module" and is working.
    But after i put the SD, I need to click on refresh for the marlin see the card,
    I know thet it impassable to make it Auto Detect, (as soon as I insert a card it immediately indicates' card inserted) without needed to press to check it.
    Can you help me and tell me how to do it?


    Answer 3 years ago

    Use an lcd display with an sd card holder is the only way you can do what you want. This way the firmware is on the motherboard while you swap sd cards. Good luck!


    3 years ago

    hello, we have followed almost everything but when we load a file for the printer to print (in pronterface) it doesn't move at all
    we have used arduino mega with ramps 1.4 marlin firmware and pronterface


    Reply 3 years ago

    What drivers are you using? Did you configure it for the right drivers? Sorry I think I read the post wrong. Thanks!


    Reply 3 years ago

    we are using A4988 drivers
    and when we load the file pronterface tells that the print has started but not even a single motor moves.