Tuesday, December 1, 2015

A DIY A4 Laser Engraver made from a scanner and a printer on ATmega328

This "Get Ready For Win98" Laser Engraving Machine it's built using an old scanner, and an old printer.
A laser engraving machine is a tool that uses lasers to engrave an object.

I've an old broken scanner and an old printer lying around. Inspired by this instructables project:
I decide to build a bigger version of my small CD-ROM based laser engraver, you can find here:
That way, the engraving area are will be almost 212mm x 274mm.
Note that some part of this post is taken from the above blog post link.

Before starting up, read my blog disclaimer and the one below:

Warning! Laser diodes drive are emitting visible and invisible laser radiation and they are extremely dangerous! Their light can permanently damage the eyes. You must never look into the working diode even without the lens or point it on a reflective surface. Laser beam can cause burns or fire. This is usually a Class IIIb laser. Everything you do at your own risk.

The Y-axis it is build using the scanner assembly, the X-axis using the printer one.
As you can see by the Get Ready For Win98 sticker, the scanner is pretty old, and this sticker was so vintage that i've decided to leave it on.

The base of this machine is the scanner itself.
The scanner was completely disassebled, all except the motor and the movement mechanism is removed. The same applies for the printer.
Assembling the hardware, pay attention to build it making X normal to the Y axis. The two direction has to be perpendicular, or your engraving will have distortions.
The printer mechanism it is connected to the Y-axis scanner assembly, that way, the laser moves over the part to be engraved.

My engraver it is powered by a 12V 2A power supply, though the total current absorbed it's 700mA.

The brain of this project is an ATmega328p running at 16Mhz. loaded with grbl firmware http://github.com/grbl/grbl, which is a powerfull yet opensource g-code parser.
I've used an Arduino Mini board, even if the software does not use the Arduino framework.
A 7805 voltage regulator it is used as power supply for the ATmega.
Grbl 0.9 it is build for 3 axis router, to make it works on 2 axis systems like this, with hard limit and homing enabled, a custom version of the firmware it is needed. The only change to apply to version 0.9g are on config.h file.
#define HOMING_CYCLE_0 (1<<Z_AXIS) 
#define HOMING_CYCLE_1 ((1<<X_AXIS)|(1<<Y_AXIS)) 
was commented out and changed to:
#define HOMING_CYCLE_0 ((1<<X_AXIS)|(1<<Y_AXIS))
//#define HOMING_CYCLE_0 (1<<Z_AXIS) 
//#define HOMING_CYCLE_1 ((1<<X_AXIS)|(1<<Y_AXIS)) 
Then the new grbl firmware can be compiled and used, preventing grbl 0.9 homing problem on 2 axis machines.

My custom version of grbl v0.9g compiler for ATmega328p @16Mhz, with a baudrate of 115200, can be download below.
CP2102 it is used as USB to UART board.
You just have to upload the firmware using your favorite uploader, the grbl wiki page drive you on how to do this step.
On the grbl wiki page you could also find any other information about command and software setup.

The motor driver I've use to move the X and Y motor stepper are Polulu A4988 Stepper Motor Driver Carrier, based on Allegro A4988.
My scanner has an unipolar 5-wire stepper motor. That Allegro driver works only with 4-wire bipolar stepper motor. So I've transformed the unipolar motor to a bipolar stepper motor.
To made this modification, I've just cut the common wire between the two main windings. Then I checked that the windings haven't got any connection by using a multimeter. That way i have two coil, like a bipolar motor. Look at the image below for carify:

The printer has a bipolar 4-wire stepper motor.

We can setup how many microstep and how much current Allegro A4988 sends to the motor.
Incrasing microsteps makes the motor more accurate, but it also reduce the motor torque.
You can made some tests to find your best motor power setup.
For mine motors, to allow a smooth and fine motor movement, and a good torque the Allegro A4988 it is setup to 8 microsteps for the Y-motor, and 16-microstep for the X-motor.
Below you can find the basic Polulu board connection wiring.

To make the Polulu board runs at 8 microsteps M1 and M2 has to be connected to logic power supply VDD, if you want to run it at 16 microsteps, connect also M3 to VDD.

Motors supply VMOD is connected straight to 12v.

On each axis a limit and an home microswitch it is placed to prevent axis over-running, and eventually the motor or the motor driver damage.
Because the limit switch are pretty sensible to noise, I've added an high pass 100nF capacitor and an additional pull-up 10k resistor. Also the limit and home wire are indipendent and distant from the motor and laser cable strap.

The laser used is a red laser diode, taken apart from the DVD-ROM writer optics.
In CD-ROM and DVD-ROM you could also find IR driver, DVD laser writer diode will be a little more powerfull than the CD one.
Laser diode usually has three pins, one is the common ground, laser and photodiode cathode (-), one the laser diode anode (+), the other is the monitor photodiode anode(+).
If the diode you are using has no mark, and you do not know the diode pinout, you have to find the laser cathode and anode. One simple method I use is to power up the diode with a 1.8 to 2.2v current, just for a little amount of time, let's say 1s, if it absorbs current, that wiring is the laser diode pinout.

Laser diode has to be drive with a proper driver, to run mine, i've build a LM317 based laser driver.
This laser driver can drive diode from 12mW to 700mW.
A 9v voltage regulator prevent overvoltage on the laser diode.
Also a NPN it is placed to allow the TTL input that comes from the microcontroller to enable or disable the laser.
We are using LM317 IC as a current regulator.
Input voltage get in the Vin pin of the LM317, from the output Vout to the ADJ pin there is a resistor R connected.
The output current Iout is given by the formula Iout = Vref/R.
Over there resistor there always be Vref voltage. When current decrease, the voltage over R should be lower, but that way the regulator increase his output voltage to adjust his Vref voltage.
Vref is 1.25 for the LM317. R is made using a fixed resistor R1 and a trimmer R2. That resistor and the trimmer sets the current that the laser use.
So laser driver current is given by the formula: I=1.25/(R1+R3).
The power rating of the resistors R1 and R2 is calculated by the forumla P=1.25*I.
Before connecting the laser and testing the driver, check that the resistence is the higher value possible, then connect the laser and measure the absorbed current using an amperometer. Note that if you set too much current to the laser, that will blow.
Below the laser driver circuit.

A standard 60mm x 60mm pc brushless fan is installed to clear the smoke, this prevents the laser optics lens to be clouded.

Commands to the engraving machine are sent through UART at 115200 baud rate.

One you have built the machine, checked and connect all, upload the grbl firmware to your microcontroller, you could use terminal software, or a grbl controller to setup your board. I'm using Universal G-Code Sender to setup and send command to grbl, but you can also use a simple terminal.

The first thing to do is test the motor movement:

To test it, just send the
X10 Y10
command, or use the Universal G-Code Sender movement button.

You should see a motor movement on each axis.

Also check the laser is turned on and off using

Now to setup the correct motor distance to run, you have to set each motor step/mm.
The axis motor step/mm calibration method is pretty simple.
Let's try the X axis calibration as example.
We know how many step/mm or steps_per_revolution grbl is actually setup, grbl $100=250.000 (x, step/mm) parameter.
Now, we move your motor for some steps, let's say 100 microsteps, the axis should have move 100mm.
Now we measure the real distance the motor has moved, let's suppose is 181mm.
The new step/mm value for this motor axis should be
steps_per_mm = (steps_per_revolution*microsteps)/mm_per_rev
138.121 = (250*100)/181
Now, if you move the motor 100mm, it should move 100mm.

Because i've installed the limit and home switch, I have alse enabled hard limits
I've setup the homing pull-off to 5mm, cause my microswitch have a long lever, and i want the motor to move fare away after the home cycle.
Also the homing cycle it was enabled:
And the homing direction mask it is changed. One may even need to invert axis direction, "dir port invert mask" is the paramenter you have to touch.

Those are the most common grbl setup, for the complete list, look at the grbl wiki page.

Below you can find the grbl configuration parameters i changed:
$21=1 (hard limits, bool)
$22=1 (homing cycle, bool)
$27=5.000 (homing pull-off, mm)
$23=3 (homing dir invert mask:00000011)
$100=37.879 (x, step/mm)
$101=94.246 (y, step/mm)
$110=100.000 (x max rate, mm/min)
$111=100.000 (y max rate, mm/min)
$130=212.500 (x max travel, mm)
$131=274.400 (y max travel, mm)

Now you could be able to send g-code drawing to your engraver.

There are a lot of software you could use to build g-code draw, the one I use the InkScape.
The working are for this plotter is 212mm x 274mm, so setup your project area to this dimension.
Once you have you path, then you could select the path you want to engrave, and transform it using the InkScape laser engraver extension.
Just copy the extension on your extension inkscape folder, restart inkscape, and use that to build your g-code file.
Once you have your g-code file, you could send it to grbl using Universal-G-Code-Sender, or other grbl software like Grbl Controller.


  • read risk disclaimer
  • excuse my bad english


  1. This comment has been removed by the author.

  2. Great work
    David How long is the wood frame or the distance from the work area to the X mechanism?

    1. Hello, thank you. It's 5.5cm from working area to laser, and 10cm from working area to the bottom of the printer mechanism. Laser height is adjustable.

  3. This comment has been removed by a blog administrator.

  4. Hi,
    You are doing a great job, espacialy with the laser engraver ;)

    Can you tell me what you have changed in your version of grbl?

    1. Hello, you can find the compiled grbl hex and the code changes in the download file on this blog post.

  5. Hello Davide, awesome project! I want to make my own. Could you give me a list of all the parts you used?

    With kind regards

    1. Hello and thank you for your feedback. Because I've used parts from an old scanner and printer, i've to build attachment by my own, I've not any list unluckly.

  6. Hi ... Looks great
    Just 1 question .... Would a lightscribe DVD laser be more powerful ? Or have they effectively done the same thing

    1. Hello and thank you. As far as i know no, it will be almost the same power. Take a look at this interesting page: http://elabz.com/laser-diode-power-output-based-on-dvd-rrw-specs/

  7. i david where i can contact you?
    whatsapp or facebook ?

    1. Hello, you can write your contact mail here.

  8. i want to buy this stuff today , im asking if u have list of items needed ( elecronic stuff) and do u have PCB schematics for print? then i can solder the items easy and faster

    1. Hello. You can find the schematics above in the article post. Basically you need a laser and a laser driver. 2 motors and 2 motors driver compatible with the grbl firmare, and a grbl compatible board (an atmega328 one would do the job).

  9. hello , is it possible to obtain a full instruction manual on the project ? a step by step detailed manual wood dimensions and more pics of the connections and especially the arduino programming part etc ... i am very interested in it , and is it possible to use a more powerful laser diode ? where can i extracted from what do u advice (krmelie@live.com) your support is highly appreciated

    1. a manual that is similar to instructables (Frankenstein engraving thing)

    2. Hello, yes, you can find it there. I've linked it above in this post as the inspiration project.

    3. i meant a manual of your work that is similar to that project .. i am interested in your project

    4. Hello, sorry for that delay. Unluckly not. All the tutorial/manual things I've written for this project are here in this blog post.

  10. I dont have pb6 pb7 pinout in my arduino . Im using arduino UNO . Not arduino micro pro
    Any idea ? What pinout i can use?

    1. Hello, PB6 and 7 are connecte to crystal on standard Arduino UNO, just like the circuit. That circuit is for a plain ATmega382, but if you have an Arduino the crystal part it's already there. Hope this helps

  11. Grbl 0.9 it is build for 3 axis router, to make it works on 2 axis systems like this, with hard limit and homing enabled, a custom version of the firmware it is needed. The only change to apply to version 0.9g are on config.h file.
    #define HOMING_CYCLE_0 (1<<Z_AXIS)
    #define HOMING_CYCLE_1 ((1<<X_AXIS)|(1<<Y_AXIS))
    was commented out and changed to:
    #define HOMING_CYCLE_0 ((1<<X_AXIS)|(1<<Y_AXIS))
    //#define HOMING_CYCLE_0 (1<<Z_AXIS)
    //#define HOMING_CYCLE_1 ((1<<X_AXIS)|(1<<Y_AXIS))
    Then the new grbl firmware can be compiled and used, preventing grbl 0.9 homing problem on 2 axis machines.

    where i can find Config.h file ?

    1. Hello. On grbl main source code folder.

    2. ok but where and how to upload this src folder to arduino ?

    3. what about my second question below ?

    4. Hello, you have to compile it using avrgcc, then you can upload the compiled hex to your micro. Take a look here: https://github.com/grbl/grbl/wiki/Compiling-Grbl

  12. btw i purshased arduino uni with CNC Shield and a4899 driver
    and laser 500mw blue with driver module
    i have in laser positive negative ( power) and fan power , and TTL
    so ttl must be connected where? to pb4?

    b cz its another laser module
    and one thing i have to connect the laser module to cnc shield no arduino pin , so what pin i have to connect , please help
    almost finish the project , ur amazing

    1. Hello, and thank you. The spindle enable pin depends on your grbl version, or how you set in the grbl code. For 0.9 it's usually on PB4. Take a look here: https://github.com/grbl/grbl/wiki/Connecting-Grbl

  13. This comment has been removed by the author.

  14. Hello, your scheme unless the driver is wrong it could again be traced ?? I think it should look like this http://imgur.com/a/hvTeI

    1. Hello, you are right, i did'n notice ADJ and OUT, swap that and made that error. Check it out now. I should be right.

  15. Hello again sir . I received laser 500mw abd driver . Bu the problem this driver ttl on 0v on and on 5v off . How to reverse this please any help or solution ? Please check the laser and description in below link
    500mw 405NM focusing blue purple laser module engraving,with TTL control laser tube diode protective googles
    (from AliExpress Android)

    1. Hello, you can simply use an NPN to reverse the signal logic, something like this should work: https://i.stack.imgur.com/KntFP.jpg

  16. Replies
    1. Hello, yes you can use a relay. But to me it's simpler with a NPN, you just have to drive a few mA, a 2n3904 or a 2n2222 would do the job, an NPN it's smaller, and also they swith faster than a relay, and have much longer life, consider that a typical realay can switch almost 100k times. Take a look here: https://www.youtube.com/watch?v=hYN8C769k8A