How can I read the actual analog read?

54 views (last 30 days)
SyukriY
SyukriY on 5 Dec 2016
Answered: SyukriY on 15 Dec 2016
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 Comment
SyukriY
SyukriY on 5 Dec 2016
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

Sign in to comment.

Accepted Answer

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

More Answers (1)

Walter Roberson
Walter Roberson on 5 Dec 2016
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 Comments
SyukriY
SyukriY on 5 Dec 2016
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 on 5 Dec 2016
Because I noticed the value is not the same and with that, I cannot proceed with my thermistor calculation to get temperature value.

Sign in to comment.

Categories

Find more on Arduino Hardware 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!