MATLAB Answers

MATLAB Arduino limit switch

16 views (last 30 days)
Raguvaran Veerappan
Raguvaran Veerappan on 24 Feb 2018
Commented: Yong Mun Pok on 12 Apr 2019
Hi, i would like to know how do I program the Arduino which controls a small DC motor. What I would like is for the motor to move in 1 direction and when the limit switch is hit the motor stops.
As of now, i cannot seem to get the for loop to work. I'm not sure if the read function is been sent to the loop. hope someone could help me. thanks in advance.
function rto_Callback(hObject, eventdata, handles)
global a
value=readDigitalPin(a, 'D11');
if (value==0)
writeDigitalPin(a, 'D8',1);
writeDigitalPin(a, 'D9',0);
else if (value==1)
writeDigitalPin(a, 'D8',0);
writeDigitalPin(a, 'D9',0);
% break
end
end

  14 Comments

David Fletcher
David Fletcher on 27 Feb 2018
Maybe, or maybe he's using the other pin as a 0V ground rather than a proper circuit ground. Either way, if he's got a motor connected directly to the Arduino, I don't fancy its chances for any great length of time.
Raguvaran Veerappan
Raguvaran Veerappan on 4 Mar 2018
To Mr Walter,
Thanks for the assistance i managed to get it to work.
cheers ragu
Yong Mun Pok
Yong Mun Pok on 12 Apr 2019
To Ragu,
Can you share the working code. It will really help me in doing my project. Otherwise, can send the relevant info the my email munson0829@gmail.com

Sign in to comment.

Answers (0)

Sign in to answer this question.