I am just trying to get a DHT11 sensor to play with me on a wemos d1 mini esp8266. I have 2 of them and both fail to read a value, that makes me wonder if I am the issue here as I still sometimes get the pin numbers wrong
I am just hoping someone can tell me if I have connected it correctly or if i am unlucky having 2 broken DHT11 sensors? That would be super helpful for me to understand what I am doing wrong here.
I am using 3.3V, GND and D4 (pin number 2?).
Code: Select all
from machine import Pin
from time import sleep
import dht
sensor = dht.DHT11(Pin(2))
while True:
try:
sleep(2)
sensor.measure()
t = sensor.temperature()
h = sensor.humidity()
print('Temperature: %3.1f C' %t)
print('Humidity: %3.1f %%' %h)
except OSError as e:
print('Sensor Reading Failed')