This page is to Setup and Config Stepper Motor ULN2003
Hardware and Software
Hardware
Stepper Motor ULN2003
Software
ESPlorer
Stepper Motor ULN2003
INT 1-4 : PIN 5-8
Extra V++ and GND (Not Connect to Arduino)
This example is NodeMCU (Change MotorPin1-4 to pin 5-8)
-- Stepper Motor ULN2003 CONTROL
-- Declare variable for the motor pins
motorINT1 = 5
motorINT2 = 6
motorINT3 = 7
motorINT4 = 8
motorSpeed = 1000 -- Speed
count = 0 -- count for step made
countsperrev = 512 -- no of step per full revolution
lookup = {B01000,
B01100,
B00100,
B00110,
B00010,
B00011,
B00001,
B01001}
-- INITIAL 74HC4051 OUTPUT PIN --------
gpio.mode(motorINT1, gpio.OUTPUT)
gpio.mode(motorINT2, gpio.OUTPUT)
gpio.mode(motorINT3, gpio.OUTPUT)
gpio.mode(motorINT4, gpio.OUTPUT)
function anticlockwise()
for i = 0, 7 do
setOutput(i);
tmr.delay(motorSpeed);
end
end
function clockwise()
for i = 7, 0, -1 do
setOutput(i);
tmr.delay(motorSpeed);
end
end
--function setOutput(out)
-- gpio.write(motorPin1, bit.isset(lookup[out], 0))
--digitalWrite(motorPin1, bitRead(lookup[out], 0));
--digitalWrite(motorPin2, bitRead(lookup[out], 1));
--digitalWrite(motorPin3, bitRead(lookup[out], 2));
--digitalWrite(motorPin4, bitRead(lookup[out], 3));
--end
-- 74HC4051 - set Address -------------
function setOutput(addressX)
gpio.write(motorINT1, gpio.LOW)
gpio.write(motorINT2, gpio.LOW)
gpio.write(motorINT3, gpio.LOW)
gpio.write(motorINT4, gpio.LOW)
if addressX == 0 or addressX == 1 or
addressX == 7 then
gpio.write(motorINT1, gpio.HIGH)
end
if (addressX == 2 or addressX == 3 or
addressX == 1) then
gpio.write(motorINT2, gpio.HIGH)
end
if (addressX == 4 or addressX == 3 or
addressX == 5) then
gpio.write(motorINT3, gpio.HIGH)
end
if (addressX == 6 or
addressX == 5 or addressX == 7) then
gpio.write(motorINT4, gpio.HIGH)
end
end
--direction 0 = clockwise 1 = anticlockwise
function loopTest(nofCycle, direction)
print("Start Stepper Motor Cycle : " .. nofCycle)
for i = 0, nofCycle, 1 do
if(count < countsperrev ) then
clockwise();
else
anticlockwise();
end
count = count + 1;
if (count >= countsperrev * 2) then
count = 0;
end
end
print("....... Stop Stepper Motor .....")
end
function moveStep(direction, nofMove)
if(direction == 0 ) then
print("Move : Clockwise - Steps " .. nofMove .. " [512 / Cycle]")
else
print("Move : Anti-Clockwise - Steps " .. nofMove .. " [512 / Cycle]")
end
for i = 0, nofMove, 1 do
if(direction == 0 ) then
clockwise();
else
anticlockwise();
end
end
end
--loopTest(10 * countsperrev)
moveStep(0, 256)
moveStep(1, 256)