Controlling the NEMA 17 MERCURY SM-42BYG011-25

UNO_EasyDriver_Wiring_02

Arduino Sketch highlighted using  http://hilite.me/ :

/*EasyDriver_Test.ino  Arduining.com  6 MAY 2012

Sketch used to test the EasyDriver board from Sparkfun.com
Used in the YouTube video (Jul 15, 2012): "Arduino EasyDriver and Stepper Motor "

During the test a movement of 360 degrees (full turn) was implemented.
The stepper turns right and left alternatively.

Hardware:
-EasyDriver v4.4
  MS1 and MS2 connected to ground to select Full-Step mode.

-Stepper Motor SM-42BYG011-25 features:
  • Step Angle (degrees) :1.8
  • 2 Phase
  • Rated Voltage : 12V
  • Rated Current : 0.33A
  
*/

#define DIR   2
#define STEP  3

void advance(int steps)
{
  if(steps>0)digitalWrite(DIR, LOW); // Set clockwise direction.
  else{
    digitalWrite(DIR, HIGH);         // Set counter-clockwise direction.
    steps=abs(steps);
  }
  for (int i = 0; i<steps; i++){     // Rotate n steps.
    digitalWrite(STEP, HIGH);
    delayMicroseconds(20);           // Minimum STEP Pulse Width 1.0uS
    digitalWrite(STEP, LOW);         // Step pulse (rising edge).
    delay(10);                       // Delay between steps
  }
} 

void setup()
{
  pinMode(DIR, OUTPUT);
  pinMode(STEP, OUTPUT);
}

void loop()
{
  delay(250);
  advance(200);
  delay(250);
  advance(-200);
}


Controlling the DOWONSOL-9181 Stepper

EasyDriver_Pot_01


Arduino Sketch highlighted using  http://hilite.me/ :

/*------------------------------------------------------
EasyDriver_Pot_01.ino  Arduining 31 MAY 2015

Stepper motors following a potentiometer on analog input 0.
A software low-pass filter is used to reduce the noise in the analog reading.

The ENABLE signal is used to shut-down the current and keep the motor cold.

Hardware:
-Arduino UNO
-EasyDriver v4.4
  MS1 and MS2 connected to GND. (single stepping)
-Stepper Motor DOWONSOL:
  Model: 9181
  Voltage: 12V
  Coils impedance: 70 Ohms. (measured)
  Motor Step angle: 18 degrees
  GearBox reduction: 36:1
  Output angle/step: 0.5 degree  (720 pulses/revolution)
-Stepper Motor MERCURY:
  Model: ST-PM35-15-11C
  Voltage: 12V
  Motor Step angle: 48 degrees
  Output angle/step: 7.5 degree  (48 pulses/revolution)

 -----------------------------------------------------*/
#define MS1   12
#define MS2   11
#define STEP  10
#define DIR   9
#define EN    8

#define POT   0
#define TURN  720      //number of steps per revolution (DOWONSOL)
//#define TURN  48      //number of steps per revolution (MERCURY)
int potVal,targetPos;
int lastPot=0;
int actualPos=0;

void pulse(){
    digitalWrite(STEP, HIGH);
    delayMicroseconds(20);         // Minimum STEP Pulse Width 1.0uS
    digitalWrite(STEP, LOW);       // Step pulse (rising edge).
} 

void setup()
{
  pinMode(DIR, OUTPUT);
  pinMode(STEP, OUTPUT);
  pinMode(MS1, OUTPUT);
  pinMode(MS2, OUTPUT);
  pinMode(EN, OUTPUT);
  
  digitalWrite(MS1, LOW);          // Full step selected
  digitalWrite(MS2, LOW);          // Full step selected
  digitalWrite(EN, HIGH);          // Disable the A3967 IC.
}

void loop()
{
  potVal = analogRead(POT);       // Potentiometer value range 0-1023
  potVal= potVal * 0.1 + lastPot * 0.9 ;  // Filtering to reduce noise.
  lastPot= potVal;
  targetPos= map(potVal,0,1023,0,TURN);   // Map pot range in the stepper range.
  if(abs(targetPos - actualPos)> 1){      //if diference is greater than 1 step.
      digitalWrite(EN, LOW);              // Enable the A3967 IC.
      if((targetPos - actualPos)> 0){
          digitalWrite(DIR, LOW);         // Set counter-clockwise direction.
          pulse();                        // move one step to the right.
          actualPos++;
          }
      else{
          digitalWrite(DIR, HIGH);        // Set counter-clockwise direction.
          pulse();                        // move one step to the right.
          actualPos--;
      }
  }
  delay(5);
  digitalWrite(EN, HIGH);                 // Disable the A3967 IC.
}

Youtube video:

https://www.youtube.com/watch?v=S5vF9NEeOhA




Advertisement