Accurate Measurements with DHT11 and Arduino via MATLAB

68 visualizzazioni (ultimi 30 giorni)
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 Commenti
Ishaan Chandratreya
Ishaan Chandratreya il 24 Set 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 il 30 Gen 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

Accedi per commentare.

Risposta accettata

B
B il 17 Mag 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 Commento
Philip Nahmias
Philip Nahmias il 24 Lug 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.

Accedi per commentare.

Più risposte (1)

Victor
Victor il 29 Giu 2023
Modificato: Victor il 29 Giu 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

Categorie

Scopri di più su MATLAB Support Package for Arduino Hardware in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by