How can I plot a continuous graphic of live recorded data with Arduino?
Show older comments
Hello everybody, I am currently working on a project in which I have to record data (in this example, temperature) and I want to plot it live on a graphic. I am using an Arduino Uno, and after downloading and installing everything correctly I wrote this code:
i=0;
while(2>1) %For making the loop infinite
x=i
v1=readVoltage(a, 'A0'); %Analog input for the first NTC temperature sensor
v2=readVoltage(a, 'A2'); %Analog input for the second NTC temperature sensor
t1=temp(v1); %Here I obtain the temperature with
t2=temp(v2); %a function that I will post afterwards
y1=t1;
y2=t2;
pause(1.0); %line 11
i=i+1;
plot(x,y1, x,y2) %line 13
hold on
axis([0 inf 15 30]) %Chose those y-axis values because in normal conditions, temp is aprox 22ºC
end
The function for the temperature "temp()" is:
function [t]=temp(v)
rAux = 10000.0;
vcc = 5.0;
beta = 3977.0;
temp0 = 298.0;
r0 = 10000.0;
vm=(vcc / 5)*(v);
rntc = rAux / ((vcc/vm)-1);
R = rntc/r0;
tkelvin = beta/(log(R)+(beta/temp0));
t=tkelvin-273.15;
I know that the program is reading the temperature, but doesn't show anything in the graphic, it appears blank:

If I change the line 13 for:
plot(x,y1,'*', x,y2,'.')
It does write the data, but as every temperature is a different colour and the points aren't "connected", I think it is taking every point as a different graphic. Here is where my problem comes, because what I want to do is that all points are connected forming a line:

As you can see, it reads the variations of the temperature when I touch the sensor, so what I have is a problem when drawing, not when collecting data.
I also thought that it could be a problem because of the "pause" in line 11, but still doesn't draw anything in the graphic if I don't explicitly choose to write points or asterisks. What's more, in this case I cannot watch the graph live, just when I cancel the operation, the graphic appears with all the data collected from the start till the moment I cut it. So, if anybody could help me to plot it as a continuous line rather than a bunch os points or asterisks, I would be glad to hear your recommendations. Thanks in advance.
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!