element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
STEM Projects
  • Learn
  • Learning Center
  • STEM Academy
  • STEM Projects
  • More
  • Cancel
STEM Projects
Blog Teacher's Pet Arduino Kit - Blog 3
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join STEM Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: madhugovindarajan
  • Date Created: 4 Jun 2015 2:35 PM Date Created
  • Views 362 views
  • Likes 0 likes
  • Comments 0 comments
  • teachers_pet
  • matlab
  • teachers pet robotics design challenge
  • arduino
  • simulink
Related
Recommended

Teacher's Pet Arduino Kit - Blog 3

madhugovindarajan
madhugovindarajan
4 Jun 2015

Hi everyone, this is Madhu Govindarajan from MathWorks. In this blog, I will share how to get started with MATLAB Support package for Arduino and servo motors.

 

All first time users please follow the instructions here to install the MATLAB Support package for Arduino. Once you have the Support package installed, the next step from the software side is to write the script for controlling the motors.

 

1) Connect the Arduino Due's Programming Port with a USB cable to the computer that you are running MATLAB on.

2) We need to know the COM port that the Arduino Due is connected to the computer. For Windows Users, Control Panel > Hardware and Sound > Devices and Printers.

3) Create a connection from MATLAB to Arduino Due using the command shown below.

>> a = arduino('com4', 'Due', 'Libraries', 'Adafruit\MotorShieldV2');

Here, the library 'MotorShieldV2' is mentioned during the connection attempt so that the server code can include information related to this Adafruit library. Once the connection is made you can see 'a' (an arduino object) in the Workspace.

4) Create an addon shield connection from MATLAB for the V2 Motor Shield using the following MATLAB commands.

>> addOnShield = addon(arduinoConnect, 'Adafruit\MotorShieldV2');

Just like before, once the connection is established a new object will be created in the Workspace.

5) To Control the Servo motor using the Adafruit Motor Shield and to make it move from 0 degrees to 180 degrees in steps of 36 degrees execute the following commands.

>> servoMotor = servo(addOnShield, 1);

>> for angle = 0:0.2:1 % From minimum 0 degrees to maximum 180 degrees

writePosition(servoMotor, angle);

pause(1);

end


Here just to show that the motor moves in 5 steps I have included the pause command which waits for a second before it continues. I have also included comments here directly (using the % sign).


For ease of use you can follow along with the YouTube video by downloading these files.


You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image



  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube