Raspberry Pi Pico W LESSON 20: Using the DHT11 Temperature and Humidity Sensor in MicroPython

preview_player
Показать описание
UPDATE: If you guys are getting errors with this lesson, try putting a second or two delay AFTER creating the sensor object:

sensor=DHT11(myPin)

Hope that helps.

You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:

In this class we will be using the Sunfounder Raspberry Pi Pico W Keppler Kit. It will make things a lot easier if we are working on identical hardware. the link below is to amazon, and is for the identical hardware I will be using in this entire class.

In this introductory video, I will show you how to use the DHT11 sensor to ready the temperature and humidity. We will implement the project using micropython. Enjoy!

#raspberrypipicoW
#dht11
#micropython
Рекомендации по теме
Комментарии
Автор

Hello friends, There is bug I canont figure out. So you dont spend hours like I did, I had to do a priming measure in a try/expect construct.## notSure, but I had to do a priming read of the sensor, without this this script would timeout. I hope this helps

## I kept getting a timeout error. I don't see it in other peoples code
## So not sure why my environment is special
try:
sensor.measure()
except:
time.sleep(5)

robakers
Автор

I also had the first read problem. After inserting a 2 second sleep after the sensor setup, everything works fine.

@Paul: thanks so much! A great series with projects that actually work and that I can understand, entertaining presentation and no irritating music!

pauldeheij
Автор

Another great lesson Paul... Love the new formatting of the Print Function. Will be implementing that in most of my future code. Thanks for recognizing Rob's contribution.

justmc
Автор

I am always behind I had a few problems! Thanks for making all these great lessons!

stephenlightkep
Автор

Thank you. The tutorial worked with the Keyestudio DHT11 which required +5v supply but worked just fine on the Pico's 3V3(OUT).

SirSurreal
Автор

Hi all, I know some have gotten errors when first reading the sensor [sensor.measure()] I too got the error too and did a little search on the DHT line of sensors. In the same way we need a second two between reads, the sensor seems to need a second between it being created/initialized and the first read. Rob's try/except with a 1 second sleep works fine or you can just put a one second sleep after you create the sensor object like I did.

keithlohmeyer
Автор

I AM LEGEND! The good news is that my solution works. The bad news is that I had to use the DHT-11 from my Raspberry Pi Raphael Kit because the Kepler kit DHT-11 does not work. After looking at the other comments I see that there is a work-around for that issue, which I will have to try. What I don't like about my solution is that the 1 second loop delay means that I have to hold the button down for a while to change between C and F. Thanks Paul for another most-excellent lesson.

cbrombaugh
Автор

Love the one line formatting. On a Mac you can type ° easily using the key combination option-shift-8.

brucemilyko
Автор

For the homework exercise, I can achieve the switch between f and C BUT since I am not using an interrupt the temp and humidity read only occurs when I press the button as well.

davidh
Автор

I used the dth11 module (3 prong) from the Elegoo "Most complete starter kit Mega 2560" bought for the Arduino course. After a little research and debugging I found the wiring of that module is not the same as the sensor Paul used with 4 pins. For the module I used, the data pin is on the left, the +5 in the center and the ground on the right. Even though that module has a pull-up resistor the code Paul taught works fine after I wired it correctly. Great lesson Paul and thanks for taking the time to share your knowledge in Engineering.

irvw
Автор

The "\r" hold in place, no scrolling is most interesting. 🥳 Thank you.

qzorn
Автор

Thanks Paul! I had to modify my code to get it to work. I used Rob Akers fix Thanks Rob.

stephenlightkep
Автор

Change print line to print("\r", 'Temp is', tempF, chr(176)+'F or', tempC, chr(176)+'C &', 'Humidity is', hum, '%', end='') it will show both F or C & H.

masmanst
Автор

I posted this comment on lesson 19 by mistake.
I've rather pre-empted what I think this week's homework will be with this solution as I won't be able to do any homework for at least 2 weeks.

I've previously used the dht11 and lcd1602 with the pico about 8 months ago when I was trying to do all of Paul's Raspberry Pi lessons using a pico. There's a link to the old (terrible) video in the description.

charlotteswift
Автор

I had an issue
File "<stdin>", line 10, in <module>
which was the sensor.measure() line. Quintuple checked everything then implemented Rob Ackers solution even though it was a different error it solved the issue. Thank you Paul I started this journey to learn how to make a vivarium controller with automated lights water and temperature and this lesson is exciting as it is directly related and I can envision doing it now exciting!

scottpegden
Автор

I am getting the following error message and tried the various fixes.(can't find Akers referred to fix, I have added multiple delays as recommended). I have a three prong DHT11 which I understand has a pull up resistor. wondering if that makes the difference. the message I receive is: MPY: soft reboot
Traceback (most recent call last):
File "<stdin>", line 33, in <module>
File "dht.py", line 1, in measure
OSError: [Errno 110] ETIMEDOUT

jbelmont
Автор

Hi Paul, I’ve been following this series, but maybe I’ve missed something. I’m confused with this DHT11. In your code you have myPin set as an output pin with a pull down resistor. I didn’t know this was even possible. I thought only input pins used pull up/down resisters to avoid pin floating? How do pull down resistors work with output pins? Why is it even an output pin if it’s reading in from the sensor? Lastly, looking at Rob Acker’s solution, he has it set as a pull up resistor, not pull down? I’m so confused.

GCRickerNH
Автор

Hi Paul, great video like always! I have a question for you. Are you planning some series about ESP32? It would be great to see you making videos about programming this especially in C language but micropython would be good too.

patrykuczak
Автор

Paul, Will you be covering tensorflow lite?, which is used to run Machine learning models using Pico

vishwanathmali
Автор

Cool video perfect for my first pico project. I have an 11 on hand. Is there a on board temp and humidity sensor ? I think I heard some mention of it somewhere.

Ducerobot