How can I read the actual analog read?

54 ビュー (過去 30 日間)
SyukriY
SyukriY 2016 年 12 月 5 日
回答済み: SyukriY 2016 年 12 月 15 日
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 Center および File ExchangeArduino Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by