How can I read the actual analog read?

54 visualizzazioni (ultimi 30 giorni)
SyukriY
SyukriY il 5 Dic 2016
Risposto: SyukriY il 15 Dic 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 Commento
SyukriY
SyukriY il 5 Dic 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

Accedi per commentare.

Risposta accettata

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

Più risposte (1)

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

Accedi per commentare.

Categorie

Scopri di più su Arduino Hardware in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by