Asked by Raguvaran Veerappan
on 24 Feb 2018

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

Opportunities for recent engineering grads.

Apply Today
## 14 Comments

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_539045

## Raguvaran Veerappan (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_539048

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_539056

## Raguvaran Veerappan (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_539241

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_539260

## Raguvaran Veerappan (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_539756

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_539771

## Raguvaran Veerappan (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_539893

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_540019

## David Fletcher (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_540030

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_540040

## David Fletcher (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_540057

## Raguvaran Veerappan (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_541831

## Yong Mun Pok (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/384599-matlab-arduino-limit-switch#comment_693428

Sign in to comment.