Introduction: How to Wire an Arduino-based 3-axis CNC Machine



I've seen a number of tutorials about how to build the platform for a 3-axis CNC milling machine.  I have not seen anyone tackle the tricky subject of the electronics.

Here now is my attempt to do so.

Step 1: Parts

You'll need:

- an arduino. I chose duemilanova. (depends on the board you get)
- 3 stepper motors.  I chose NEMA 17s . ($15/ea)
- 3 EasyDrivers from Sparkfun . ($15/ea)
- some Cat5 ($2?)
- a 12V power supply for the steppers ($5?)
- a soldering iron
- some electrical tape
- an optional female plug is not a bad idea (<$1)

TIP: Don't get a 6ft or 10ft Cat5 cable.  Buy your cat5 by the foot from any computer or electronics store. That stuff has one wire inside instead of lots of little fibers.  Little fibers are a huge pain to work with. 

Step 2: Wire the Stepper Motor to the EasyDriver

Now we'll wire up each of the EasyDrivers.

Remove some of the interior wire from the Cat5 and strip the ends.  For each servo you will need two normal pairs of white/colored and one oddball of a white and two colored.  In all, you'll have to strip 14 ends.

PCB soldering is easy, once you get used to it.  There are many other tutorials that cover the subjct.  Follow the image as indicated.  Your color combinations for the servo may be different.  I had to google for a long time to find this page with the color codes for my model.


TIP: "Do NOT connect or disconnect a motor while the driver is energized. This will cause permanent damage."  -- Sparkfun

Next we'll wire the power sources and the arduino.

Step 3: Soldering and Wiring.

I've done this all in one step, but feel free to wire each EasyDriver one at a time, check that it works, and then unplug it from the power and do the next one.

All 3 GND wires from the EasyDrivers are soldered to a single line, which goes to GND on the arduino.

All the positive leads from the stepper power are soldered to a single line.

All the negative leads from the stepper power are soldered to a single line.

TIP: Remember to put the plug cover on the wire BEFORE you solder everything together. Then slide the cover down and over the soldering.

TIP: Don't forget to have everything disconnected while you solder!

Solder the positive and female lines to the female plug.

Double check you didn't wire the board power to the stepper power.  That would be bad.

Do you have a multimeter?  This would be a good time to check your connections.

Plug in the power.  The +5v light in the corner of each board should light up.

Now the wiring is done, time to test it with some code.
 

Step 4: Testing One Stepper

UPDATE: I've been playing with my steppers and I wrote this little piece of code to play with just a single stepper.
Change the DIR/STEP pins as you see fit.  If you put the stepper on a hollow flat surface like a desk top it will sound like a tiny formula 1 race car.

// for duemilanove atmega328 arduino board + easydriver stepper controller
// dan@marginallyclever.com 2010-06-15
#define DIR1_PIN (12)
#define STEP1_PIN (13)
#define DELAY (1600/10)
#define BAUD (9600)

void setup() {
Serial.begin(BAUD);
pinMode(DIR1_PIN,OUTPUT);
pinMode(STEP1_PIN,OUTPUT);
}


void loop() {
int i,j=DELAY;

digitalWrite(DIR1_PIN, LOW); // Set the direction.
delayMicroseconds(DELAY);
Serial.println(">>");

for (i = 0; i<4000; i++) // Iterate for 4000 microsteps.
{
digitalWrite(STEP1_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP1_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
delayMicroseconds(j); // This delay time is close to top speed for this
j+=1;
} // particular motor. Any faster the motor stalls.

digitalWrite(DIR1_PIN, HIGH); // Change direction.
delayMicroseconds(DELAY);
Serial.println("<<");

for (i = 0; i<4000; i++) // Iterate for 4000 microsteps
{
digitalWrite(STEP1_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP1_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
delayMicroseconds(j); // This delay time is close to top speed for this
j-=1;
} // particular motor. Any faster the motor stalls.
}

Step 5: Sample Arduino Code

// for duemilanove atmega328 arduino board + easydriver stepper controller
// dan@marginallyclever.com 2010-06-15
#define DIR1_PIN 4
#define STEP1_PIN 5
#define DIR2_PIN 6
#define STEP2_PIN 7
#define DIR3_PIN 8
#define STEP3_PIN 9
#define DELAY 150


void setup() {
Serial.begin(9600);
pinMode(DIR1_PIN,OUTPUT);
pinMode(STEP1_PIN,OUTPUT);
pinMode(DIR2_PIN,OUTPUT);
pinMode(STEP2_PIN,OUTPUT);
pinMode(DIR3_PIN,OUTPUT);
pinMode(STEP3_PIN,OUTPUT);
}


void loop() {
int i;

digitalWrite(DIR1_PIN, LOW); // Set the direction.
digitalWrite(DIR2_PIN, LOW); // Set the direction.
digitalWrite(DIR3_PIN, LOW); // Set the direction.
delay(DELAY);
Serial.println(">>");

for (i = 0; i<6800; i++) // Iterate for 4000 microsteps.
{
digitalWrite(STEP1_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP1_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
if((i%2)==0) {
digitalWrite(STEP2_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP2_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
}
if((i%4)==0) {
digitalWrite(STEP3_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP3_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
}
delayMicroseconds(DELAY); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.

digitalWrite(DIR1_PIN, HIGH); // Change direction.
digitalWrite(DIR2_PIN, HIGH); // Change direction.
digitalWrite(DIR3_PIN, HIGH); // Change direction.
delay(DELAY);
Serial.println("<<");

for (i = 0; i<6800; i++) // Iterate for 4000 microsteps
{
digitalWrite(STEP1_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP1_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
if((i%2)==0) {
digitalWrite(STEP2_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP2_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
}
if((i%4)==0) {
digitalWrite(STEP3_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP3_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
}
delayMicroseconds(DELAY); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
}

Step 6: In Conclusion

If everything worked right, you should have three steppers each moving at different speeds back and forth.  There should be a light on each EasyDriver showing that it has power.  If you have a light and no movement, You might not have a good connection to your arduino.

So what next?
Now that you have three motors working through the arduino you can use the serial interface to tell the arduino what you want the steppers to do.  By changing the different motors in the right pattern you can interpret G-CODE and start cutting patterns.  The biggest choice you face is what to cut!

Thanks for reading!
Dan

Comments

author
VishalC37 made it!(author)2017-05-05

What if I want to use 2 steppers for y axis

author
techknowdroid made it!(author)2017-02-18

This is a Great Instructable Sir! Your explanation on how to wire the steppers and the easydriver boards to the arduino, is very nice.

I too have made a small CNC
machine using easy drivers and your guide really helped me on the wiring part.

Here is the link to my cnc machine:-

https://www.instructables.com/id/CNC-Arduino-GRBL-...

Thanks a lot for giving your time.

author
DerekJ25 made it!(author)2017-01-22

OK, got the 3 steppers doing different speeds using TB6560 drivers (only had to adjust the delay to make the code work), no idea what I need to do next to get gcode talking to the arduino. I can make the gcode but no idea how it is sent to the arduino.

Where do I look now?
Thanks ever so much.

author
KunalA18 made it!(author)2016-09-25

i want to use the speed sensor to print accordingly to the moving paper. means to use the speed value and print on x axis at a time.

author
Revanchist made it!(author)2016-05-30

awesome info thanks! I have a question I would really like you to answer if possible... I'm trying to use AutoDrivers instead of EasyDrivers to drive my NEMA 23 Stepper motors.... I'm trying to use GRBL as you've clearly suggested, but I'm not sure how to make GRBL recognize the AutoDrivers... The drivers are these https://www.sparkfun.com/products/11611.... I had those drivers already in my possession, and would rather use them than spending another 80 bucks for a GRBLShield...

Any help is greatly appreciated!

author
octebra made it!(author)2016-04-14

This a great instructable with lots of ideas, if you could please post a schematic of the wiring I would be gratefull.

author
jmsiefer made it!(author)2013-11-20

I'm just getting into Arduino, so I do apologize for the question, however is it possible to use an Arduino Uno for this project?

author
aggrav8d made it!(author)2013-12-20

Yes.

author
geniusdan05 made it!(author)2016-01-17

Hi sir!....can u plz tell me how do i use the l298n instead of the easy driver?
Plz give me a detailed guide....its my computer project and i have to finish it....thanks....dan

author
jatinbatra made it!(author)2013-12-30

Heyy, It's not possible for me to get 4 easy drivers to use it with 3D printer , rather I would like to use my own drivers, I 'm thinking to use L293D or simple H bridges to run my Bipolar stepper ( 4 wires) , how can I make it run , I have seen number of programs and software like grbl for easy drivers ,Adafruit motor shield V1 and V2 , grbl shield but not with H-bridges , so the issue is pretty common for many people as well.
I tried two out of three motors , uploaded grbl to Arduino and sent Gcodes from Universal Gcode sender , only one of my motor seem to work (however very slowly nad an irritating "buzzzzzzzz" like noise is coming out of it). I tried some variations with steps for different axis and I could see it move with 10 steps/mm.
I don't know what to do.
Can't you make easy drivers or motor shield or grbl shield on your own ?
Also I need a 4 axis driver as I would be using it for my 3d printer.
Thanks, any help would be appreciated.

author
AMTP1 made it!(author)2015-09-05

How did you get the universal Gcode sender to work? I went to gethub and downloaded it. I clicked on the file that had Jar.Jar in it and nothing happened and then clicked on the sw file and nothing happened! What do you do with the github downloaded file to make the sender come up? What are the steps? I am using windows 7 64.

Thanks

author
Richley made it!(author)2014-02-04

Will this work with Arduino UNO or will it only work with Arduino Duemilanova ?

Is it possible to connect 3 stepper drivers with ONE EasyDriver ? ( i doubt it's possible, but wants to know about the possibility for that )

author
jongscx made it!(author)2014-02-08

Yes, this will work with all flavors of Arduino.

Short answer, Yes you can connect all 3 to the same easydriver but they will all turn the same.

Long Answer: Stepper motors, unlike "regular" DC motors, have 2 sets of coils inside. To turn a stepper, you need to alternately turn these coils on and off, which is what the Easy-driver does. So, if you want to control 3 stepper motors... you need 3 drivers.

author
PHYSICART made it!(author)2015-12-02

I have an Uno too, I'm beginner totally. Output on Uno 5, 6 and 9 are ~ PWM, is that the same output that you sketched ?


http://2.bp.blogspot.com/-M9WMQFNfXEQ/VOgnMnz18sI/...

author
Richley made it!(author)2014-03-20

another question here, can I connect one Raspberry Pi, directly to 3 Stepper Motor, and control all 3 of them to turn different direction/speed ?
or must I connect a Raspberry Pi -> 3 EasyDriver -> 3 Stepper Motor

author
AliB70 made it!(author)2015-11-30

Nice one my friend! Let me pick your brain up. Using the above and some other tutorials around the web, I put together 3 easy drivers controlling 3 stepper motors, used an Arduino Uno board with external power supply. Used some code available online / above. So far so good. My question is what's the next step. How to get this setup work with the CNC or 3d Printer in the production environment? How the G-Code file be read by this setup? Actually I'm after a full work flow for using easy driver with arduino uno. Firmware > XLoader > ????? Please help. Thanks

author
akihiro94 made it!(author)2015-08-25

I wanna ask you...i made the seem with you...but i got trouble....question : how much current did you need to supply the shield.... voltage :12voltdc and the current to supply 3 motors is???

author
cliffyd made it!(author)2015-11-21

you need to check the specs for your steppers and see what V they run. I used a 12v wall wart and spliced 3 wires of the 1 pos/neg. and ran them to my easy drivers. worked for me. they are capable of 30v max if you have large steppers prob around 24v. run a second walwart to your driver board they are anywhere from 5-15v chek specks and run a line to that.

author
jcobern made it!(author)2015-11-08

trying to make this code run 6 steppers, will this code do that?

author
cliffyd made it!(author)2015-11-21

No the code has to be tweek'd for 6 to run. unless you spliced 2 motor wires together to run off the same pins might work but they would be limited to doing the exact same thing.

author
cliffyd made it!(author)2015-11-21

I paid $2.25 for my easy drivers on Ebay. exact replica's anyway!

author
Scottspence442 made it!(author)2015-06-14

Soo could you plug this into a program like Mach3 or linux cnc?

meaning, if you have your arduino interpret Gcode can you hook this up to a program like the above?

author
AmbujB made it!(author)2015-03-27

I have ordered grbl cnc shield v3 from ebay from this link http://www.ebay.in/itm/TDP004-ARDUINO-CNC-SHIELD-V...

now when i try to connect this shield it requires power before i mount it onto my arduino uno. The issue is that before i could use the setup i have to detach the shield from uno and power it first and then mount it and connect it to pc. is there any solution to this?

do reply asap

author
nreed4 made it!(author)2013-02-07

Could you add a fourth stepper motor to pins 1 and 2? Could you also control a heatbed and an extruder (nichrome wire), because I am trying to build a 3d printer. Also how do you control the z-axis with only one motor.

author
LostboyTNT made it!(author)2015-02-26

Pins 1 and 2 are required for data input, you could only use them IF you set it up to just run the program you've already loaded, that didn't require any additional input. (in other words, no)
Running it with an uno, you really don't have enough output pins to control anything additional. If you built it with a mega, or something else, then you'd have additional data pins for controlling other things, but honestly it sounds like you should be using a ramp board anyways.
Z axis only requires 1 motor. I've seen some designs for extruder based printers that use 2 Z axis motors, but it's no more required than 2 motors on the X axis.

author
jmsiefer made it!(author)2014-03-31

If you could answer a quick question for me, I would sincerely appreciate the help.

I'm making a homemade laser-cutter, and the problem I'm facing at the moment is how to trigger the laser ON instead of driving a stepper motor (the motor for the Z-Axis). Now, in your photo for Step 2: "Wired the Stepper Motor To the EasyDriver" you show "5 Out and Ground." Are these pins something I can control off and on? I'm using GRBL on the Arduino Uno, so I'm not sure exactly how I would write the GCode to do this.

Thank you so much!!!

author
hazem.Monther made it!(author)2015-02-05

Hi jmsiefer,

What you need is a relay module that will control the trigger of the laser.

author
nicken83 made it!(author)2014-08-17

I'm building my own cnc router at this moment, using scrap materials. The constructrion of the hardware is allmost finished, en looks quite good! Time to start the programming en controlling of the steppermotors. I surely will use this handy tutorial. But what seems most unclear to me now is how i convert a drawing to g-code, and how do i get the g-code to the arduino?

Any help with this would be very appreciated!

IMG_20140807_170027.jpg
author
Brutus+Ultimatum made it!(author)2014-11-02

Look up GRBL, it's a program you upload to the arduino to convert g-code to the motor drivers.

author
diyman made it!(author)2014-05-29

Nice project!! I had a quick question. I was looking into getting the easy driver and 3 steppers for my cnc build but i'm not sure if my steppers will work with the easy drivers. all the steppers i have looked at so far are rated for 1.3A or so. the easy driver is only rated for 750mA. Will that stepper work for me or do i have to look for one rated under 750mA. I would appreciate it

author
ruisantos10 made it!(author)2014-07-15

Hi diyman!

I'm not the author, bus as I've been studying and searching on how to make these 3D moves, and from what I got, usually the stepper controllers I found were rated to a determined Current(A) on EACH coil. So as this steppers have 2 coils, I've read that it means it can handle a total of 1.5A. This one shield seems to be what I look for:

"4 H-Bridges: per bridge provides 0.6A (1.2A peak current) with thermal protection, can run motors on 4.5V to 36V DC"

I'm about to order it, but I'm still colecting some other hardware (and few cash ;) )

So I think that one you said works fine! I looked over it, but the L293D looks better and cheaper for me. Also I'm pretty sure I've read somewhere, that you can actualy kind of stack more L293D on each of the provided ones to increase Current! I won't need that, but it's a possibility.

For now I'll use it just to drive DVD Drive stepper motors, which I guess won't need more than 200/300mA, for testing purposes, to get it bigger later, with the same Electronics, but with Nema (17, probably)stepper motors driving a threaded rod.

I'm so eager to finally get to that big project! But I'm learning all by my self almost from 0, so it takes some time.

To the author, congratulations! There is actually a fault on guiding people on the electronics part of these machines, but you covered it really well! Thank you for that, and I hope to be able to return my knowledge back with a good tutorial and my good intention to exchange knowledge.

Best regards

author
agostina+2007 made it!(author)2014-06-17

can this code interpret g code??

author
agostina+2007 made it!(author)2014-06-17

can this code interpret g code??

author
smughal5 made it!(author)2014-06-07

hello..i am having issues with the output.

this is what i have done so far:
1- downloaded hex file from https://github.com/grbl/grbl/downloads
2- using Xloader, i have uploaded the hex file.
3- downloaded grbl controller.
Now when see the outputs from arduino uno pins, except pin 2,3,4 and 5, all pins are consistently high, while these 4 are consistently low.
i need to know where i am making a mistake.
The above mentioned steps are what exactly i have done not even a single thing different.
Please help…
Thanks

author
pabloevaristo made it!(author)2014-05-26

Hi, great job!.

I'm trying to use the adafruit motorshield as stepper controller but I don't know the pin configuration for grbl files.

Do you have any sketch about this?

Thanks a lot

author
jatinbatra made it!(author)2013-12-26

Can I run 4 steppers with Arduino and stepper drivers ?
Why do you have to use easy drivers , when you could just buy cheap ICs like L293Ds and ULN2003/4 to drive your steppers?

author
jongscx made it!(author)2014-02-08

Each driver needs 2 digital lines: Step and Direction. So, you can run as many drivers as your arduino has pins for.

author
pinhead1984 made it!(author)2014-01-31

I'm still new to the Arduino and can't answer your 4-axis question, but I am currently working on building a CNC using the L298 driver. To use the L298 "like" an EasyDriver, you also need the L297 controller (or equivalent) and some other components. The L293D is only a driver (handles the voltage and current) and requires a controller just like the L298. The ULN2003/4 is a DARLINGTON ARRAY and is not designed for the current desires of a stepper.

Datasheets:

L293D

L297

L298

ULN2003

author
mkulesza made it!(author)2014-01-20

Hello
The Lord's great imaged motor control and stepper motors rather for the help of the driver.

I just have one question .... Can I control L298 driver, front using the Arduino for the help mach3

author
pinhead1984 made it!(author)2014-01-31

I am currently working on building a CNC using the L298 driver. To use it "like" an EasyDriver, you also need the L297 controller (or equivalent) and some other components (look up PDF).

author
andrebrandt made it!(author)2014-01-04

Hi. Are you using the grbl code in Arduino for the CNC?
Or have you made one your self?
What prog are you using for designing and g-code?

Best,
Andy

author
gakes made it!(author)2013-12-13

Thanks for the info...Can I wire up 3 different stepper motors to work on my cnc or do they have to be the same? I was wondering if I could adjust the movements on each stepper separately

author
aggrav8d made it!(author)2013-12-20

You can. It's a lot easier to use three of the same thing - less variation means less debugging.

author
write2upadhyay made it!(author)2013-10-03

i wanted to make my project, cnc milling, wireless. so i need inputs on how i would be able to send gcode generated in eagleCAD wirelessly?? and what all necessary changes i would need to make in electronics section of the project. kindly help.

author
aggrav8d made it!(author)2013-10-03

Sorry, I can't help you with this. I have almost zero experience with wireless.

author
write2upadhyay made it!(author)2013-10-03

thanks for your response. i had some input that we can send the gcode generated via a serial-to-bluetooth converted and can recieve the code in reciever blutooth which we will interface on controller, in place of serial port. i was just wondering whether it will work or not

author
aggrav8d made it!(author)2013-10-03

I don't see a problem as long as the connection doesn't drop. Wifi, cable, bluetooth... it's all the same.

author
write2upadhyay made it!(author)2013-10-03

yes, you right. i am doing my final year project and our guide is expecting us to do some out-of-box change..so someone in our group suggested making it wireless, and now we are juggling to get the idea implemented..

author
Tony32 made it!(author)2013-10-02

Could these NEMA17's be enough to have a dremel on it and cut wood? Or are they too weak? Nice tutorial!

author
Music_Man608 made it!(author)2013-06-10

Very well said. I'm a noob and need serious help. If you don't mind, I'll compile a list on the programming side of things since I only plan to engrave my business name and phone number on keys. Thanks a bunch. Btw, I love this tutorial.

About This Instructable

461,236views

795favorites

License:

Bio: I want to build my moon base with remote controlled robots and solar sintering.
More by aggrav8d:Aduino I²C 2-Way CommunicationArduino Starter Kit 2: Use Buttons for LED ControlArduino Starter Kit 1: First circuit and program to control an LED
Add instructable to: