Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dht11 module issue #105

Open
TAHMINAISLAM673 opened this issue Feb 13, 2025 · 7 comments
Open

dht11 module issue #105

TAHMINAISLAM673 opened this issue Feb 13, 2025 · 7 comments

Comments

@TAHMINAISLAM673
Copy link

hello i am trying to get temperature and humidity using DHT11 sensor using resbi 4 B .But it says unable to set pin 4.I tried to another pin it still says same thing.

@TAHMINAISLAM673
Copy link
Author

TAHMINAISLAM673 commented Feb 13, 2025

import board
import adafruit_dht

dht = adafruit_dht.DHT11(board.D4)  # Change to DHT22 if using one

try:
    temp = dht.temperature
    humidity = dht.humidity
    print(f'Temperature: {temp}°C, Humidity: {humidity}%')
except RuntimeError as e:
    print(f"Error: {e}")

this is my code

@TAHMINAISLAM673
Copy link
Author

TAHMINAISLAM673 commented Feb 13, 2025

import sys
import time
import Adafruit_DHT

# Set pin to GPIO 4
pin = 4  

# Set sensor type to DHT11 (use 22 for DHT22)
sensor_type = 11  

try:
    while True:
        # Introduce a delay
        time.sleep(2)  

        # Read data from the sensor
        humidity, temperature = Adafruit_DHT.read_retry(sensor_type, pin)

        # Convert temperature to Fahrenheit
        fahrenheit = (temperature * 1.8) + 32  
        celsius = temperature  

        # Check if data is valid, then print; otherwise, show an error
        if humidity is not None and temperature is not None:
            print("Temperature: {:.1f}°C ({:.1f}°F)  Humidity: {:.1f}%".format(celsius, fahrenheit, humidity))
        else:
            print("Cannot read from device")

except KeyboardInterrupt:
    sys.exit()

when I use this code it says get platform

@caternuson
Copy link

I edited your post to add code markup to make them readable.

@caternuson
Copy link

Python is case sensitive, so your second code example is not importing correctly. Should result in some error on that line.

Your first code example looks generally OK.

But it says unable to set pin 4

What is the full text of the error message you get here?

@TAHMINAISLAM673
Copy link
Author

[/](url)

Image
Image

@TAHMINAISLAM673
Copy link
Author

Python is case sensitive, so your second code example is not importing correctly. Should result in some error on that line.

Your first code example looks generally OK.

But it says unable to set pin 4

What is the full text of the error message you get here?

My first code say unable to set pin 4 to inpuy

@caternuson
Copy link

The majority of the error message is not shown. Can you copy all the lines of error message text here instead of a photograph?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants