/* Program 10-3 Stepper motor control * * H-bridge driver TB6612FNG consists of four half-bridge circuit. * A bipolar stepper motor should have one winding connected * across M1-M2 terminals and the other winding M3-M4. It works with * a unipolar stepper motor as well. * The program turn two revolutions in one direction and reverse the direction * for one revolution. The StepsPerRevolution should be adjusted to match * the motor. * * This program uses Stepper library. For details of the library see * https://www.arduino.cc/en/Reference/Stepper */ #include const int StepsPerRevolution = 96; /* motor specific value */ const int PWM12 = 5; const int PWM34 = 6; /* specify the pins used to control the stepper motor */ Stepper stepper(StepsPerRevolution, 2, 3, 7, 8); void setup() { stepper.setSpeed(30); /* set the step speed for rpm */ /* enable motor output with PWM at 100% */ pinMode(PWM34, OUTPUT); pinMode(PWM12, OUTPUT); digitalWrite(PWM34, HIGH); digitalWrite(PWM12, HIGH); } void loop() { /* turn motor in one direction for two revolutions */ stepper.step(StepsPerRevolution * 2); delay(500); /* pause before reverse */ /* reverse motor direction for one revolution */ stepper.step(-StepsPerRevolution); delay(500); /* pause before reverse */ }