How can I read the actual analog read?

36 次查看(过去 30 天)
Hi, MathWorks communities.
I have a question regarding the "readVoltage(a, ' ') command. When I run my code it shows a voltage data. But when I try to find the maximum or minimum value it shows something else. Can anyone tell me why it happens like that?
clear all;
a = arduino();
for r = 1:10
H(1,r) = readVoltage(a , 'A0')
pause(1);
end
ts = timeseries(H(1,:),1:length(H)); %(data)(time)
save('ardu1','ts','-v7.3')
This is the answer from command window.
H =
Columns 1 through 6
0.2639 0.2639 0.2639 0.2639 0.2639 0.2639
Columns 7 through 10
0.2639 0.2639 0.2688 0.2639
>> maximum = max('ardu1')
maximum =
117
>> minimum = min('ardu1')
minimum =
49
  1 个评论
SyukriY
SyukriY 2016-12-5
Because I want to calculate the temperature using the LM35 sensor. So, the calculation is like this.
temp = (5.0 * analogRead(A0) * 100.0) / 1024;
because the value from the analog read is like this somehow.
169 296 300 299 302

请先登录,再进行评论。

采纳的回答

SyukriY
SyukriY 2016-12-15
You can actually read the analog value using readVoltage.
You just need to make some calculation.
analog = readVoltage * (1023 / 5);

更多回答(1 个)

Walter Roberson
Walter Roberson 2016-12-5
max('ardu1') means to apply max() to the vector that is the character string 'a', 'r', 'd', 'u', '1'.
There is no MATLAB operator for finding the max() of a .mat file.
Consider max(H)
  4 个评论
SyukriY
SyukriY 2016-12-5
The data is stored in H. But the value is from 'readVoltage'. In the arduino, I get the analog value such as this [169 296 300 299 302]. But by reading the readVoltage the value is not the same. What should I do to get or (maybe convert the readVoltage value) to become the analog value.
SyukriY
SyukriY 2016-12-5
Because I noticed the value is not the same and with that, I cannot proceed with my thermistor calculation to get temperature value.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by