Error while operating stepper motor
4 views (last 30 days)
Show older comments
Hello,
I want to control stepper motor using matlab, arduino hardware and l293d driver.
I write simple code to supply the driver with appropriate pulses, the motor move but not in the correct way and the speed is fixed dispite of value of delay time between steps. this is the code below. I test the code in arduino ide it work fine and the stepper fully controlled, but i don't know why in matlab it doesn't work. any one help
clear;
clc;
delay_time = 0.001; % delay time between steps
%% Initialize arduino pins
a = arduino("COM6","Mega2560");
configurePin(a,"D8","DigitalOutput");
configurePin(a,"D9","DigitalOutput");
configurePin(a,"D10","DigitalOutput");
configurePin(a,"D11","DigitalOutput");
%% move stepper motor step by step with delat time 1ms
while 1
% first step
writeDigitalPin(a,'D8',1)
writeDigitalPin(a,'D9',0)
writeDigitalPin(a,'D10',1)
writeDigitalPin(a,'D11',0)
pause(delay_time)
% second step
writeDigitalPin(a,'D8',0)
writeDigitalPin(a,'D9',1)
writeDigitalPin(a,'D10',1)
writeDigitalPin(a,'D11',0)
pause(delay_time)
% third step
writeDigitalPin(a,'D8',0)
writeDigitalPin(a,'D9',1)
writeDigitalPin(a,'D10',0)
writeDigitalPin(a,'D11',1)
pause(delay_time)
% 4th step
writeDigitalPin(a,'D8',1)
writeDigitalPin(a,'D9',0)
writeDigitalPin(a,'D10',0)
writeDigitalPin(a,'D11',1)
pause(delay_time)
end
0 Comments
Answers (1)
Shreshth
on 16 Jul 2024
Hey Safaa,
It appears that u are looking to control stepper motor using MATLAB and L293D driver.
MATLAB handles the timing and digital pin writing compared to the Arduino IDE. MATLAB might not be able to achieve the precise timing required for controlling the stepper motor, resulting in the motor not moving correctly or at a fixed speed regardless of the delay time.
I would recommend you to install the support package for ardunio hardware and then try to control the motor.
You can use L293D motor block controls to control the motor.
Kindly refer to the below mentioned resources from MathWorks to understand about the support package and controlling motor using Arduino board.
Hope it helps.
0 Comments
See Also
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!