MathWorks - Mobile View
  • Melden Sie sich bei Ihrem MathWorks Konto anMelden Sie sich bei Ihrem MathWorks Konto an
  • Access your MathWorks Account
    • Eigener Account
    • Mein Community Profil
    • Lizenz zuordnen
    • Abmelden
  • Produkte
  • Lösungen
  • Forschung und Lehre
  • Support
  • Community
  • Veranstaltungen
  • MATLAB erhalten
MathWorks
  • Produkte
  • Lösungen
  • Forschung und Lehre
  • Support
  • Community
  • Veranstaltungen
  • MATLAB erhalten
  • Melden Sie sich bei Ihrem MathWorks Konto anMelden Sie sich bei Ihrem MathWorks Konto an
  • Access your MathWorks Account
    • Eigener Account
    • Mein Community Profil
    • Lizenz zuordnen
    • Abmelden

Videos und Webinare

  • MathWorks
  • Videos
  • Videos Homepage
  • Suche
  • Videos Homepage
  • Suche
  • Vertrieb kontaktieren
  • Testsoftware
  Register to watch video
  • Description
  • Full Transcript
  • Related Resources

Using MATLAB and Arduino for Motor Control

Madhu Govindarajan, MathWorks

This hands-on tutorial shows how commands from MATLAB® Support Package for Arduino® can be used to control DC, stepper, and servo motors. We use Adafruit Motor Shield V2 and Arduino Due with MATLAB and step through a series of MATLAB commands to show these motors in action.

In this demo, we are going to see how to control motors using MATLAB Support Package for Arduino. For software, I have MATLAB and MATLAB Support Package for Arduino pre-installed on my machine. If you do not have the Support Package installed, you can go to the add-ons tab and click on Get Hardware Support Packages to download and install the Support Package. For the hardware, I have Arduino Due, Motor Party Pack for Arduino, DC Battery Pack, and a USB Micro-b Cable.

To follow along with this demo, and to make the connections that I have, connect the Servo 1 pin on the Motor Shield to the Servo Motor. And one pin to the DC Motor, and M3 and M4 pins to the Stepper Motor. It is important to note that the DC Battery Pack is necessary to control the DC Motor and the Stepper Motor. Connect the DC Battery Pack to the power pin. The Micro-b end of the cable needs to be connected to the programming -ort on the Due, and the USB end to the PC on which you have MATLAB installed. For more detailed instructions on how to make connections, please follow this link.

Now that we have made all the necessary connections, let us go to MATLAB and see how we can control motors. For this, I have written a script that I am going to show. The Arduino function in this script establishes a connection with the Due that disconnected on the com port mentioned in the first input. This function also provides instructions to MATLAB on the libraries that need to be included in the Arduino Server Code. When I execute this in MATLAB Command Window, MATLAB creates an object that represents the physical object it is connected to.

The add-on function can then operate on the object that was created to connect to the Motor Shield. Executing a command on the Command Window and running a MATLAB script has the same effect. So in the rest of this video, I'm going to use the button to go to the next section of Code after executing the current section.

MATLAB creates a new object in the workspace every time it connects to a new physical object. In this case, the Motor Shield. Here in this section of Code, the Servo and right position functions are the ones we need to pay attention to. Servo function lets you communicate from MATLAB to the Servo Motor that is connected in the port number mentioned in the second input. The right position function allows you to command the Servo Motor to move to the position mentioned. Here, I'm using a 4 loop to move the motor from 0 to 180 degrees five times, back and forth. I've attached an image of a wheel here to the Servo Motor to show it in action.

In the next section of Cord, the Stepper function helps us establish a connection to the Stepper Motor that is connected on Port 2. The third input to this function specifies the number of steps the Stepper Motor must take in every revolution. The Move function commands the Stepper Motor to move the number of steps that is mentioned in the second input. Let us see if MATLAB can make the ballerina dance to its tunes.

To communicate with the last type of motor that comes along with the Motor Party Pack from MATLAB, the DC Motor function can be used. The stop and start comment does exactly what the name suggests. Remember, these functions can only be used after the speed of the motor is mentioned. The speed of the motor must be mentioned as a percentage value for the maximum speed of the motor. The hypnotizing disc here shows the working of the DC Motor.

With that, we have seen how to control motors using MATLAB and Support Package for Arduino.

Related Products

  • MATLAB

Learn More

Download MATLAB Support Package for Arduino

Feedback

Featured Product

MATLAB

  • Request Trial
  • Get Pricing

Up Next:

3:38
Using MATLAB and Arduino to Acquire Analog Signals

Related Videos:

33:09
Using Arduino with MATLAB and Simulink
39:07
MATLAB Meets MINDSTORMS: How to Control LEGO NXT Robots...
2:04
Install the MATLAB and Simulink Support Packages for Arduino
35:18
Real-Time Control and Analysis in Biomedical Applications...

View more related videos

MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web site

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • Vertrieb kontaktieren
  • Testsoftware

Produkte

  • MATLAB
  • Simulink
  • Software für Studierende
  • Hardware-Unterstützung
  • File Exchange

Testen oder Kaufen

  • Downloads
  • Testsoftware
  • Vertrieb kontaktieren
  • Preise und Lizenzierung
  • Store

Lernen

  • Dokumentation
  • Tutorials
  • Beispiele
  • Videos und Webinare
  • Schulungen

Support

  • Hilfe zur Installation
  • Antworten
  • Consulting
  • License Center
  • Support kontaktieren

Über MathWorks

  • Jobs & Karriere
  • Newsroom
  • Social Mission
  • Vertrieb kontaktieren
  • Über MathWorks

MathWorks

Accelerating the pace of engineering and science

MathWorks ist der führende Entwickler von Software für mathematische Berechnungen für Ingenieure und Wissenschaftler.

Entdecken Sie…

  • Select a Web Site United States
  • Patente
  • Handelsmarken
  • Datenschutz
  • Datendiebstahl verhindern
  • Status von Anwendungen

© 1994-2021 The MathWorks, Inc.

  • Facebook
  • Twitter
  • Instagram
  • YouTube
  • LinkedIn
  • RSS

Folgen Sie uns

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic.  By continuing to use this website, you consent to our use of cookies.  Please see our Privacy Policy to learn more about cookies and how to change your settings.