Making GCODE controllable LEDs

GCODE LED Mosfet



Hmmm...To be able to control an LED from GCODE does provide a level of swagger to your 3D printer. With this guide you can control your light with a few GCODE commands. You can place a line of GCODE in your Start GCODE and End GCODE of your favourite slicer to illuminate your print process when it starts and stops. Or, you can edit your the GCODE generated by your slicer to illuminate the LED at certain printer events.

You can also edit Marlin 1.1.8 to include a menu item in the LCD menu to turn it on and off. How cool can it get? Adding the LED sub-menu does require knowledge on how to edit and compile Marlin in order to accomplish this. If you are not up to speed on how to upgrade to Marlin 1.1.8, visit our Upgrade to Marlin 1.1.8 section to learn how. But don't worry if you don't know how or don't want to. You can still get the GCODE controlled LED to work without configuring/compiling Marlin. You only need to tinker with Marlin if you want to control the LED from the LCD sub-menu. You can still use your Start/End GCODE sections of you favourite slicer to control this.

Now, about the Halo LED. For the correct fit around the Anet A8 print nozzle, 60mm Halo lights fit perfectly. These specific Halo LEDs used in this guide also have built in resistors. This means that you can plug them directly into your power supply or on the 12v power input on the Anet A8 motherboard. The total amperage usage for this LED is only 80 Milliamps @ 12vdc.Even the anaemic Anet power supply can handle this with zero problems.

One thing to note about this specific Halo light is that comes with a short extension of cable soldered to the back or bottom of the light. See pictures above with the short wires. To be on the safe side and to also add some length to the cable, we will need to de-solder this short pair of cables and solder on some better 24 gauge cable. This will now direct the cables to the face of the light and keep them away from the carriage. It's also a good idea to add some shrink wrap near where the wires come off of the light. Bend the wires slightly and apply heat to the shrink wrap. This will give it a natural curve going up towards the top of the printer and add some stress relief when the printer is moving.

OK, lets build this.

STL Files

Thingiverse STL link for MOSFET case shown in last picture above

Steps

  1. Download the STL file above and print the MOSFET case .
  2. De-solder the pre-installed short black and red wires from the LED.
  3. Following the picture above (top row far right), cut the red wire of your new cable longer than the black one. The cut ends should line up with the solder points almost perfectly.
  4. Strip the wires carefully and tin both wires with solder. Also add some solder to the positive and negative terminals of the led. The side with the lights.
  5. Solder the black negative wire to the light first. This will ensure that the red wire will not get melted since the solder joint is pretty close the the positive red wire.
  6. Apply some heat shrink like above if desired.Also place some 1/4" 3M double sided tape in the locations shown below. Make sure to cover the old solder points on the bottom to make sure no shorts occur.
  7. GCODE Anet A8 LED Adhesive
  8. Remove the pair of white thermistor wires, red insulated hot-end wires,extruder fan wires and stepper motor wires from the motherboard.Fish the wires through the center of the LED and adhere the light to the bottom of the extruder carriage. It's a good idea to test fit before removing the adhesive backing on the double sided tape.
  9. Zip-tie the wire coming from the LED to the rest of the printer head wires.
  10. Install the MOSFET and case about 2 inches above the motherboard just next to the USB port.
  11. Using the wiring diagram below, make the following connections into the MOSFET.
  12. Anet A8 LED Mosfet
  13. Since the Anet does not really have any IO pins (motherboard input/output pins), we will need to modify the 10 pin ribbon cable to get access to pin 29. This is an open pin and already is configured to respond to GCODE commands. We just have to expose it. Follow the picture below.
  14. GCODE A8 Pin Diagram
  15. You will need to cut the ends off of two female Dupont connectors and solder to the extensions of the GND and pin 29 (6th cable) on the 10 pin ribbon cable.Connect the wires respectively to the MOSFET as shown in the MOSFET diagram. Shrink wrap is advised. Your 10 pin ribbon cable should look like this.
  16. Anet A8 cable pinout for LED
  17. Power off the printer. Using the MOSFET diagram above, make the power connections to the power supply as shown below.
  18. Anet A8 Power Supply

Basic Usage No firmware compiling

M42 P{your pin number} S{brightness value 1-255} Anet A8 can only do ON/OFF no PWM pins are available.

Anet A8 Example Place M42 P29 S255 in start GCODE section of your slicer to turn ON when print starts. Place M42 P29 S0 in end GCODE section of your slicer to turn OFF after print finishes.Use example below and place M42 P29 S255 and M42 P29 S0 in Start/END GCODE respectively making sure to place them one GCODE command from the end. Do not edit anything else in your GCODE and ignore the additional settings below. They are specific to this printer.

Anet A8 GCODE LED

Advanced Usage - Firmware compiling required

Marlin 1.1.8 also provides an excellent option to include a case light option that will appear on your lcd screen to turn the light on/off. You will need to compile a version of marlin and edit your Configuration_adv.h file to tell Marlin what pin you have available to use.Anet A8 only has pin 29 available so you would add that to #define CASE_LIGHT_PIN 29.Uncomment all sections below and make sure everything matches.

#define CASE_LIGHT_ENABLE
#if ENABLED(CASE_LIGHT_ENABLE)
#define CASE_LIGHT_PIN 29 //Set this number to the available pin on your motherboard
#define INVERT_CASE_LIGHT false // Set true if Case Light is ON when pin is LOW
#define CASE_LIGHT_DEFAULT_ON true // Set default power-up state on
#define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // Set default power-up brightness (0-255, requires PWM pin)
#define MENU_ITEM_CASE_LIGHT // Add a Case Light option to the LCD main menu
#endif

If you are not up to speed on how to upgrade to Marlin 1.1.8 or make the changes above, visit our Upgrade to Marlin 1.1.8 section. If you have successfully compiled and uploaded Marlin 1.1.8, you will following those exact steps but only make the changes above to the configuration__adv.h file (lines 239-245) then compile and upload. That's it.

If you have a pwm capable pin available on your motherboard, Marlin will add the brightness sub menu in your LCD screen. No brightness sub menu is available if your motherboard pin in non PWM.

GCODE commands to control the LED on Anet A8 example above would be M42 P29 S255 M42 P{your pin number} S{brightness value 1-255}

Build Your Own