File Exchange

image thumbnail

Arduino meets MATLAB

version 1.1 (1.48 KB) by

Matlab Linked to Arduino



View License

The current submission illustrates a way to use the popular open source arduino boards with MATLAB illustrating the capabilities of data acquisition and visualization in real time .

The Arduino Demilanove based on the ATMEGA 328 is used to send a series of time series through the serial interface and the matlab code acquires the data and performs a meaningful part of the same at a baud rate of 9600.

There are quite a few things that could be made more visually appealing by using Matlab with the microcontrollers !

I was happy to get my board at a low cost not bearing much custom duties and i have listed the vendor who markets them in India !

Comments and Ratings (15)


Joseph (view profile)

Thanks for this one. However, I am using gizDuino MiniUSB with ATEM328. Unlike Arduino Uno, gizDuino is being read by the computer as "libusb" not as coneected in communication port. Therefore I have the problem of identifying what COM port to be use. Can you help me figure out how to solve my problem?

i tried to interface arduino uno with matlab using command
but facing errors like undefined function
can anyone help me out??


Hossam (view profile)

I would like to know how to send bytes from the arduino to matlab, and these bytes are packets for an image ? I would like to display the image on matlab. I would be grateful to who answers me :)


Suresh (view profile)

I don't see anything on the graph.

I have a Microcontroller board(Arduino Uno) that sends data between 1 - 1024(digits)for every 1000 mili seconds to the COM port 5 of Windows XP PC.

I want to receive this data in to MatLab and display a graph of Time versus Data. I want to display both Static and Dynamic or whichever is possible easily.

Sreeram Mohan

Hi Alex is ,

Looks like what u need to do is the reverse of what my file submission does !

Instead of the fscanf u could do a fprintf to the com port that is assigned to the arduino on the PC and pass in the sinewave values from matlab !

Hope this helps !


Sreeram Mohan

hi fremond khoo ,

Potentiometers are generally analog inputs which can be easily read through the pins on the arduino ! refer to the analogIn functions and a simple schematic on the arduino playground on how to do it !

Further the only interface through which the arduino can talk to any other software on a host (PC) is basically through the serial port.

so having said that
analogin --> Arduino --> serial.print --> matlab code

should be the psuedo path !

Hope this helps !


Alex is

is it technically possible I mean?

Alex is

Hi I am trying to generate sine waves from matlab and input into the arduino uno. can someone please help me in describing the procedure?

fremond khoo

hi and good day to all,

i want to ask about the interface with arduino and matlab..i am now trying to get the data from potentiometer which is attached at my stepper motor shaft..can anybody tell me how to get the data from potentiometer through arduino board to my computer(MATLAB) and try to plot the graph at the same time?..i have the code to plot the graph but i cant run both files at the same..

either i run my motor or get data from potentiometer by turning the potentiometer how do i solve this??..

anyone would be so kind to help out here??

thanks in advance^^

Gautam Vallabha

See here for another freely downloadable implementation of a MATLAB <-> Arduino interface over a USB serial cable:

Sreeram Mohan

Hi Daniel,

A simple fix to the problem faced is to make the arduino to get a start command from the matlab and then start the communication from the arduino end.I have had success doing this and may be post an other sketch to the file exchange.

Cheers !

Thanks Ram. I was using code similar to the screen shot and it was not solving the timeout problems. It took me quite some time to figure this out but here's what was happening (In case anyone else cares):

The Arduino Starts sending serial messages on bootup. If Matlab is stated after the Arduino Matlab has a lot of trouble framing the Serial messages. What does work is to reset the arduino, and then while the bootloader is starting up, open the serial port. That way Matlab doesn't time out and it gets the first reading for the arduino. Another solution is to implement some sort of handshaking.

Sreeram Mohan

Hi Daniel,

You could look at the snap shot with the file-submission and the c-code is clearly visible.

hope this helps,


Do you have the Arduino side of this code? I get a timeout when I try to read in the serial data using the serial.write() on the arduino. Is there a end of line that is required by Matlab?



Just added some places to find these boards in INDIA .

MATLAB Release
MATLAB 7.4 (R2007a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today