Stepper Motor ULN2003

Stepper Motor ULN2003

This page is to Setup and Config Stepper Motor ULN2003

Hardware and Software

Hardware

Stepper Motor ULN2003

Software

Arduino IDE

Sanki Notes

    • Stepper Motor ULN2003

    • INT 1-4 : PIN 8-11

    • Extra V++ and GND (Not Connect to Arduino)

Examples

This example is Arduino and Digispark (Change MotorPin1-4 to pin 0-4)

Reference : http://www.4tronix.co.uk/arduino/Stepper-Motors.php

            1. // This Arduino example demonstrates bidirectional operation of a

            2. // 28BYJ-48, using a ULN2003 interface board to drive the stepper.

            3. // The 28BYJ-48 motor is a 4-phase, 8-beat motor, geared down by

            4. // a factor of 68. One bipolar winding is on motor pins 1 & 3 and

            5. // the other on motor pins 2 & 4. The step angle is 5.625/64 and the

            6. // operating Frequency is 100pps. Current draw is 92mA.

            7. ////////////////////////////////////////////////

            8. //declare variables for the motor pins

            9. int motorPin1 = 8; // Blue - 28BYJ48 pin 1

            10. int motorPin2 = 9; // Pink - 28BYJ48 pin 2

            11. int motorPin3 = 10; // Yellow - 28BYJ48 pin 3

            12. int motorPin4 = 11; // Orange - 28BYJ48 pin 4

            13. // Red - 28BYJ48 pin 5 (VCC)

            14. int motorSpeed = 1200; //variable to set stepper speed

            15. int count = 0; // count of steps made

            16. int countsperrev = 512; // number of steps per full revolution

            17. int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};

            18. //////////////////////////////////////////////////////////////////////////////

            19. void setup() {

            20. //declare the motor pins as outputs

            21. pinMode(motorPin1, OUTPUT);

            22. pinMode(motorPin2, OUTPUT);

            23. pinMode(motorPin3, OUTPUT);

            24. pinMode(motorPin4, OUTPUT);

            25. Serial.begin(9600);

            26. }

            27. //////////////////////////////////////////////////////////////////////////////

            28. void loop(){

            29. if(count < countsperrev )

            30. clockwise();

            31. else if (count == countsperrev * 2)

            32. count = 0;

            33. else

            34. anticlockwise();

            35. count++;

            36. }

            37. //////////////////////////////////////////////////////////////////////////////

            38. //set pins to ULN2003 high in sequence from 1 to 4

            39. //delay "motorSpeed" between each pin setting (to determine speed)

            40. void anticlockwise()

            41. {

            42. for(int i = 0; i < 8; i++)

            43. {

            44. setOutput(i);

            45. delayMicroseconds(motorSpeed);

            46. }

            47. }

            48. void clockwise()

            49. {

            50. for(int i = 7; i >= 0; i--)

            51. {

            52. setOutput(i);

            53. delayMicroseconds(motorSpeed);

            54. }

            55. }

            56. void setOutput(int out)

            57. {

            58. digitalWrite(motorPin1, bitRead(lookup[out], 0));

            59. digitalWrite(motorPin2, bitRead(lookup[out], 1));

            60. digitalWrite(motorPin3, bitRead(lookup[out], 2));

            61. digitalWrite(motorPin4, bitRead(lookup[out], 3));

            62. }