Arduino_Interface_with_MATLAB
Arduino_Interface_with_MATLAB
Installing Packages
You can easily install packages through your MATLAB.
First, start MATLAB and click the Add-Ons drop down menu. In the drop-
down menu click Get Hardware Support Packages. It will start the package
installer window.
Testing
Once the packages are installed, connect your Arduino board to your PC and
type the following command in MATLAB command window,
>> a = arduino()
if you have more than one Arduino connected to your PC, you have to
specify the board type you will be communicating with:
>> clear a
Wiring Diagram
Connect the cricuit as shown below to complete the following two
examples:
Hardware
Arduino Uno
1 x 1k Ohm resistor
USB cable for arduino
LED
Start MATLAB and create an m-file and write the following code:
Code
% create an arduino object
a = arduino('com3', 'uno');
for i = 1:10
pause(0.5);
pause(0.5);
end
clear a
Steps
1. Start MATLAB and install Arduino Hardware Support Packages (if not
already installed).
2. Connect your board to the PC and test if it’s working properly with
MATLAB.
3. Make the circuit as shown in the circuit diagram and connect pin 11 to
one end of the LED pin through resistor.
4. Connect other point of the LED to the ground pin on your arduino
board.
5. Write your m-file and save it. Run your file and MATLAB will burn that
file to your board.
6. Your led will start to blink.
Video
Hardware
Arduino Uno
1 x 1k Ohm resistor
USB cable for arduino
LED
Connect the circuit as shown above in the circuit diagram.
Code
a = arduino('com3', 'uno');
brightness_step = (5-0)/20;
for i = 1:20
pause(0.1)
end
% start a loop to turn off the led in steps so that it looks like
% led is fading
for i = 1:20;
pause(0.1)
end
clear a
Steps
1. Start MATLAB and install Arduino Hardware Support Packages (if not
already installed).
2. Connect your board with PC and test if it’s working properly with
MATLAB.
3. Make the circuit as shown in the circuit diagram, connect pin 11 to one
end of the LED pin through resistor.
4. Connect other point of LED to ground pin on your arduino board.
5. Write your m-file and save it. Run your file and MATLAB will burn that
file to your board.
6. Your led will start to brighten and then dim.
Voila!
Video