# Adafruit\_DHT11 with RPi 4b

**URL:** <https://forum.sunfounder.com/t/adafruit-dht11-with-rpi-4b/4420>\
**Category:** General Discussion\
**Created:** [February 25, 2026, 4:53pm UTC](https://forum.sunfounder.com/t/adafruit-dht11-with-rpi-4b/4420 "2026-02-25T16:53:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rolph](https://avatars.discourse-cdn.com/v4/letter/r/b9bd4f/32.png) [@Rolph](https://forum.sunfounder.com/u/Rolph)\
**Post date:** [February 25, 2026, 4:53pm UTC](https://forum.sunfounder.com/t/adafruit-dht11-with-rpi-4b/4420/1 "2026-02-25T16:53:06Z")

</div>

Hi there,

I’m quite new to RPi and was working on the tutorials of Paul McWorther.

Now I came across the DHT11 temperature sensor where I was first notified about the ‘unkown platform error’ which I understand is linked to me using the RPi 4b (instead of older versions). With many searches I managed to work around this error but now I get the message ‘int’ object not callable. If you can help me out would be appreciated.

Here is the code I’m using:

import RPi.GPIO as GPIO  
import Adafruit\_DHT  
import digitalio  
import board  
import time

# Initial the dht device, with data pin connected to GPIO4

sensor = Adafruit\_DHT.DHT11(board.D4)

while True:  
try:

# Print the values to the serial port

temperature\_c = sensor.temperature  
humidity = sensor.humidity  
print("Temp: {:.1f} C Humidity: {}% ".format(temperature\_c, humidity))

```auto
except RuntimeError as error:
    # Errors happen fairly often, DHT's are hard to read, just keep going
    print(error.args[0])
    time.sleep(2.0)
    continue
except Exception as error:
    sensor.exit()
    raise error

time.sleep(2.0)

```

---

<div class="post-metadata">

**Author:** ![Spf650](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@Spf650](https://forum.sunfounder.com/u/Spf650)\
**Post date:** [February 25, 2026, 7:17pm UTC](https://forum.sunfounder.com/t/adafruit-dht11-with-rpi-4b/4420/2 "2026-02-25T19:17:54Z")

</div>

Possibly because of this line….

```auto
sensor = Adafruit_DHT.DHT11(board.D4)

```

Adafruit\_DHT.DHT11 is actually an int constant, not a class.

Just a best guess

---

<div class="post-metadata">

**Author:** ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)\
**Post date:** [February 26, 2026, 7:12am UTC](https://forum.sunfounder.com/t/adafruit-dht11-with-rpi-4b/4420/3 "2026-02-26T07:12:22Z")

</div>

The error “int object not callable” happens because two different DHT libraries are being mixed together in the code.

In your current script, this line:

sensor = Adafruit\_DHT.DHT11(board.D4)

is the issue.

Adafruit\_DHT.DHT11 is actually just an integer constant, not a function. So Python is trying to “call” an integer, which causes the error.

If you are following Paul McWhorter’s tutorial, please modify your code like this:

import Adafruit\_DHT

import time

sensor = Adafruit\_DHT.DHT11

pin = 4 # GPIO4

while True:

```
humidity, temperature = Adafruit_DHT.read(sensor, pin)

if humidity is not None and temperature is not None:

    print(f"Temp: {temperature:.1f} C Humidity: {humidity}%")

else:

    print("Sensor failure. Please check wiring.")

time.sleep(2)

```

---

<div class="post-metadata">

**Author:** ![Rolph](https://avatars.discourse-cdn.com/v4/letter/r/b9bd4f/32.png) [@Rolph](https://forum.sunfounder.com/u/Rolph)\
**Post date:** [February 28, 2026, 7:55am UTC](https://forum.sunfounder.com/t/adafruit-dht11-with-rpi-4b/4420/4 "2026-02-28T07:55:46Z")

</div>

> [@SunFounder\_Moderator](#):
>
> import Adafruit\_DHT
> 
> import time
> 
> sensor = Adafruit\_DHT.DHT11
> 
> pin = 4 # GPIO4
> 
> while True:
> 
> ```auto
> humidity, temperature = Adafruit_DHT.read(sensor, pin)
> 
> if humidity is not None and temperature is not None:
> 
> print(f"Temp: {temperature:.1f} C Humidity: {humidity}%")
> 
> else:
> 
> print("Sensor failure. Please check wiring.")
> 
> time.sleep(2)
> 
> ```

Hello, and many thanks for your response to my question.  
However, I already tried this, and tried now once more, but with this code the following error is raised:

RuntimeError(‘Unknown platform’)

As I understand this has to do with the fact that I run this code on a RPi 4b which is apparently not defined in “platform\_detect.py”. If you might have an idea how to solve this issue, would be appreciated.

---

<div class="post-metadata">

**Author:** ![Rolph](https://avatars.discourse-cdn.com/v4/letter/r/b9bd4f/32.png) [@Rolph](https://forum.sunfounder.com/u/Rolph)\
**Post date:** [February 28, 2026, 7:56am UTC](https://forum.sunfounder.com/t/adafruit-dht11-with-rpi-4b/4420/5 "2026-02-28T07:56:40Z")

</div>

Hi Spf650,

Thanks for your suggestion. Do you perhaps also know how to define it as a class?  
Any suggestion is welcome.

---

<div class="post-metadata">

**Author:** ![Spf650](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@Spf650](https://forum.sunfounder.com/u/Spf650)\
**Post date:** [February 28, 2026, 8:22am UTC](https://forum.sunfounder.com/t/adafruit-dht11-with-rpi-4b/4420/6 "2026-02-28T08:22:50Z")

</div>

Im not an expert here. All i can give you is generic debug information rather than anything specific to adafruit

For the unknown platform error, You could try basic stuff like

sudo apt update  
sudo apt install python3-blinka  
sudo reboot

But, You would need to give a lot more information for me to have a chance e.g exact os that you are using, using a venv? Inside a docker?

Probably better to do a general google, as you already said you’ve solved this previously anyway.

---

<div class="post-metadata">

**Author:** ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)\
**Post date:** [March 2, 2026, 10:00am UTC](https://forum.sunfounder.com/t/adafruit-dht11-with-rpi-4b/4420/7 "2026-03-02T10:00:07Z")

</div>

The error you’re seeing — RuntimeError: ‘Unknown platform’ — is not caused by your wiring or Python syntax. It happens because the Adafruit\_DHT library is an older driver and it may not recognize newer Raspberry Pi OS, such as Bookwarm, Trixie, so it reports “Unknown platform”.

The best solution is to use a newer, actively maintained DHT library.

1. Install dependencies

sudo apt update

sudo apt install -y python3-pip libgpiod2

1. Install the modern DHT library

pip3 install adafruit-circuitpython-dht --break-system-packages

1. Test script

import time

import board

import adafruit\_dht

# GPIO4

dht = adafruit\_dht.DHT11(board.D4)

while True:

```
try:

    temperature = dht.temperature

    humidity = dht.humidity

    print(f"Temp: {temperature}°C Humidity: {humidity}%")

except RuntimeError as e:

    \# DHT sensors can occasionally fail a read — retrying is normal

    print("Read error:", e)

time.sleep(2)

```
