RBG LED Driver Board for Your 3D Printer!

Hello readers, today I want to show you guys how to add RBG LEDs to your Marlin Firmware powered 3D Printer. This should work with most boards which are compatible with the Marlin firmware and have free PWM pins (it could work in other ones with a little bit of tinkering as well).

Not long ago, the Marlin firmware added support to control RBG LEDs from firmware, not only that but also automatic control of them based on states that the printer is in. This allows you to get a heads up on how your printer is doing depending on it’s status. Not only that, but you could also program your Slicer’s GCODE to use specific colors depending on what’s going on with your printer. Needless to say, this mod can also apply to any Arduino board which has PWM pins. It is quiet easy to write code to control this LED board with them, and write compatible code with it.

So, without further a due, here is how you can build your own PCB to control an LED strip.

Materials Required for This Build

These are the materials that you will need to complete this build:

  • Wire (I used 22 Gauge wire for this build)
  • 2 x Female to Female Wires W/ Dupont Connectors
  • 3 x 2N2222 NPN Transistors
  • 4 x Screw Terminals (Sort of optional)
  • 1 x Prototyping Perf Board
  • Flux Core Solder
  • Strip of RBG LEDs
  • Shrink Tubing (You can also use Electrical Tape)

These are the tools that you will need to complete the build:

  • Soldering Iron
  • Solder Sucker (Optional but useful)
  • Wire Stripper (Any kind would do)
  • Flush Cutters (Or anything that can cut leads)
  • Flux (Optional but useful)

Building The LED Driver PCB

The start of this build without question are the 2N2222 transistors used to drive the LED strips. The 2N2222 is a BJT transistors, which in the simplest terms is a device that acts like an electrical switch (Very similar to Relays but made out of a semiconductor material).  These type of transistors consist of three legs, which as shown in the diagram below have three different names and functions. Click here to view the datasheet of the 2N2222 transistor.

The Base of the transistor is where we will be sending our switching signal, this can be just a normal High signal (5V for any Arduino based microcontroller) or Low (Which is basically 0V or Ground). By doing this, we end up controlling any components connected to either the Collector or the Emitter.

Similarly, we can also use PWM (Pulse Width Modulation) in order to control the voltage across the Collector-Emitter path. PWM basically chops up a specific voltage (for instance 5V) into smaller voltages by having a “High” signal for a certain percentage of time, and a “Low” signal the rest of the time. For instance, if you wanted to get 2.5V from a 5V source, you will PWM it so 50% of time it is “High” and 50% of the time it is “Low”. Complicated? Well lucky for us, the firmware is going to do all of the work for us!

For now, all you have to do is note the name of the pins of your transistor. This will be important for you to know going forwards. Just remember that if you view your transistor from the flat side, the left pin is the Emitter, the middle one will always be our Base, and the right pin will be our Collector.

Feeling lost? Here it’s a diagram that I made so you can see how everything will be electrically connected:

Each color of the LED strip will act just as if it was a single LED. Every one of our transistors will switch a specific LED color and vary it’s intensity. So, depending on the voltage being provided by each pin of your board, you will be able to achieve different colors. Basically like when we used to mix paint as a kid, but with electricity, and logic of course.

The way that I got my 2N2222 transistors was by buying a assorted pack of transistors. Transistors are very useful to have around so you should get one of these, or you could find a pack of 10 x 2N2222 on Ebay easily.

The Perf board is where we will be soldering all our components too. Perf boards are extremely useful when you want to make just a single circuit. Just keep in mind that there is only one side that you can solder to (At least the ones I have are single sided).

Something that I tend to do with my Perf boards is to cut them to size before using them (You can always do it the other way around). This allows you to save the rest for other projects. Since we will be only using three transistors in our circuit, the piece of perf board that we will be using does not have to be big at all. My piece was 8×8 holes, and I still had enough space to keep the transistors far apart from each other.

Step 1: Soldering the Transistors to Perf Board

To make it easier for myself, I mounted my Perf board in my custom made 3D printed PCB vice which I showed you guys how to make in a previous post.

Next we have to take our transistors and slightly bend their outermost leads outwards. This will allow us to easily mount them on our Perf board and have enough separation so they won’t short out with the Base pin. Keep in mind that we are only bending outwards the Collector and Emitter pins.

Now insert transistors into the holes in the Perf board. Be sure that the transistors have about 2 holes of separation from each other. This minimizes the risk of shorts when we go to solder them.

After all the transistors are in place, you can always flip the whole Perf board and bend the leads in order for the transistors to not fall down when we go to solder them.

It is finally time to start melting some metal! Take your solder and your soldering iron, be sure that they are heated to a suitable temperature (I tend to heat mines to about 300C – 350C (572F – 662F)). Take your time and do not burn yourself!

Done soldering the legs? Great! Now we have to trim those leads. Use a flush cutter to cut the excess leads flush with the blob of solder. Don’t worry if you don’t get the whole lead, It does not have to be perfect.

Now we need to cut our wires. The length of the wire is really up to you. You need in total (For now) 7 pieces of wire. 3 that will go to your 3D printer’s controller board, 3 that will go to your LEDs, and 1 that will go to the ground of your power supply. Here is what you need to consider for each of these groups of wires:

Controller Board Wires: These just need to be able to reach from the Gates of your transistors to your 3D printer’s controller board. If you know that your PCB will live close to your controller board, then you don’t really need to cut them that long, just long enough that they will reach the pins of your board.

LED Wires: These wires are going to be connected from the Collector of your transistors to the RBG pads in your LED strips. If you are using a block connector, make sure that your wires will reach from where you place your PCB to where you would like to place your block connector.

Ground Wire: This wire will be the one that will connect the emitter of all the transistors down to the ground of your printer’s power supply. This wire just needs to be long enough to reach the screw terminal of the ground rail of your power supply.

Step 2: Cutting Wires for the Connections

Now you need to strip the insulation of the wires, for the end of the wires going towards your PCB, you want to strip the insulation back about 4-5mm. For the end going to the block connector, 6-8mm should be fine. For the one going to the power supply, you want it to be at least 10mm so it can make good contact.

Now it is time for us to create our Controller board to Gate wires. To do this, we have to sacrifice two of these female to female wires with dupont connectors on their ends. Cut them in half in order to create 4 separated wires (We will only be using 3 of these). Now, from the wire end, strip the insulation back about 5-6mm.

Step 3: Creating the Gate-to-Board Wires

Now, take the previously cut wires (In my case the black wires) that are going towards the controller board and the ones with one female dupont connector, tin their exposed wire ends and solder them together as shown below.

After soldering the wires together, use a piece of shrink tubing to cover the solder connection. If you do not have shrink tubing, you can always use electrical tape.

Now our wires that will connect to our Gate-to-Board wires are finally done and we can move on to soldering them to the transistors.

Step 4: Soldering all Wires to the PCB

Now it is time for one of the most tricky parts of the build, soldering all the damn wires to the board. Just kidding, I wouldn’t say it is tricky but you need to be careful when doing so in order to not short any of the connections.

First, take your Gate-to-Board wires and slide their wire end in the hole next to the gate of the transistor. From there you can bend the wire to the side and solder it by flooding wire with solder, making sure that the new solder and the solder in the Gate of the transistor fuse together.

Now, take your wires that will connect to your LEDs and solder them to the Collector of your transistors. Basically, doing the same process that we did for the Gate-to-Board wires.

Now comes a part that is a little challenging, soldering the Ground wire and joining all of the grounds. First, solder negative wire to the middle transistor’s Emitter. From there, you will have to flood all the pins in that same row with solder in order to join together all the grounds. You could also strip the insulation out of a small piece of wire and use the wire as a bridge to solder the three grounds together (But still, feel free to laugh at the clip of me struggling with this step).

And that’s about it, that should be all our connections soldered in place. Now it is time for us to test this bad boy to see if it works or if it would release the magic smoke.

Step 5: Testing the PCB

At this point, if you have a Arduino Uno or Nano laying around, you can test your LED driver board. In my case, I had an LED strip already wired which I could connect to the board, but if you don’t you can always skip to step 6 and come back to this one after you are done. Anyways, back to the scientific testing!

As was stated before, my small test LED strip was already wired up. I decided to wire my board in the same way as the pins are shown in the strip, which goes:

  • Black = +12V
  • Red (Ground) = Red = Left Transistor
  • Blue (Ground) = Blue = Middle Transistor
  • Green (Ground) = Green = Right Transistor

Connect the transistor’s Gate wires to the Arduino’s pins in this manner:

  • Red – Pin 13
  • Blue – Pin 12
  • Green – Pin 11

Now download this Arduino sketch and flash it to your Arduino. Your Arduino should start flashing in the same manner as the picture below.

In order to power up the LED strip we will need to connect it to a 12V source. If you have an old ATX power supply or random 12V power supply you can use that. There should be two leads, a 12V lead and a ground lead. Connect the 12V lead of your power supply (Sometimes labeled as just “+”) to the +12V connection of your LED strip, and Ground to the Ground lead that connects your transistor’s emitters. If you are using an ATX power supply, the yellow wire should be +12V and the black wire should be Ground.

Keep that you will also have to wire the ground of your Arduino board to the Ground of your power supply.

If your LED strip starts to flash in a sequence that starts with Red, followed by Blue and Green and many other colors, then you should be good to go because your strip works perfectly!

Step 6: Wiring the LED Strip

Now it is high time that we wire our led strip. For this step you need your roll of LEDs and some wire. If you are not using a screw terminal block like I am, then you will not need to cut more wire, your wire will be the one going to the Collector of your transistors. So, if you are connecting directly, just keep in mind which transistor are you soldering to which color and you should be fine.

A word of warning, be careful how many strips you use for this build. Before anything, measure how much current one of your strips draws while emitting full brightness white light, and multiply it by the amount of sections of the LED strip that you would like to use. When I measured my strips, one of them while emitting White light would draw about 0.1A, and the maximum continuous current this transistor can handle is about 0.6A. Which means I can get away with having 6 strips of LEDs, however, because we have a 3 transistors, the current will split (almost) evenly across them. Turning the current through every transistor into about 0.033A, so that number of strips that I said before, multiply it by 3 and that should be our max amount of strips.

In my case, I soldered a Yellow wire to the “+12V” pad, Red to the “Red” pad, Black to the “Blue” pad, and finally White to the “Green” pad.

In order to make your life easier when soldering these wires, first tin the pads on the LED strips, then tin your wires. To solder them, just touch the wire and pad together and while touching them with the soldering iron. When your solder melts, remove the soldering iron and let the solder joint cool down. Be careful with this step, as I burned myself tinning the pads (You can see if in the clip below lol).

Step 7: Attaching the LEDS to the Bracket

For this beautiful occasion, I made a swivel bracket for my Folgertech Prusa i3. This bracket attached to the acrylic frame of my printer and allows me to tilt my LED strip to any area that I need light in. It also has a flat surface where I can easily stick the LED strip to. If you would like to print these files for your Folgertech Prusa i3, you can get the .STL files here.

And so I did what any man would do and removed paper covering the sticky adhesive back of my LED strip and stuck it to my bracket. I do not show it here but I also added two zip ties to hold the wires in place so they wouldn’t flap around and break the solder connections.

Now, if you are using a block connector, you can connect your driver PCB board to the LED strip by screwing in the connections to the block. Be sure to remember the way in which you are connecting them, because it will be very important for our next step.

Now we are finally ready to install our monstrosity to our dear and beloved 3D Printer!

Step 8: Installing LEDs and Board to the 3D Printer

So, at least for my printer, I started this step by screwing in my bracket to the top of my printer. You can always just stick your LED strip to your printer in a position that illuminates your working area (I just think it’s better to use brackets in this case).

Now that the bracket is installed, we need to connect our LED driver board to our printer. First, connect the Ground of our board (Connected to the Emitter of our transistors) to the Ground of our printer’s power supply. Next, connect the +12V connection of our LED strip to the +12V of our printer’s power supply.

Now here comes the tricky part and the one that changes depending on your board. Every board is different and has different pinouts, what you are going to do is find a schematic of your board and then find the “Servo” pins. Let’s use the Ramps 1.4 as an example. Here it’s the pinout of the Ramps:

If you look very closely, located at the bottom left you will see some pins labeled “Servos”. These pins are D11, D6, D5 and D4. These are pins to control servos, you don’t need to know what they are but all you need to know is that the previously mentioned pins can output PWM signals, which can allow us to turn on, off and change the brightness of our LEDs.

So, knowing this information, I went ahead and connected my Gate-to-Board wires to Pin D6 for Red, D5 for Green, and D4 for Blue. The reason behind not using D11 is because for some odd reason, when I connected any wire to it, no matter the color, it did not work at all. This also happened when I installed one of these modules on my friend’s 3D Printer which also used a Ramps, but instead, the issue was with pin D5. It is a weird issue but it does happen, so if one of your color does not work, be sure that it is connected properly, if it still does not work, switch pins in the firmware and hardware.

And that’s basically it for the physical connections, now it is time to configure our firmware in order to use the LED strip.

Step 9: Firmware Configuration

If our LED driver board is the heart of this project, the Marlin firmware is the soul of it. In the newer versions of Marlin they added the option to use any unused digital pin to be able to control LED strips. This feature is only available on newer versions of the firmware (But feel free to check your firmware and see if this feature is there just in case). If your firmware is old, you might have to transition your “Configuration.h” to a newer version. This is done by copying and pasting any non-stock configurations from the old firmware’s “Configuration.h” to the newer one, until everything looks and works as it should.

If you need the Marlin firmware, you can find it here. If you need the newest version of the Arduino IDE you can also find it here.

Now, after that process is done, navigate to your firmware’s “Configuration.h” and scroll down until you see a line that says “#define RGB_LED” and uncomment the line by removing the two “//” in front of it. Now change the values of the “# define RGB_LED_ …” lines to the pins that we stated before( Red = 6, Green = 5, Blue = 4).

Now that you have made those changes, connect your 3D through USB to your computer and flash the firmware to it. If everything goes well, you should not see any errors pop up on the Arduino IDE. Now it is finally time to test the LEDs but in our printer!

Step 10: Testing the LEDs w/ 3D Printer

So, in order to test out the functionality of the LEDs, you can use this GCODE file that I made to make sure that all the colors cycle properly. Like the Arduino code, this GCODE tests the red, blue and green colors at different intensities (to check that PWM is working) first and then tests other colors.

In order to use this GCODE, you can either load it to an SD card and run it from your LCD or just run it through your host printing software. If you would like to send your own GCODE, you can either write it on a notepad text file with the extensions “.gcode” or send it through your host software (the easiest way)

Regarding controlling LEDs through GCODE: Marlin has a specific GCODE command to control LEDs and their color intensities, this command is “M150”. You can either run M150 as:

  • M150 Red (For the Red color)
  • M150 Blue (For the Blue color)
  • M150 Green (For the Green color)

Using M150 this way will just light up the LEDs at the color that you tell it, at full intensity. There is also another way in which you can control them by using:

  • M150 R255 B0 U0 (For Red at full intensity)
  • M150 R0 B255 U0 (For Blue at full intensity)
  • M150 R0 B0 U255 (For Green at full intensity)
  • M150 R255 B255 U255 (For White light at full intensity)

Using R, B, U as parameters gives you much more granular control when it comes to setting your desired colors because you can mix colors by changing the intensity of each color. For instance, if you wanted to get Purple, with 1/2 of the full intensity you will just send the GCODE command “M150 R127 B127 U0”.

Tips regarding setting colors: Because the PWM signals can only go 255 (5V), your maximum brightness will be at 255 and your minimum brightness will be at 0 (0V). The range of 0-255 has to do with the 8-bit processor that these boards tend to use.

There is also another feature which we have not talked about yet, which is included on the Marlin firmware which was automatically enabled, which is the “Status LED” feature. This feature allows the printer to show with light colors the status of your printer.

Here it’s how it works:

When your printer is heating your bed up, the LEDs will go from Blue (Cold) to Purple (Target temperature). When your printer is heating up the hotend, it will go from Purple (Cold) to Red (Target Temperature). After this happens, the printer will start printing and it will change the LED colors White, allowing you to easily view your printer’s area as it prints.  This is extremely useful because you don’t have to be near your printer to know what’s going on with it.

Anyways, that is about it from me for today. I hope you guys enjoyed this tutorial as much as I did making it. If you are having any problems during the build process, do not hesitate to ask questions in the comments below. If you enjoyed this post, share it with your friends or people that you think might benefit from this mod.



Leave a Reply

Your email address will not be published. Required fields are marked *