Skip to content

Instantly share code, notes, and snippets.

@li2hub
Last active April 2, 2019 11:04
Show Gist options
  • Save li2hub/32b6adefddc33e058c8ff17af8e9c7de to your computer and use it in GitHub Desktop.
Save li2hub/32b6adefddc33e058c8ff17af8e9c7de to your computer and use it in GitHub Desktop.
import Adafruit_DHT
from time import sleep
sensor = Adafruit_DHT.DHT11
pin = 4
while(1):
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}* Humidity={1:0.1f}%'.format(temperature, humidity))
else:
print('Failed to get reading. Try again!')
sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment