Hi!
I'm working on a project that involves displaying the real time data acquired from a variable resistor on the monitor. I am using MATLAB along with Arduino for this purpose.
I am unable to display the real time data.
This is the code I am using for Arduino:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println(analogRead(A0));
}
This is the code I am using for MATLAB:
clc;
clear;
arduino = serial('COM41', 'BaudRate', 9600);
fopen(arduino);
x=linspace(1,100);
for i=1:length(x)
y(i)=fscanf(arduino, '%d');
end
fclose(arduino);
title('Breathing Pattern')
plot(x,y)
xlabel('Time in seconds');
ylabel('Digital Value');
I have attached a picture of the output I get. The graph doesn't depict the variation in the potentiometer. When I ran the program, the potentiometer was kept at a constant value, yet the graph shows varying values. The value of the potentiometer displayed in the graph doesn't correspond to the actual value of the potentiometer. I ran the program using Arduino and used the Serial monitor to verify the value.