Accurate Measurements with DHT11 and Arduino via MATLAB

조회 수: 64 (최근 30일)
B
B 2013년 5월 10일
편집: Victor 2023년 6월 29일
I have a DHT11 sensor connected to an Arduino UNO. I can get consistent (and expected) data values through the Arduino software by following this tutorial. However, I'd like to replicate the same data collection with MATLAB.
I'm stuck on how I can take the DHT11's digital signal and "break it down" into its component bits so that they can be identified and used properly. From my understanding, the DHT11's signal is 40 bits, and is set up so that the first 16 relate to the humidity detected, the following 16 are for temperature, and the last 8 are the checksum.
Is it possible to separate a digital signal into a collection of bits? How can I use MATLAB to get measurements from this sensor?
  댓글 수: 4
Ishaan Chandratreya
Ishaan Chandratreya 2017년 9월 24일
I am wishing to read DHT11 using a raspberry pi on MATLAB. Could anyone help me with that? I have already tried reading GPIO pin as sensor transmits data, and have tried connecting rx to data, and using serialdev of raspberry pi package
Jan Schäfer
Jan Schäfer 2023년 1월 30일
You must load the Adafruit/DHTxx library in to Matlab. After this you can write a = arduino('COM12', 'Uno', 'Libraries', 'Adafruit/DHTxx');
readHumdity(a,Pin)
readTemperature(a,Pin)
good luck

댓글을 달려면 로그인하십시오.

채택된 답변

B
B 2013년 5월 17일
My final code, for readings once a minute:
s = serial('COM3'); %Connected to COM3
set(s,'BaudRate',9600);
set(s,'Timeout', 65); %sensor will timeout after 65 seconds
fopen(s);
x = 1:1:60; %readings over the span of one hour
for i=1:length(x)
y(i) = fscanf(s, '%f', 6);
z(i) = fscanf(s, '%f', 6);
i
end
fclose(s);
% Plot data from arduino
plot3(x,y,z)
title('temperature v. humidity v. time');
xlabel('time');
ylabel('humidity');
zlabel('temperature');
  댓글 수: 1
Philip Nahmias
Philip Nahmias 2018년 7월 24일
I am faced with a similar situation like you and I am a bit confused on how you were able to resolve your situation. First of all did you have an arduino package on matlab or did you just define the connection as serial? Cause I was under the impression I had to download some arduino package and I haven't managed to make it work.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Victor
Victor 2023년 6월 29일
편집: Victor 2023년 6월 29일
clear
s = serialport('COM3',9600)
time=100;
subplot(211)
h1=animatedline('Color','r');axis([1,time,10,40]),grid on
ylabel('Temperatura (°C)')
subplot(212)
h2=animatedline('Color','b');axis([1,time,40,80]),grid on
xlabel('iteraciones'),ylabel('Humedad (%)')
for i=1:time
out = read(s,7,'string');
if rem(i,2) == 0
Humi=str2double(out);
addpoints(h2,i,Humi)
else
Temp=str2double(out);
addpoints(h1,i,Temp)
end
end

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by