control the arduino from matlab
Show older comments
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
Haitham Abdalhafeez
on 25 May 2022
Answers (0)
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!