NodeMCU Stepper Motor ULN2003

NodeMCU Stepper Motor ULN2003

This page is to Setup and Config Stepper Motor ULN2003

Hardware and Software

Hardware

Stepper Motor ULN2003

Software

ESPlorer

Sanki Notes

    • Stepper Motor ULN2003

    • INT 1-4 : PIN 5-8

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

Examples (LUA)

This example is NodeMCU (Change MotorPin1-4 to pin 5-8)

            1. -- Stepper Motor ULN2003 CONTROL

            2. -- Declare variable for the motor pins

            3. motorINT1 = 5

            4. motorINT2 = 6

            5. motorINT3 = 7

            6. motorINT4 = 8

            7. motorSpeed = 1000 -- Speed

            8. count = 0 -- count for step made

            9. countsperrev = 512 -- no of step per full revolution

            10. lookup = {B01000,

            11. B01100,

            12. B00100,

            13. B00110,

            14. B00010,

            15. B00011,

            16. B00001,

            17. B01001}

            18. -- INITIAL 74HC4051 OUTPUT PIN --------

            19. gpio.mode(motorINT1, gpio.OUTPUT)

            20. gpio.mode(motorINT2, gpio.OUTPUT)

            21. gpio.mode(motorINT3, gpio.OUTPUT)

            22. gpio.mode(motorINT4, gpio.OUTPUT)

            23. function anticlockwise()

            24. for i = 0, 7 do

            25. setOutput(i);

            26. tmr.delay(motorSpeed);

            27. end

            28. end

            29. function clockwise()

            30. for i = 7, 0, -1 do

            31. setOutput(i);

            32. tmr.delay(motorSpeed);

            33. end

            34. end

            35. --function setOutput(out)

            36. -- gpio.write(motorPin1, bit.isset(lookup[out], 0))

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

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

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

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

            41. --end

            42. -- 74HC4051 - set Address -------------

            43. function setOutput(addressX)

            44. gpio.write(motorINT1, gpio.LOW)

            45. gpio.write(motorINT2, gpio.LOW)

            46. gpio.write(motorINT3, gpio.LOW)

            47. gpio.write(motorINT4, gpio.LOW)

            48. if addressX == 0 or addressX == 1 or

            49. addressX == 7 then

            50. gpio.write(motorINT1, gpio.HIGH)

            51. end

            52. if (addressX == 2 or addressX == 3 or

            53. addressX == 1) then

            54. gpio.write(motorINT2, gpio.HIGH)

            55. end

            56. if (addressX == 4 or addressX == 3 or

            57. addressX == 5) then

            58. gpio.write(motorINT3, gpio.HIGH)

            59. end

            60. if (addressX == 6 or

            61. addressX == 5 or addressX == 7) then

            62. gpio.write(motorINT4, gpio.HIGH)

            63. end

            64. end

            65. --direction 0 = clockwise 1 = anticlockwise

            66. function loopTest(nofCycle, direction)

            67. print("Start Stepper Motor Cycle : " .. nofCycle)

            68. for i = 0, nofCycle, 1 do

            69. if(count < countsperrev ) then

            70. clockwise();

            71. else

            72. anticlockwise();

            73. end

            74. count = count + 1;

            75. if (count >= countsperrev * 2) then

            76. count = 0;

            77. end

            78. end

            79. print("....... Stop Stepper Motor .....")

            80. end

            81. function moveStep(direction, nofMove)

            82. if(direction == 0 ) then

            83. print("Move : Clockwise - Steps " .. nofMove .. " [512 / Cycle]")

            84. else

            85. print("Move : Anti-Clockwise - Steps " .. nofMove .. " [512 / Cycle]")

            86. end

            87. for i = 0, nofMove, 1 do

            88. if(direction == 0 ) then

            89. clockwise();

            90. else

            91. anticlockwise();

            92. end

            93. end

            94. end

            95. --loopTest(10 * countsperrev)

            96. moveStep(0, 256)

            97. moveStep(1, 256)