Sửa chữa Robot đồ chơi công nghệ
Sửa chữa Robot dân dụng

How to test Control a Stepper Motor with A4988 Driver

Posted at: THUrsday - 08/12/2016 10:33 - post name: SuperG
Control a Stepper Motor with A4988 Driver

Control a Stepper Motor with A4988 Driver

In this Arduino Tutorial we will learn how to control a Stepper Motor using the A4988 Stepper Driver. You can watch the following video or read the written tutorial below.

The A4988 is a microstepping driver for controlling bipolar stepper motors which has built-in translator for easy operation. This means that we can control the stepper motor with just 2 pins from our controller, or one for controlling the rotation direction and the other for controlling the steps.

 

 

1
A4988-Stepper-Driver

 

The Driver provides five different step resolutions: full-step, haft-step, quarter-step, eight-step and sixteenth-step. Also, it has a potentiometer for adjusting the current output, over-temperature thermal shutdown and crossover-current protection.

Its logic voltage is from 3 to 5.5 V and the maximum current per phase is 2A if good addition cooling is provided or 1A continuous current per phase without heat sink or cooling.

A4988-Specifications

A4988 Stepper Driver Pinout


Now let’s close look at the pinout of the driver and hook it up with the stepper motor and the controller. So we will start with the 2 pins on the button right side for powering the driver, the VDD and Ground pins that we need to connect them to a power supply of 3 to 5.5 V and in our case that will be our controller, the Arduino Board which will provide 5 V.  The following 4 pins are for connecting the motor. The 1A and 1B pins will be connected to one coil of the motor and the 2A and 2B pins to the other coil of the motor. For powering the motor we use the next 2 pins, Ground and VMOT that we need to connect them to Power Supply from 8 to 35 V and also we need to use decoupling capacitor with at least 47 µF for protecting the driver board from voltage spikes.

A4988-Wiring-Diagram

The next two 2 pins, Step and Direction are the pins that we actually use for controlling the motor movements. The Direction pin controls the rotation direction of the motor and we need to connect it to one of the digital pins on our microcontroller, or in our case I will connect it to the pin number 4 of my Arduino Board.  With the Step pin we control the mirosteps of the motor and with each pulse sent to this pin the motor moves one step. So that means that we don’t need any complex programming, phase sequence tables, frequency control lines and so on, because the built-in translator of the A4988 Driver takes care of everything. Here we also need to mention that these 2 pins are not pulled to any voltage internally, so we should not leave them floating in our program.

Next is the SLEEP Pin and a logic low puts the board in sleep mode for minimizing power consumption when the motor is not in use.

Next, the RESET pin sets the translator to a predefined Home state. This Home state or Home Microstep Position can be seen from these Figures from the A4988 Datasheet. So these are the initial positions from where the motor starts and they are different depending on the microstep resolution. If the input state to this pin is a logic low all the STEP inputs will be ignored. The Reset pin is a floating pin so if we don’t have intention of controlling it with in our program we need to connect it to the SLEEP pin in order to bring it high and enable the board.

A4988-Truth-Table1

The next 3 pins (MS1, MS2 and MS3) are for selecting one of the five step resolutions according to the above truth table. These pins have internal pull-down resistors so if we leave them disconnected, the board will operate in full step mode.

The last one, the ENABLE pin is used for turning on or off the FET outputs. So a logic high will keep the outputs disabled.

Components needed for this Arduino Tutorial


You can get the components from any of the sites below:

*Please note: These are affiliate links. I may make a commission if you buy the components through these links.
I would appreciate your support in this way!

Circuit Schematics


Here’s the complete circuit schematics. I will use the drive in Full Step Mode so I will leave the 3 MS pins disconnected and just connect the Direction and the Step pins of the drive to the pins number 3 and 4 on the Arduino Board and as well the Ground and the 5 V pins for powering the board. Also I will use a 100µF capacitor for decoupling and 12V, 1.5A adapter for powering the motor. I will use a NEMA 17 bipolar Stepper Motor and its wires A and C will be connected to the pins 1A and 1B and the B and D wires to the 2A and 2B pins.

Controlling-Stepper-Motor-Circuit-Schematics

Current Limiting


Before we connect the motor we should adjust the current limiting of the driver so that we are sure that the current is within the current limits of the motor. We can do that by adjusting the reference voltage using the potentiometer on the board and considering this equation: Current Limit = VRef x 2

Reference-Voltage-Measurement3

However this equation is not always correct as there are different manufactures of the A4988 driver board. Here’s a demonstration of my case: I adjusted the potentiometer and measured 0.6V reference voltage. So the current limiting should be that value of 0.6*2, equal 1.2 A.

Reference-Voltage-Measurement4

Now because I am using the Driver in Full Step Mode and according to the A4988 Datasheet in this mode the winding current could reach only 70% of the current limit, the 1.2A*0.7 would equal 0.84A. In order to check this I uploaded a simple code that sends continuous logic high to the Step pin (so that we can better notice the current) and connected my meter in series with one winding of the motor and powered it up. What I got was 0.5A which means that the equation wasn’t correct for my case.

Reference-Voltage-Measurement5

Video: https://youtu.be/5CmjB4WF5XA

 

Controlling a Stepper Motor with an Arduino UNO on 8 steps

 

Controlling a Stepper Motor with an Arduino
Stepper_bb.png

This tutorial will show you how to operate a stepper motor that was salvaged from an old printer with an Arduino.

Step 1: What is a Stepper Motor?
What is a Stepper Motor?
Stepper Motor.jpg

A stepper motor consists of two main parts, a rotor and a stator. The rotor is the part of the motor that actually spins and provides work. The stator is the stationary part of the motor that houses the rotor. In a stepper motor, the rotor is a permanent magnet. The stator consists of multiple coils that act as electromagnets when an electrical current is passed through them. The electromagnetic coil will cause the rotor to align with it when charged. The rotor is propelled by alternating which coil has a current running through it.

Stepper motors have a number of benefits. They are cheap and easy to use. When there is no current send to the motor, the steppers firmly hold their position. Stepper motors can also rotate without limits and change direction based on the polarity provided.

Step 2: Parts List

Needed Parts

  • Stepper Motor (This motor was salvaged from an old printer)
  • Arduino
  • Insulated Copper Wire
  • Wire Cutters/Strippers
  • Current Regulator
    • Transistor
    • H-Bridge (What will be used in this tutorial)
    • Motor Shield

Optional Parts

  • Soldering Iron
  • Solder
  • Soldering Fan
  • 3rd Hand Tool
  • Safety Glasses

Step 3: Attach the Wires

Attach the Wires
IMG_4878.JPG
IMG_4879.JPG

Most stepper motors have four leads so you will need to cut four pieces of copper wire (note the color does not correlate to anything specific. Different colors were only used to make it easier to see). These leads will be used to control which coil is currently active in the motor. This motor was salvaged from an old printer so soldering the wires on was the easiest option for this project. Anyway you can safely make a connection (solder, plug, clips) will work though.

Step 4: Arduino Sketch

Arduino Sketch
stepper.png
step_motor1_2.gif

Arduino already has a built in library for stepper motors. Simply go to File > Examples > Stepper > stepper_oneRevolution. Next you are going to want to change the stepsPerRevolution variable to fit your specific motor. After looking up the motors part number on the internet, this particular motor was designed for 48 steps to complete one revolution. What the Stepper library is actually doing is just alternating HIGH and LOW signals to each coil as shown in the GIF.

Step 5: What is an H-Bridge?

What is an H-Bridge?
hbridge_labpinout.jpg

An H-Bridge is a circuit comprised of 4 switches that can safely drive a DC motor or stepper motor. These switches can be relays or (most commonly) transistors. The transistor is a solid state switch that can be closed by sending a small current (signal) to one of its pins. Unlike a single transistor which only allow you to control the speed of a motor, H-bridges allow you to also control the direction in which the motor spins. It does this by opening different switches (the transistors) to allow the current to flow in different directions and thus changing the polarity on the motor. WARNING: Switches 1 and 2 or 3 and 4 should never be closed together. This will cause a short circuit and possible damage to the device.

H-Bridges can help prevent your Arduino from being fried by the motors you are using it drive. Motors are inductors, meaning that they store electrical energy in magnet fields. When current is no longer being sent to the motors, the magnetic energy turns back into electrical energy and can damage components. The H-Bridge helps isolate your Arduino better. You should never plug a motor directly into an Arduino.

Though H-Bridges can be fairly easily built, many opt to buy an H-Bridge (such as a L293NE/SN754410 chip) due to convenience. This is the chip that we will be using in this tutorial. The physical pin numbers and their purpose are listed below.

  • Pin 1 (1, 2EN) ---> Motor 1 Enable/Disable (HIGH/LOW)
  • Pin 2 (1A) ---> Motor 1 Logic Pin 1
  • Pin 3 (1Y) ---> Motor 1 Terminal 1
  • Pin 4 ---> Ground
  • Pin 5 ---> Ground
  • Pin 6 (2Y) ---> Motor 1 Terminal 2
  • Pin 7 (2A) ---> Motor 1 Logic Pin 2
  • Pin 8 (VCC2) ---> Power Supply for Motors
  • Pin 9 ---> Motor 2 Enable/Disable (HIGH/LOW)
  • Pin 10 ---> Motor 2 Logic Pin 1
  • Pin 11 ---> Motor 2 Terminal 1
  • Pin 12 ---> Ground
  • Pin 13 ---> Ground
  • Pin 14 ---> Motor 2 Terminal 2
  • Pin 15 ---> Motor 2 Logic Pin 2
  • Pin 16 (VCC1) ---> Power Supply for H Bridge (5V)

Step 6: Connect the Wires

Connect the Wires
IMG_5178.JPG
IMG_4885.JPG
IMG_5179.JPG

For a stepper motor, the 4 terminal pins on the H-Bridge should connect to the 4 leads of the motor. The 4 logic pins will then connect to the Arduino (8, 9, 10, and 11 in this tutorial). As shown in the Fritzing diagram, an external power source can be connected to power the motors. The chip can handle an external power source from 4.5V to 36V (I just chose a 9V battery because I'm still new to Fritzing).

Step 7: Upload Code and Test

Upload your code onto your Arduino. If you run your code and everything works as expected then that is awesome! If the wires are put into the wrong pins then the motor will just vibrate instead of fully rotating. Play around with the speed and direction of the motor as you see fit.

You should now have a working stepper motor with your Arduino. What you do next with it is up to you.

Step 8: Referneces & Thanks

The full data sheet for the H-Bridge can be found here.

When I initially posted this I didn't think it would gain the attention that it did. For that reason, I just made a quick instructable that I was planning on editing once all my parts had arrived. I didn't mean to cause so much concern with my previous, sloppy methods. Thanks for all your comments and I have updated my instructable to reflect the more appropriate method of connecting stepper motors.

 

Motor is Bi-polar. It has two windings and you need to use a circuit that constantly inverts the polarity of the supply to the coils.

enter image description here

This is done with an H-bridge that operates as four switches.

enter image description here

You need one H-bridge per coil, so you'll need two of them to control your stepper. In practice these switches are either mosfets or transistors.

enter image description here

enter image description here

Bi Polar Stepper Motor with L293D and Arduino

 

Bi Polar Stepper Motor with L293D and Arduino

Components used:

  1. Arduino Uno
  2. Stepper Motor ML17A3 B (This is the model no printed on motor)
  3. Breadboard
  4. L293D
  5. 9v Battery Pack
  6. Some Jumper cables

To make the connections, follow the circuit diagram.

Step 1: Connections on breadboard

Connections on breadboard
20140831_050142.jpg
20140831_050230.jpg
20140831_050334.jpg

The images show the step by step connections made on bread board. I started off with GND pins and then to the motor and then Arduino and finally the Battery Pack.


Step 2: Code

I used the code from Arduino IDE. I tried with stepper_OneRevolution and stepper_OneStepAtATime example and they worked fine. The code is listed below.

/* 
This program drives a unipolar or bipolar stepper motor. The motor is attached to digital pins 8 - 11 of the Arduino. The motor should revolve one revolution in one direction, then one revolution in the other direction. Created 11 Mar. 2007 Modified 30 Nov. 2009 by Tom Igoe */

#include

const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution // for your motor

// initialize the stepper library on pins 8 through 11:

Stepper myStepper(stepsPerRevolution, 8,9,10,11);

void setup() { 
// set the speed at 60 rpm: 
myStepper.setSpeed(60); 
// initialize the serial port: 
Serial.begin(9600); }

void loop() {

// step one revolution in one direction: 
Serial.println("clockwise"); 
myStepper.step(stepsPerRevolution); 
delay(500); 
// step one revolution in the other direction: 
Serial.println("counterclockwise"); 
myStepper.step(-stepsPerRevolution); 
delay(500); }

Step 3: Final Testing

The testing video: https://youtu.be/dpKPrYC8Ye0

 

Article reviews
Total number of articles is: 0 in 0 rating
You click on a star to rate article
 

About us

About us We provide 3D printers for retail and wholesale, We produced and assembled at Hanoi, Vietnam with many type: Cube, Delta, Mendel, scara, robot arm, custom by client...  - Repair 3D printers - Provide 3D printing materials...

1 1 1