Introduction: Mini CNC Machine Arduino Based & Adafruit Driver Motor L293D V1 & 2*Mini Stepper CD/DVD Player #1

In this project I will show you how to easily build your own low-cost Arduino Mini CNC Plotter!

For X and Y axis we will use stepper motors and rails from two dvd/cd roms! Printing area will be max 4x4cm.

Step 1: The Video in Youtube :

Step 2: Parts

For this project you will need:

- Part list for beginners:

- Arduino uno ( or Mega ) Breadboard

- Shield driver motor L293D adafruit v1

- Mini Servo motor 9g

- 2x DVD/CD Drives

Librairy For Adafruit Shield Driver Motors v1 :

Step 3: X Y Axe

In first image above you will see the Y axis of our CNC machine. Attach it on your surface, in this part you will need some screws and nuts.

In second image you will see the X and Y axis. The X axis is attached to two plastic parts that I took from remaining 'garbage' stuff. I cut it to fit the construction. This is an easy procedure. Just make sure to put the Y axis straight to CNC base and the X axis vertically in this (90 degrees)

Step 4: The Z Axis

That's the most difficult part of our construction.

You will need something to attach it on X axis, a flat surface. On that surface you will attach the servo motor (Z axis) and the pen base. Pen (or pencil) must be able to move up and down with the help of servo motor. Watch the above image to understand what you need to do to duild Z axis. Tip! Use your imagination ;)

Step 5: the Circuit

Step 6: Uploading the CNC Code

Here is the main CNC code embedded using codebender!

In this part you will see your pen goes up. If don't, change penUp and penDown variables that controlling the servo motor. Press the "Run on Arduino" button and program your board from your browser!

Step 7: Make Your Own Gcode Files

To make gcode files that are compatible with this cnc machine you have to use the Inkscape.

Inkscape is professional quality vector graphics software which runs on Windows, Mac OS X and Linux. It is used by design professionals and hobbyists worldwide, for creating a wide variety of graphics such as illustrations, icons, logos, diagrams, maps and web graphics. Inkscape uses the W3C open standard SVG (Scalable Vector Graphics) as its native format, and is free and open-source software. Download and install Inkscape from : https://inkscape.org/en/download/windows/

(Important: download 0.48.5 version)

Now you need to install an Add-on that enables the export images to gcode files. This add on can be found here with installation notes.

https://github.com/martymcguire/inkscape-unicorn

Setup Inkscape for first use
Open the Inkscape, go to File menu and click "Document Properties". See the 1st image above and make the changes, make sure to change first to "cm". Now close this window. We will use the area within 4 to 8 cm. See the 2nd image above. How to print texts Put text, change font to Times New Roman and size to 22. Now click on cursor icon and center the text like the 3rd image above. Select Path from menu and "Object to Path". How to print images This is more difficult than texts. Images must have a transparent background. Drag and drop the arduino logo image (download it from files) in Inkscape. Click ok to the next window. Now you have to re-size the image to fit our printing area, see the 4th image above. Click Path from menu and "Trace Bitmap". Make changes as the 5th image above. Click ok and close the window. Now, move the gray scale image, and delete the color one behind it. Move the grey image to the correct place again and click from Path menu "Object to path". The 6th image above show how to delete image outline. Export as gcode Final, go to file menu, click save as and select .gcode. Click ok on next window. That's it! Ready to go! Use the gctrl.pde app to print the gcode file on your new Arduino CNC Plotter! I will make a video on next days about this procedure because it's little complicated. It took me a lot of time to understand how it's working...

Step 8: The GCTRL Program

Now we are ready to print our first image! To do this we will use the gctrl . This program sends 'gcode' images to the cnc plotter.

What is gcode? Gcode is a file with X,Y and Z coordinates. Header of this file is set to: M300 S30.00 (Servo down) G1 X10.00 Y10.00 F2500.00 G1 X20.00 Y10.00 F2500.00 M300 S50.00 (Servo up)

Click the "play" icon/button to start the program.

Download gctrl for Windows :

https://www.instructables.com/files/orig/F69/K945/I...

Click First time to " p " to select Port number for Arduino

and click to " g " to select Gcode file ...

Step 9: Examples Gcode File

Comments

author
injobho made it! (author)2017-03-30

I made a bigger version using your code to make a large cnc router
(40cmx30cm) and it is nicely printing small images that you shared.
Unfortunately it is printing images within a 5cm x5cm zone only. I tried
increasing the Xmax, Ymax beyond 50 but anything beyond 5 cm in printed
at a different place. your cd rom lead screw has high pitch but my lead
screw has 1.25 mm pitch. After calibration, I ended up at
StepsPerMillimeterY=1250, StepsPerMillimeterX=650

I also checked
the stepper motor example in adafruit library and it also draws line of 5
cm only (motor.step(4000, FORWARD, MICROSTEP); I tried with number
larger than 4000. Is it a limitation of the hardware? Can you please
help? I am a mechanical engineer but new to arduinio.

unnamed.jpg
author
DebojitK (author)injobho2017-08-12

Hi I am impressed by your design. Would you please share some more design details?

Like Servo details, lead screw detail, stepper driver (if not L293d based) etc.

Lead screws are very costly. Is it possible to use a long bolt and nut to replace proper lead screw?

author
injobho made it! (author)injobho2017-04-01

Fixed the problem. It was happening because of the low pitch of the screw the value of x1 was exceeding the range of int. I Just changed it to long and its solved the problem but at a cost of higher memory.

Capture.JPG
author
Yassineb12 (author)injobho2017-07-22

thanks for the solution !

author
DebojitK made it! (author)2017-08-12

I had to change the motor mode to INTERLEAVE instead of MICROSTEP.

Capture.PNG
author
DanielC807 made it! (author)2017-08-04

please help me

WhatsApp Image 2017-08-04 at 16.45.42.jpegWhatsApp Image 2017-08-04 at 16.45.45.jpeg
author
DebojitK (author)DanielC8072017-08-12

Are you still struggling to get a better drawing?

If so here are some things you can try out as I explain below.

If you are using L293d shield, the major problem can be with microstepping. If you see the Afmotor library documentation they clearly mention that microstepping looses torque severely and any sort of retracting force can stop the movement while the motor runs in microstepping mode. Even when the pen touches the sheet it can generate that friction that can create the problem. I changed the code a little bit to use INTERLEAVE mode instead of MICROSTEP.

Interleave is similar to microstep but with lesser resolution. I found with interleaving the motor traverses 16 mm for 200 steps. So steps per mm = 200/16=12.5. Torque is quite good. I also adjusted the speed of drawing and now it gives very neat drawings.

The setting that worked for me is as below:

const int stepsPerRevolution = 100;

float StepsPerMillimeterX = 12.5;
float StepsPerMillimeterY = 12.5;


myStepperX.setSpeed(50);
myStepperY.setSpeed(50);

snippet from drawline() method

if (dx > dy) {
for (i=0; i<dx; ++i) {
myStepperX.step(1,sx,STEP);
over+=dy;
if (over>=dx) {
over-=dx;
myStepperY.step(1,sy,STEP);
}
delay(StepDelay);
}
}
else {
for (i=0; i<dy; ++i) {
myStepperY.step(1,sy,STEP);
over+=dx;
if (over>=dy) {
over-=dy;
myStepperX.step(1,sx,STEP);
}
delay(StepDelay);
}
}

author
DanielC807 (author)2017-08-04

Hello guys, now i'm making cnc, i've followed all the steps that already exist, but the output of the resulting image is very messy and i am confused the fact is where is the error?

Please help

author
Yassineb12 made it! (author)2017-07-19

baraka allah fik ! finally i've managed to reach a good output

i love to share my solution to my problem which was a distored image :

1/ not all the axe taken frm the drives are good ! i've tried 4 axel to find a good one my Y axel

2/ there was step skipping so the solution was in CNC_Code.INO i've changed :

this

float StepInc = 1;

int StepDelay = 0;

int LineDelay =0;

int penDelay = 50;

to this :

float StepInc = 1;

int StepDelay = 1;

int LineDelay =0;

int penDelay = 20;

salam

1/

DSC_0266[1].JPGDSC_0265[1].JPG
author
Eduardo A.D (author)2017-07-03

Hi, very, very good project, I see that many people have been successful.

I have uploaded Test_X_Axis_CNC_Plotter and Y, and my engines have good movement.

I have a problem with gctrl.pde and gctrl.exe, but I do not know why. My engines have no movement with gctrl. Select the serial port (OK), use the arrows and no movement, load a gcode image with (G) and no movement. I do not know where the problem is.

You help me? Thank you

My beta-CNC without Arduino, only router with OpenWRT and L293 driver. Does not interpret GCODE yet:

https://www.youtube.com/watch?v=16uzCy-xsO0

author
LourivalI (author)2017-07-01

How do I fill out the drawing? I can only make outlines.

author
Juan ManuelK (author)2017-06-13

hello, my problem i:

Arduino:1.6.11 (Windows 10), Tarjeta:"Arduino/Genuino Uno"

C:\Users\Kriivo\AppData\Local\Temp\ccdbL8gd.ltrans0.ltrans.o: In function `loop':

ccdbL8gd.ltrans0.o:(.text+0xcb4): undefined reference to `AF_Stepper::onestep(unsigned char, unsigned char)'

ccdbL8gd.ltrans0.o:(.text+0xce2): undefined reference to `AF_Stepper::onestep(unsigned char, unsigned char)'

ccdbL8gd.ltrans0.o:(.text+0xd28): undefined reference to `AF_Stepper::onestep(unsigned char, unsigned char)'

ccdbL8gd.ltrans0.o:(.text+0xd56): undefined reference to `AF_Stepper::onestep(unsigned char, unsigned char)'

C:\Users\Kriivo\AppData\Local\Temp\ccdbL8gd.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_FKZY7W9IN4TTHPJ.ino.cpp.o.1877':

ccdbL8gd.ltrans0.o:(.text.startup+0xc4): undefined reference to `AF_Stepper::AF_Stepper(unsigned int, unsigned char)'

ccdbL8gd.ltrans0.o:(.text.startup+0xd2): undefined reference to `AF_Stepper::AF_Stepper(unsigned int, unsigned char)'

C:\Users\Kriivo\AppData\Local\Temp\ccdbL8gd.ltrans0.ltrans.o: In function `main':

ccdbL8gd.ltrans0.o:(.text.startup+0x2f6): undefined reference to `AF_Stepper::setSpeed(unsigned int)'

ccdbL8gd.ltrans0.o:(.text.startup+0x302): undefined reference to `AF_Stepper::setSpeed(unsigned int)'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compilación en tarjeta Arduino/Genuino Uno.

Este reporte podría tener más información con
"Mostrar salida detallada durante la compilación"
opción habilitada en Archivo -> Preferencias.

author
Pardeepsaini (author)2017-06-13

hello sir my cnc not drow properly it can drow only a square it's urjent plz sir

author
Pardeepsaini (author)2017-06-13

my cnc not drow properly it can drow only square

author
Namangupta (author)2016-12-18

Hello sir...Thank u so much for this post...I have been working on this project from last one week..I have followed each and every step mentioned by u.. I have used Ur code and even followed Ur circuit diagram.. but still I m not getting a desired output... I mean I'm getting a distorted output... I think I'm facing the problem in wiring.. I'm sending u one picture with all the wiring configuration I have used.. if the wiring is not correct plz correct it by commenting the correct combination (like A1 A2 B2 B1 )... It's urgent sir plz help me out

CYMERA_20161218_162758.jpg
author
SarojR (author)Namangupta2017-02-17

have you fixed it ? i m having same issue

author
vsk21 made it! (author)SarojR2017-05-01

hi O'Donovan I am also having same issue

My output is distorted and all jumbled up

So i request you .Please help sir its urgent

IBALL - WIN_20170501_163744.JPGIBALL - WIN_20170501_163730.JPGIBALL - WIN_20170501_163712.JPGIBALL - WIN_20170501_163704.JPG
author
Varadgh (author)Namangupta2017-04-26

I am also having same issue
Please help anyone

author
O'DonovanM (author)Namangupta2017-02-05

Hi

In step 5 you're told to connect y Axe to M3 M4. This did not work for me, I connected my Y Axe to M1 M2.

If printed text is back to front switch a1a2 b1 b2 in reverse order eg a1 becomes b2, a2 becomes b1 and so on.

If only one axe moves and the other stays still then you may have a wire lose on the axe that is not moving or you need to switch only one pair of wires 1 and 2 to become 2 and 1.

If your image is printing in what looks like one corner then your start point in software may be incorrect.

My software settings are different for some images Inkskape images start in the centre:

Arduino settings (1) X -18 +18 - Y-18 +18 start plotting in the centre of page. Arduino settings (2) max X36 max Y36 starts closest to me to the right.

I hope this helps in some way.

It took me a while to figure this out.

K

author
O'DonovanM made it! (author)O'DonovanM2017-02-25

X Y Min Max

Capture.JPG
author
SarojR (author)O'DonovanM2017-02-17

hello , i am having same issue and output is distorted . how to change the starting point in software

author
O'DonovanM (author)SarojR2017-02-18

Hi SarojR

The starting point is where you start your pen or start plotting. Put the pen down on the paper and outline the edges of the paper. this is the Min max that your plotter can do, you will end up with a square.

Draw a line from one corner to the other to form a cross in the square already made, the center of this cross is where Inkskape starts the plotting.

In the program you download to the Arduino change the values for the X and Y from 36 to read -18 +18 and upload to the Arduino again.

K

author
renem67 made it! (author)2017-04-19

Thanks fro your good work. I made it but my cnc is based in an old printer and scanner. I print the test images directly on the glass of the scanner, the white paper below is just to highlight the drawing. I searched for a cnc with the adafruit stepper driver V1, so I found just what I needed. Thanks again.

IMG_20170419_172936.jpg
author
itavaci (author)2017-04-14

Is gctrl compatible with Windows 10, I did run it a couple of times, cannot do any selections, pressing "p" or "g" button does not work. Your help is much appreciated.

author
nepenth0 (author)2017-03-14

all im getting from the z- axis servo is jitters, any help?

author
yusufgktsster2. (author)2017-03-14

I have heat problem. Both of motors and l293d are overheated in 30-40 second. can anyone give me some advice.

author
insructAbdo made it! (author)2017-03-08

thank youu of All :)

that other instructables to how make this project step by step :

https://www.instructables.com/id/How-to-Make-Mini-CNC-Router-Drawing-by-Arduino-and/

vlcsnap-2017-02-28-01h11m37s56.png
author
kentb7 (author)2017-02-26

Super nice project !

My project its up and running.

Now i have som ? about it.

Can`i change the motorer on X and Y from DVD step motorer to eks. 28BYJ-48 5 volt.

author
O'DonovanM made it! (author)2017-02-05

Fantastic, Thanks a million for this.

I have it up and running.

You're a STAR.

Snap_8.jpgSnap_1.jpgSnap_2.jpgSnap_3.jpgSnap_4.jpgSnap_5.jpgSnap_6.jpgSnap_7.jpg
author
SarojR (author)O'DonovanM2017-02-17

can you send me your circuit connection between stepper and shield .. every thing is perfect but my output is distorted

author
Sdyasin (author)2017-02-13

I've made it but it isn't working after uploading the code please any one help me

author
Anubhav8651 (author)2016-12-19

Hello, I Hav Made It But I Hav A Major Issue With Power Supply. Ones I Hav Supplied 19v 1.5Amp Then 1 Cap. Of 16v 100uf Blew Up I Hav Repaired It Will Any One Will Suggest Me Wat To Supply Power To L293D Motor Sheild

author
O'DonovanM (author)Anubhav86512017-02-05

Remove the jumper from the motor driver board L293D and supply 5V to the board this worked for me

author
JHON JAIMEL (author)2016-05-31

hola a todos; eh estado trabajando en este proyecto y podrian modificar ciertas cosa del codigo para mejorar el rendimiento de nuestro mini cnc y evitar daños en nuestra shield motor. ademas reducir el ruido de los motores y el calor que esto producen al trabajar.

entonces la parte del codigo que hay que modificar seria esta:

void setup() { // Setup

Serial.begin( 9600 );

TCCR2B = TCCR2B & B11111000 | B00000001;

TCCR0B = TCCR0B & B11111000 | B00000001;

penServo.attach(penServoPin);

penServo.write(penZUp);

delay(100);

// Decrease if necessary

myStepperX.setSpeed(500);

myStepperY.setSpeed(500);

}

que sea de su agrado!!!!!

author
Mitho66 (author)JHON JAIMEL2017-01-31

great thanks

author
saif2580 (author)2016-08-03

What is the main code to upload on arduino?
Plz tell me any one,...

author
Mitho66 (author)saif25802017-01-31

CNC_Code.INO

author
MirzaK5 (author)2017-01-01

If we change pcb drill with pen so it will work or not

author
MukaddemA (author)2016-12-09

hello. I made this one and its working properly. thanks for sharing. Now I am trying to increase the size of plot. here it plots only 4cm/4cm. I want to increase it by 20 cm by 20 cm . i have all the mechanical set up but when i upload the gcode it plots only the 4cm by 4cm area what can i do? please help.

author
Minh Vu Nguyen (author)2016-07-04

Hi insructAbdo, can you show me how to decrease speed of X and Y axis, i change the number in the line "myStepperX.setSpeed ()" from 500 to 100 but nothing happen, it still run the same speed.

author
JaimeJ16 (author)Minh Vu Nguyen2016-10-10

hola vu nguyen minh , como te fue con el problema ? lo solucionaste? me pasa lo mismo a mi y no se que hacer para poder bajar la velocidad del eje x e y :( ....

saludos

author
bwantha made it! (author)2016-09-20

i make it bro but no working . bro i dont't know adafruit motor shild libary and accelstepe master install from arduino bord uplode now please help me how to install this driver arduino bord ?

temp_825477135.jpgtemp_1240492110.jpgtemp_746709017.jpgtemp_1376865196.jpgtemp_-1302042447.jpgtemp_68015277.jpgtemp_-1849178799.jpg
author
مدهشان (author)2016-05-21

very good

author
John Tan峻 (author)2016-05-10

If i am using the adafruit motor shield V2, can I use change the library without changing others code?

author
bgsdika (author)2016-05-07

hey, it's a great project. I've made this yesterday, can you tell me where is the zero point located (0,0)?

author
ToniV13 (author)2016-04-30

great

author
iqbal12392 (author)2016-04-28

wow, great build. can i use a salvage part from printer instead a dvd drive (i have 3 x A3 canon printer (ix6560,ix5000,ix4000))???? can you explain to me how it works??? thank you. you ROCKs!!!

author
Chipmunk03 (author)2016-04-27

I made one myself back in 2014 based on the Laserengraver. I discovered that there are microswitches on the board where the stepper for the disk spindle resides. There is a flat cable coming from it. I use these the calibrate and home the pen before and after printing/plotting.

I adjusted the code in Inkscape to use it. I am not finished, yet, but here is a part of the code.

It is done on my Mac. On Linux or windows you have to find the right path to the extensions folder.

'/Applications/Inkscape/Contents/Resources/extentions/share/Inkscape/unicorn/context.py'

in self.reamble:

self.preamble = [

"(Scribbled version of %s @ %.2f)" % (self.file, self.xy_feedrate),

"( %s )" % " ".join(sys.argv),

"G21 (metric ftw)",

"G28 X%.2f Y%.2f Z%.2f (Home X Y Z)" % (self.x_home, self.y_home, self.z_height),

"G90 (absolute mode)",

"G92 X%.2f Y%.2f Z%.2f (you are here)" % (self.x_home, self.y_home, self.z_height),

""

]

and n in self.postscript:

self.postscript = [

"",

"(end of print job)",

"M300 S%0.2F (pen up)" % self.pen_up_angle,

"G4 P%d (wait %dms)" % (self.stop_delay, self.stop_delay),

"M300 S255 (turn off servo)",

"G1 X0 Y0 F%0.2F" % self.xy_feedrate,

"G1 Z%0.2F F%0.2F (go up to finished level)" % (self.finished_height, self.z_feedrate),

"G1 X%0.2F Y%0.2F F%0.2F (go home)" % (self.x_home, self.y_home, self.xy_feedrate),

"G28 X%.2f Y%.2f Z%.2f (Home X Y Z)" % (self.x_home, self.y_home, self.z_height),

"M18 (drives off)",

]

Now I am working on the Mini_CNC_Arduino_Plotter.ino to read out the state of the switches. If they are open, the motors have to move until the switches are closed. Then home must be set (X=0.00, Y=0.00). This comes from G28 X Y Z.

I've tested it with this switch_test.no:

//------------------------------------------------------------------------------

// Draw robot - switch test

// dan@marginallycelver.com 2012 may 06

//------------------------------------------------------------------------------

// Copyright at end of file.

// please see http://www.github.com/MarginallyClever/Makelangel... for more information.

//------------------------------------------------------------------------------

// CONSTANTS

//------------------------------------------------------------------------------

#define CUTOFF (512)

//------------------------------------------------------------------------------

// VARIABLES

//------------------------------------------------------------------------------

char a,b,a1,b1;

long c=0;

//------------------------------------------------------------------------------

// METHODS

//------------------------------------------------------------------------------

void readSwitches(char a1, char b1) {

// get the current switch state

a1=analogRead(3) < CUTOFF;

b1=analogRead(5) < CUTOFF;

}

//------------------------------------------------------------------------------

// print the state of each button

void ps() {

Serial.print(c++);

Serial.print("\t");

Serial.print(a==0?"Off":"On");

Serial.print("\t");

Serial.println(b==0?"Off":"On");

}

//------------------------------------------------------------------------------

void setup() {

Serial.begin(9600);

// Serial.begin(57600);

digitalWrite(A0,HIGH);

digitalWrite(A1,HIGH);

digitalWrite(A2,HIGH);

digitalWrite(A3,HIGH);

digitalWrite(A4,HIGH);

digitalWrite(A5,HIGH);

Serial.print("T");

Serial.print("\t");

Serial.print("L");

Serial.print("\t");

Serial.println("R");

a=analogRead(3) < CUTOFF;

b=analogRead(5) < CUTOFF;

ps();

}

//------------------------------------------------------------------------------

void loop() {

a1=analogRead(3) < CUTOFF;

b1=analogRead(5) < CUTOFF;

readSwitches(a1,b1);

if(a1!=a){

a=a1;

ps();

}

if(b1!=b) {

b=b1;

ps();

}

delay(2);

}

/**

* This file is part of DrawbotGUI.

*

* DrawbotGUI is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* DrawbotGUI is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with Foobar. If not, see <http://www.gnu.org/licenses/>.

*/

Output:

T L R

0 Off Off

1 On Off

2 On On

author
makerblogAT (author)2016-04-27

Thanks for this Instructable! Finally I can point makerblog.at-Users asking for an english version of my tutorial to this page :)

author
xsdata (author)2016-04-22

very nice project and great job, i wish some people would see the learning that you have made by building it. to some a printer is the answer, live must be very easy, to me your project ROCKS!

About This Instructable

99,598views

949favorites

License:

Bio: My name is Abderrahim Aabida , 23 years , living in Morocco - Safi , holds a diploma in basic physics and electronics at the Faculty of Sciences in ... More »
More by insructAbdo:How to Make Mini CNC Router Drawing by Arduino and Shield L293DDrawing instructables robot by Mini CNC - Arduino - L293D ShieldMini CNC machine Arduino Based & Adafruit Driver Motor L293D v1 & 2*Mini Stepper CD/DVD player #1
Add instructable to: