Skip to content

szazo/DHT11_Python

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
March 24, 2020 14:57
May 11, 2016 11:10
March 24, 2020 14:49
May 24, 2020 22:39

DHT11 Python library

This simple class can be used for reading temperature and humidity values from DHT11 sensor on Raspberry Pi.

Installation

To install, just run following:

pip install dht11

Usage

  1. Instantiate the DHT11 class with the pin number as constructor parameter.
  2. Call read() method, which will return DHT11Result object with actual values and error code.

For example:

import RPi.GPIO as GPIO
import dht11

# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()

# read data using pin 14
instance = dht11.DHT11(pin = 14)
result = instance.read()

if result.is_valid():
    print("Temperature: %-3.1f C" % result.temperature)
    print("Humidity: %-3.1f %%" % result.humidity)
else:
    print("Error: %d" % result.error_code)

For working example, see dht11_example.py (you probably need to adjust pin for your configuration)

License

This project is licensed under the terms of the MIT license.

About

Pure Python library for reading DHT11 sensor on Raspberry Pi

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages