Accurate Measurements with DHT11 and Arduino via MATLAB

64 visualizaciones (últimos 30 días)
B
B el 10 de Mayo de 2013
Editada: Victor el 29 de Jun. de 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 comentarios
Ishaan Chandratreya
Ishaan Chandratreya el 24 de Sept. de 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 el 30 de En. de 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

Iniciar sesión para comentar.

Respuesta aceptada

B
B el 17 de Mayo de 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 comentario
Philip Nahmias
Philip Nahmias el 24 de Jul. de 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.

Iniciar sesión para comentar.

Más respuestas (1)

Victor
Victor el 29 de Jun. de 2023
Editada: Victor el 29 de Jun. de 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

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by