Professional Documents
Culture Documents
Sending Data From The Arduino To MATLAB
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.
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);