Accurate Measurements with DHT11 and Arduino via MATLAB

67 Ansichten (letzte 30 Tage)
B
B am 10 Mai 2013
Bearbeitet: Victor am 29 Jun. 2023
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 Kommentare
Ishaan Chandratreya
Ishaan Chandratreya am 24 Sep. 2017
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 am 30 Jan. 2023
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

B
B am 17 Mai 2013
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 Kommentar
Philip Nahmias
Philip Nahmias am 24 Jul. 2018
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Victor
Victor am 29 Jun. 2023
Bearbeitet: Victor am 29 Jun. 2023
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

Kategorien

Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by