0% found this document useful (0 votes)
80 views1 page

Sending Data From The Arduino To MATLAB

The document describes a program that sends variable values from an Arduino to MATLAB to be plotted over time. The Arduino code initializes a variable i, begins serial communication at 9600 baud, and prints the incremented value of i in a loop. The MATLAB code opens a serial connection to the Arduino, uses a for loop to scan the received values into a vector y as it iterates from 1 to 100, closes the connection, and plots y against the index vector x.

Uploaded by

Parveen Sahni Er
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views1 page

Sending Data From The Arduino To MATLAB

The document describes a program that sends variable values from an Arduino to MATLAB to be plotted over time. The Arduino code initializes a variable i, begins serial communication at 9600 baud, and prints the incremented value of i in a loop. The MATLAB code opens a serial connection to the Arduino, uses a for loop to scan the received values into a vector y as it iterates from 1 to 100, closes the connection, and plots y against the index vector x.

Uploaded by

Parveen Sahni Er
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Sending Data From The Arduino To MATLAB

Program will be send the value of a variable from the Arduino to MATLAB and plot them.
Arduino Serial Code is

1. int i=0;
2. void setup()
3. {
4. Serial.begin(9600);
5. }
6.
7. void loop()
8. {
9. Serial.println(i);
10. i++;
11. }

all am doing in the code above is sending the value of the variable i at a baud rate of 9600.

And The MATLAB Code is

1. clear all
2. clc
3.
4. arduino=serial('COM4','BaudRate',9600);
5.
6. fopen(arduino);
7.
8. x=linspace(1,100);
9.
10. for i=1:length(x)
11. y(i)=fscanf(arduino,'%d');
12. end
13.
14. fclose(arduino);
15. disp('making plot..')
16. plot(x,y);

You might also like