Someone bought NEMA17 motors from us and asked for a test, so we obliged and thought it may be better to post it here in case someone else needs it. The requirements was to use the following parts from our stock:
- Saleng/Arduino Uno
- NEMA17 Bipolar Stepper Motor
- A4988 driver module
We then needed to rotate the motor clockwise and counter clockwise to demonstrate its basic usage. Here is our wiring diagram:
This is our test code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
/*************************************************************************** A testing code to move a NEMA17 stepper motor on both directions using the A4988 motor driver module. This software is free provided that this notice is not removed and proper attribution is accorded to Layad Circuits and its Author(s). Layad Circuits invests resources in producing free software. By purchasing Layad Circuits' products or utilizing its services, you support the continuing development of free software for all. Revision: 1.0 - 2018/12/11 - initial creation Layad Circuits Electronics Engineering Supplies and Services B314 Lopez Bldg., Session Rd. cor. Assumption Rd., Baguio City, Philippines www.layadcircuits.com general: info@layadcircuits.com sales: sales@layadcircuits.com +63-916-442-8565 ***************************************************************************/ const byte PIN_STEP = A0; const byte PIN_DIR = A1; const unsigned long HALF_PULSE_WIDTH = 750; void setup() { pinMode(PIN_STEP,OUTPUT); pinMode(PIN_DIR,OUTPUT); Serial.begin(9600); } void loop() { digitalWrite(PIN_DIR,HIGH); // move in one direction for(int x = 0; x < 400; x++) { // generate 200 pulses digitalWrite(PIN_STEP,!digitalRead(PIN_STEP)); delayMicroseconds(HALF_PULSE_WIDTH); } delay(2000); digitalWrite(PIN_DIR,LOW); //change to the opposite direction for(int x = 0; x < 400; x++) { // generate 200 pulses digitalWrite(PIN_STEP,!digitalRead(PIN_STEP)); delayMicroseconds(HALF_PULSE_WIDTH); } delay(2000); } |
After uploading and correctly wiring, you should expect the motor to move one full revolution in both directions. Happy hacking!