control the arduino from matlab

hi im doing project for my study its about pir sensore and servo motor i do it for arduino and its ready and work but my colleg want us to link the arduino with matlab and control the arduino bord from matlab like manual control and digital plz help me i dont understand any thing in matlab plz help my arduino code is :#include Servo myServo; int servopos = 0; int motionPin = 4; int Led = 8; void setup() { myServo.attach(9); myServo.write(0); Serial.begin(9600); pinMode (motionPin,INPUT); pinMode(Led,OUTPUT); } void loop() { int readValue = digitalRead(motionPin); if(readValue == 1){ OpenDoor(); digitalWrite(Led,HIGH); Serial.print">Serial.print (digitalRead(motionPin)); Serial.println(" ON "); delay(5000); } else{ CloseDoor(); digitalWrite(Led,LOW); Serial.print (digitalRead(motionPin)); Serial.println(" OFF "); } } void OpenDoor() { while(servopos <110){ servopos++; myServo.write(servopos)">myServo.write(servopos); delay(10); } } void CloseDoor() { while(servopos >0){ servopos--; myServo.write(servopos); delay(10); } }

1 Comment

i do these plz help it didnt work
a = arduino('COM5','UNO','Libraries','Servo')
my_servo = servo(a,'d9')
writePosition(my_servo,0)
writeDigitalPin(a,'d8',0)
motionDetected = readDigitalPin(a, 'd4')
disp(motionDetected);
if motionDetected
fprintf('Motion detected on %s\n', datestr(now));\
writePosition(my_servo,0.61);
writDigitalPin(a,'d13',1);
delay (5000);
else
fprintf('Motion detected off %s\n', datestr(now));
writePosition(my_servo,0);
writDigitalPin(a,'d13',0);
delay (20);
pause
end
end

Sign in to comment.

Answers (0)

Categories

Products

Release

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!