MATLAB libraries of DHT11 sensor

If the DHT11 sensor is connected to my Arduino and I want to read the temperature and humidity data directly from that pin of Arduino to which it is attached without the help of any arduino code, is there any Matlab library available for that?

1 Comment

Hi Sadiq,
Kindly reach out to MathWorks Technical Support to get help in resolving your query

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 20 Nov 2021

4 Comments

Thank you very much dear Walter Roberson for your prompt response. I have visited that earlier and I have tried that too but that doesn' work.
I have modefied that code like below:
clc
clear all
delete(instrfindall);
close(instrfindall);
s = serial('COM5');
time=100;
i=1;
while(i<time)
fopen(s)
fprintf(s, 'Your serial data goes here')
out = fscanf(s)
Temp(i)=str2double(out(1:4));% Temp(i)=str2num(out(1:4));
subplot(211);
disp(Temp(i))% By Me
plot(Temp(i),'g');% plot(Temp,'g');
axis([0,time,10,50]);
title('Parameter: DHT11 Temperature');
xlabel('time');
ylabel('Temperature');
grid
Humi(i)=str2double(out(5:9));
subplot(212);
disp(Humi(i))% By Me
plot(Humi(i),'m');
axis([0,time,10,100]);
title('Parameter: DHT11 Humidity');
xlabel('time');
ylabel('% of Humidity');
grid
fclose(s)
i=i+1;
drawnow;
end
delete(s)
clear s
But when I execute it in debugger mode, and I check the variable out, tooltp shows: out: 1 x 20 char=
Temperature: 18.00
Likewise when I check Temp(i), the debgger shows in tooltip as:
Temp: 1 x 20 double=
NaN
Also no any graph is displayed.
Hi! The answer would interest me as well :) When using Sadiq's modified code, I get:
Warning: Unsuccessful read: A timeout occurred before the Terminator was reached.
'serial' unable to read all requested data. For more information on possible reasons, see Serial Read Warnings.
out =
'nannannannannannannannan'
NaN
NaN
Some help would be great!
Sebi
If "out" is showing Temperature: 18.00 then the implication is that the data sent by the other side is not just numeric. If you know for sure that the "Temperature:" part is always going to be there then you can use fscanf() with a format of 'Temperature: %f' to read the numeric part directly, but if there might be a variety of text then you need to analyze the text to figure out which format to use.

Sign in to comment.

Categories

Find more on Instrument Control Toolbox in Help Center and File Exchange

Asked:

on 20 Nov 2021

Commented:

on 7 Dec 2022

Community Treasure Hunt

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

Start Hunting!