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

470,396

802

185

Published

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

About: I want to build my moon base with remote controlled robots and solar sintering.



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

Share

    Recommendations

    • Oil Contest

      Oil Contest
    • Make it Move Contest

      Make it Move Contest
    • Clocks Contest

      Clocks Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    185 Comments

    What if I want to use 2 steppers for y axis

    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.

    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.

    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.

    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!

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

    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?

    4 replies

    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

    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.

    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

    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 )

    3 replies

    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.

    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

    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

    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???

    1 reply

    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.

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

    1 reply

    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.