How to Fix "Failed to Read Sensor" Error on ESP32 with DHT22 in MicroPython?

Hey guys @Middleware & OS am building a Temperature and Humidity Monitoring System with ESP32 and DHT22 Sensor Using MicroPython, my aim is to create a temperature and humidity monitoring system using an ESP32 microcontroller and a DHT22(Temperature and humidity) sensor, read temperature and humidity data from the DHT22 sensor, display the data on the serial monitor and update the readings every 2 seconds. But i keep getting the error failed to read sensor here's my code
from machine import Pin
import dht
import time

# Initialize DHT22 sensor
sensor = dht.DHT22(Pin(16))

while True:
try:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
print('Temperature: %3.1f C' % temp)
print('Humidity: %3.1f %%' % hum)
except OSError as e:
print('Failed to read sensor.')
time.sleep(2)
from machine import Pin
import dht
import time

# Initialize DHT22 sensor
sensor = dht.DHT22(Pin(16))

while True:
try:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
print('Temperature: %3.1f C' % temp)
print('Humidity: %3.1f %%' % hum)
except OSError as e:
print('Failed to read sensor.')
time.sleep(2)
attachment 0
Solution:
Also could you check with a logic analyzer if the Data in pin is always high cuz If signal from DHT22 is always high-voltage-level, it means DHT22 is not working properly, please check the electrical connection status....
Jump to solution
2 Replies
melta101
melta1016mo ago
Could you share the entire log
Solution
melta101
melta1016mo ago
Also could you check with a logic analyzer if the Data in pin is always high cuz If signal from DHT22 is always high-voltage-level, it means DHT22 is not working properly, please check the electrical connection status.
Want results from more Discord servers?
Add your server