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

  Рет қаралды 10,052

Paul McWhorter

Paul McWhorter

Күн бұрын

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)
time.sleep(2)
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:
/ paulmcwhorter
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.
amzn.to/3ubMRs1
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!
[Disclosure of Material Connection: I am a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com. ]
#raspberrypipicoW
#dht11
#micropython

Пікірлер: 93
@robakers6127
@robakers6127 Жыл бұрын
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)
@robakers6127
@robakers6127 Жыл бұрын
here is the final solution: kzbin.info/www/bejne/ZnbCY2eCj8yMp9k - As always all comments are welcome
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@justmc62
@justmc62 Жыл бұрын
Thank you so much for your solution. I did not get to the homework yet but could not get Paul's lesson to run correctly either. Kept getting an " OSError: [Errno 110] ETIMEDOUT" . I tried using a 3 pin DHT11 I had from an Elegoo kit I purchased for Paul's Arduino course but to no avail. The 3 pin was a module type with an onboard resistor . Tried code with PULL_DOWN, PULL_UP and no internal Pico resistor. Nothing worked but your try: except: with the Sunfounder supplied 4 pin DHT11 ... Hmmm. 😕
@lorisrobots
@lorisrobots Жыл бұрын
I was getting a timeout error as well. When I used a DHT-11 already on a breakout board (with three pins - purchased separately), it worked as Paul showed. With the DHT-11 from our kit, I found your code worked (just using your try except construct). Thanks!
@alexandrlysyuk335
@alexandrlysyuk335 6 ай бұрын
I have changed from PULL_DOWN to PULL_UP resistor line. If anyone can explain why it helps it would be great.. And Everything works without any sleep(1) delay #sensorPin= Pin(dataPin,Pin.OUT,Pin.PULL_DOWN) sensorPin= Pin(dataPin,Pin.OUT, Pin.PULL_UP)
@pauldeheij8350
@pauldeheij8350 Жыл бұрын
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!
@ChrisWalters-b1g
@ChrisWalters-b1g Ай бұрын
Just want to say a big thank you Paul. Your videos are really helpful.
@irvw4510
@irvw4510 10 ай бұрын
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.
@NebulaNuggets3
@NebulaNuggets3 6 ай бұрын
Hey man, I had a question I am using the same dht11 module but I've wired it the exact same as you except when I run the code, I keep getting the OSError: [Errno 110] ETIMEDOUT. Have you experienced this and if so how did you fix it?
@austencook1036
@austencook1036 Ай бұрын
@@NebulaNuggets3 i fixed it underneath the sensor declaration with sensor=DHT11(myPin) and underneath time.sleep(2)
@cbrombaugh
@cbrombaugh Жыл бұрын
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.
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@justmc62
@justmc62 Жыл бұрын
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.
@stephenlightkep1621
@stephenlightkep1621 Жыл бұрын
I am always behind I had a few problems! Thanks for making all these great lessons!
@SirSurreal
@SirSurreal Жыл бұрын
Thank you. The tutorial worked with the Keyestudio DHT11 which required +5v supply but worked just fine on the Pico's 3V3(OUT).
@brucemilyko8549
@brucemilyko8549 11 ай бұрын
Love the one line formatting. On a Mac you can type ° easily using the key combination option-shift-8.
@andthatswhy5198
@andthatswhy5198 Ай бұрын
thank you for the error-fixer in the description!, i was getting an error but its fixed now
@qzorn4440
@qzorn4440 Жыл бұрын
The " " hold in place, no scrolling is most interesting. 🥳 Thank you.
@keithlohmeyer
@keithlohmeyer Жыл бұрын
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.
@cbrombaugh
@cbrombaugh Жыл бұрын
Many thanks to Rob Akers and Keith Lohmeyer for providing the fix for the DHT-11 problem. After beating my head against the wall for a couple hours, I finally switched to the DHT-11 from my Raspberry Pi Raphael kit and it worked fine, so I concluded that the DHT-11 in my Kepler kit is defective. After reading Keith's comment I simply added a 1 second delay after creating the sensor object. And voila! both sensors now work.
@ke7uia
@ke7uia Жыл бұрын
Oh, my I did receive an error that did not make much sense. Yes, I did hold my breath while running. The error was, ' File "", line 12, in '. The line was 'sensor.measure()'. So I placed a 'time.sleep(1)' after the 'sensor=DHT11(myPin)'.
@davidh1187
@davidh1187 6 ай бұрын
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.
@MorrWorm8
@MorrWorm8 11 ай бұрын
This channel is top of its class!!
@stephenlightkep1621
@stephenlightkep1621 Жыл бұрын
Thanks Paul! I had to modify my code to get it to work. I used Rob Akers fix Thanks Rob.
@scottpegden4550
@scottpegden4550 Жыл бұрын
I had an issue File "", line 10, in 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!
@lucarennabass
@lucarennabass 9 ай бұрын
HI, I have the same issue, could you please post the solution you implemented? Thank you!
@masman1st
@masman1st 2 ай бұрын
Most interesting, on ESP32 depending on what GPO Pin is used changes where the time.sleep (argument ?) statement line has to be. On one Pin it is above (while True:), on another Pin it is after (while True:), yet on a different Pin it is the last line at the bottom. An then there was one Pin that sleep was needed in two places.
@Ed-fv9rl
@Ed-fv9rl Жыл бұрын
Thanks Paul! I m late because, I moved back to USA from Portugal. Working on catching up. 😊
@paulmcwhorter
@paulmcwhorter Жыл бұрын
Welcome back. Now, get CAUGHT UP!
@edSabio572
@edSabio572 Жыл бұрын
@@paulmcwhorter Hi Paul: When I tried to run the program, dht is not present. tried to install using tools menu, but have the following message: "Could not fetch search results: " I could use some advise from the team...
@Ed-fv9rl
@Ed-fv9rl Жыл бұрын
@@edSabio572 Thanks Paul, I had to recreate my profile, get a new email Account. But I was able to continue my work. The certificate issue is gone after I changed my profile and resynced my computer to US time. I will catch up soon...
@Ducerobot
@Ducerobot Жыл бұрын
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.
@zoro.73
@zoro.73 Жыл бұрын
picoW has an onboard temp sensor connected to ADC4
@patrykuczak1975
@patrykuczak1975 Жыл бұрын
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.
@jbelmont72
@jbelmont72 10 ай бұрын
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 "", line 33, in File "dht.py", line 1, in measure OSError: [Errno 110] ETIMEDOUT
@todd3c
@todd3c 8 ай бұрын
After you create an instance of the sensor put in a sleep of 1 second.
@israelpurdum9470
@israelpurdum9470 9 ай бұрын
I am trying to do this same project, but when I type the .measure() command the shell gives me the error code: Traceback (most recent call last): File "", line 12, in File "dht.py", line 1, in measure OSError: [Errno 110] ETIMEDOUT
@olisad5413
@olisad5413 9 ай бұрын
Hi I had the same problem. I'm using the 3 pin DHT11 not sure if you do as well. But in the example he uses DHT11 with the pull down resistor. I think the 3 pins have something of a pull up resistor. So, following the same code in the video, change line 7 to: myPin= Pin(dataPin, Pin.IN, Pin.PULL_UP). This worked for me. Hope it helps :)
@GCRickerNH
@GCRickerNH Жыл бұрын
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.
@keithlohmeyer
@keithlohmeyer Жыл бұрын
The sensor uses a one wire protocol so in the DHT library module a request for data is sent and data is returned over the same pin. I assume that the pin is changed between input and output in the library. In Arduino we use an external pull down resistor on the data pin so I guess using the internal pull down makes the circuit easier. Also I think Rob's issue with his code is because he used pull up instead of pull down but that is just a guess.
@charlotteswift
@charlotteswift Жыл бұрын
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. Here's the new video: kzbin.info/www/bejne/o5fcnoyondWFsLs
@masman1st
@masman1st 2 ай бұрын
Change print line to print(" ", 'Temp is',tempF,chr(176)+'F or',tempC,chr(176)+'C &','Humidity is',hum,'%',end='') it will show both F or C & H.
@iampad545
@iampad545 Жыл бұрын
Paul, will you be covering raspberry pi pico PIO assembly coding?
@robakers6127
@robakers6127 Жыл бұрын
I have been looking at this to. Not so sure I understand much other than a couple of videos. I looked at books for Assember, but could not determine which one was the best. Anyone have any suggestions?
@keithlohmeyer
@keithlohmeyer Жыл бұрын
@@robakers6127 My understanding is PIO has a very limited cmd set so I would think a general book on assembly language would be less helpful. In my mind PIO is for the people that write libraries that need super fast execution such as Neopixels or audio.
@iampad545
@iampad545 Жыл бұрын
@@robakers6127 Had hoped Paul would be covering this incredible feature of the pi pico. The I/O using this becomes incredibly powerful. Let you know if I find out any more about it.
@keithlohmeyer
@keithlohmeyer Жыл бұрын
@@iampad545 Hi a good place to start is the rp2040 datasheet section 3. The Micro Python docs only have a one page tutorial and example that I see but there are quite a few YT vids on it. Adafruit also has a tutorial and some example code but it is based on their Circuit Python implementation of the PIO using their library modules. It is still an interesting read. Hope this helps.
@marciuse70
@marciuse70 4 ай бұрын
Hi! I get an error when I run the code. I search Google about this unsuccessfully. Can someone help me? Does anyone has the some error? from machine import Pin import utime as time from dht import DHT11 dataPin = 16 myPin = Pin(dataPin,Pin.OUT,Pin.PULL_DOWN) sensor = DHT11(myPin) while True: sensor.measure() tempC = sensor.temperature() hum = sensor.humidity() print(tempC, hum) time.sleep(1) MPY: soft reboot Traceback (most recent call last): File "", line 11, in File "dht.py", line 1, in measure OSError: [Errno 110] ETIMEDOUT
@Video_editor2003
@Video_editor2003 8 ай бұрын
AttributeError: 'DHT11' object has no attribute 'measure' how to tackle this error sir
@scottwait3585
@scottwait3585 Жыл бұрын
Thank you Paul!
@vishwanathmali4338
@vishwanathmali4338 Жыл бұрын
Paul, Will you be covering tensorflow lite?, which is used to run Machine learning models using Pico
@paulmcwhorter
@paulmcwhorter Жыл бұрын
I cover that in the Raspberry PI class. Dont think pico is powerful enough for tensorflow lite
@FranciscoCruz-jg7gc
@FranciscoCruz-jg7gc 6 ай бұрын
I fixed the error by adding the sensor.measure() outside the loop time.sleep(1) sensor.measure() time.sleep(1)
@FranciscoCruz-jg7gc
@FranciscoCruz-jg7gc 6 ай бұрын
time.sleep(1) sensor.measure() time.sleep(1) adding those lines fixed it
@rupadarshisamanta3288
@rupadarshisamanta3288 10 ай бұрын
from machine import Pin, I2C import utime as time from dht import DHT11 dataPin=28 myPin=Pin(dataPin,Pin.OUT,Pin.PULL_DOWN) sensor=DHT11(myPin) print('My Sensor Data') while True: sensor.measure() tempC=sensor.temperature() hum=sensor.humidity() print(" ", tempC,hum, end='') time.sleep(1), when i used this code i faced this error continuously.- Traceback (most recent call last): File "", line 11, in File "dht.py", line 1, in measure OSError: [Errno 110] ETIMEDOUT, please help me.
@mattclark2367
@mattclark2367 9 ай бұрын
where you able to find a solution? i am having the same bug.
@fornogg
@fornogg 8 ай бұрын
The way I ended up getting this to work for anyone getting the error, is by connecting the sensor to VBUS instead of 3V3(OUT)
@PhysicsAssignmentHelp
@PhysicsAssignmentHelp Жыл бұрын
I've written the code, but i'm getting operator system error with .measure(). Does anyone else have this issue too?
@keithlohmeyer
@keithlohmeyer Жыл бұрын
Try adding a one second delay after creating the sensor object. That worked for me.
@PhysicsAssignmentHelp
@PhysicsAssignmentHelp Жыл бұрын
@@keithlohmeyer I did this right now, it works. Thank you Keith!
@Ed-fv9rl
@Ed-fv9rl Жыл бұрын
Adding 1 sec always works. Also
@keithlohmeyer
@keithlohmeyer Жыл бұрын
Homework complete kzbin.info/www/bejne/o6XSq6yNZZ2siJI Others were commenting about buttons not being very responsive. I show how I get around that problem.
@paulmcwhorter
@paulmcwhorter Жыл бұрын
Excellent, thanks for posting.
@LorisHW
@LorisHW Жыл бұрын
Here is my homework. Thanks to Rob Akers for his code to deal with the timeout error. kzbin.info/www/bejne/lYuWhmlomdqLmKs
@briankelly4095
@briankelly4095 Жыл бұрын
Hi Paul. My lesson 20 homework can be found at kzbin.info/www/bejne/jJe4ZqutotmLj80 Another classmate & I were coding along with you during the lesson and found that neither of our programs worked. We each needed a sleep statement that you didn't seem to need. Fascinating. I wound up with a sleep statement in the 'while True' loop of my homework too. It makes the pushbutton a little unresponsive. No worries for this application but other uses might need an alternate approach. Here's my vote for learning about Pico W interrupts when you think the time is right. Thanks for all the great course material Paul.
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@snowman58able
@snowman58able Жыл бұрын
I am legend. I made one mistake by having my sleep time in the wrong place and corrected it. I also could not remember how to limit my Fahrenheit to one decimal place.
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@Bob-zg2zf
@Bob-zg2zf Жыл бұрын
I'm glad you cough less often now.
@Wythaneye
@Wythaneye Жыл бұрын
Better late than never, my homework for lessons #20 and #21: kzbin.info/www/bejne/jJrHpqt9rdeChck
@inchworm9311
@inchworm9311 Жыл бұрын
I think my DHT11 is busted, so instead I used the built-in temp sensor on the pico W: adcPin = 4 sensor = machine.ADC(adcPin) adcVal = sensor.read_u16() voltage = (3.3/65535) * adcVal temperature = 27 - (voltage - 0.706)/0.001721 Hope that helps anybody else w a broken sensor
@kev67uk
@kev67uk Жыл бұрын
Another brilliant lesson Paul, thank you. My homework is here, with a basic, slightly buggy version, and a slightly more improved version at the end 😉 kzbin.info/www/bejne/qWe6ppWYgq6MY6c Looking forward to next week's lesson so I can see how we were supposed to do it 😁.
@freddyveza
@freddyveza Жыл бұрын
My homework link, using timers kzbin.info/www/bejne/jabafXWnoLaYfNU
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@todd3c
@todd3c 8 ай бұрын
!!!!!!!!!!! IF using the sensor from the kit CHANGE DHT22 to DHT11 (I had a DHT22 in my junk box and used it) from machine import Pin import utime as time from dht import DHT22 dataPin =16 # setup the DHT22 myPin=Pin(dataPin, Pin.OUT, Pin.PULL_DOWN) sensor = DHT22(myPin) time.sleep(1) # Wait 1 second AFTER setting up the sensor otherwise you'll get a data error butPin=14 # Button setup myButton = Pin(butPin, Pin.IN,Pin.PULL_UP) toggle = False butLastState = 1 while True: try: if myButton.value() == 0 and butLastState: # Button PRESSED toggle = not toggle #Toggle between C & F for the temp butLastState = 0 elif myButton.value() ==1: # Button released get ready for next press butLastState = 1 sensor.measure() temp=sensor.temperature() hum=sensor.humidity() if not toggle: fc = 'C' else: fc='F' temp=((temp*9)/5)+32 print(" ","Temp =",str(temp)+chr(176)+fc, " Humidity =",str(hum)+'%', end=' ') time.sleep(1) except KeyboardInterrupt: break except: print("Data error from sensor")
@jameslewellen150
@jameslewellen150 Жыл бұрын
Here is this weeks homework. Nice video Link: kzbin.info/www/bejne/fZDZYpaGa8Shh5Y
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@TheTechRancher
@TheTechRancher Жыл бұрын
My Homework Link: kzbin.info/www/bejne/eqqrnHmjaMljes0 Another great video Paul. Looking forward to the next lesson.
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@karliskide2460
@karliskide2460 Жыл бұрын
Thank you for an amazing lesson! Here is my homework assignment for this one: kzbin.info/www/bejne/sH_Kh5uHl7J8nrM The measurement does not look very precise, it seems like DHT11 heats up internally.
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@davidgoldsmith7475
@davidgoldsmith7475 11 ай бұрын
I get the error messge Traceback (most recent call last): File "", line 12, in File "dht.py", line 1, in measure OSError: [Errno 110] ETIMEDOUT I have used this code on another Raspberry Pico W and it worked fine. I have tried the sleep(1) solution but it does not stop the "dht.py" error.
@jbelmont72
@jbelmont72 10 ай бұрын
I'm getting the same message. What was your solution please?
@rupadarshisamanta3288
@rupadarshisamanta3288 9 ай бұрын
Yeah same problem. Did you figure out the solution?
@mikeshipley3509
@mikeshipley3509 9 ай бұрын
same problem here.
@mikeshipley3509
@mikeshipley3509 9 ай бұрын
does anyone have a dht.py in their thonny program folder? There are lots of them & that one is called for.
@JulioGuevara-nl6yf
@JulioGuevara-nl6yf 9 ай бұрын
I just change the pull resistor from DOWN to UP and it seems to work fine. Hope it helps
Raspberry Pi Pico W: Wireless Weather Station
17:13
ExplainingComputers
Рет қаралды 291 М.
龟兔赛跑:好可爱的小乌龟#short #angel #clown
01:00
Super Beauty team
Рет қаралды 27 МЛН
Don't look down on anyone#devil  #lilith  #funny  #shorts
00:12
Devil Lilith
Рет қаралды 46 МЛН
Это было очень близко...
00:10
Аришнев
Рет қаралды 3,7 МЛН
How to use VH,VW,EM,REM and flex order in CSS
36:56
Brammatech
Рет қаралды 4
How to read the temperature sensor on the Raspberry Pi Pico
13:08
learnelectronics
Рет қаралды 30 М.
Get Started in Electronics #9 - Using the DHT11 Humidity & Temp Sensor
15:33
DHT11 and DHT22 Temp & Humidity Sensors on Raspberry PI and Arduino
16:17
How To Use A Relay With Raspberry Pi Pico
11:59
Core Electronics
Рет қаралды 27 М.
龟兔赛跑:好可爱的小乌龟#short #angel #clown
01:00
Super Beauty team
Рет қаралды 27 МЛН