MATLAB Answers


MATLAB Arduino limit switch

Asked by Raguvaran Veerappan on 24 Feb 2018
Latest activity Commented on by 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


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.
To Mr Walter,
Thanks for the assistance i managed to get it to work.
cheers ragu
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

Sign in to comment.

0 Answers