Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()
# read data using pin 14
instance = dht11.DHT11(pin=14)
while True:
result = instance.read()
if result.is_valid():
file = open('room.txt','a')
text = str(datetime.datetime.now()) + ',' + str(result.temperature) + ','
text += str(result.humidity) + '\n'
file.write(text)
file.close()
print("Last valid input: " + str(datetime.datetime.now()))
print("Temperature: %d C" % result.temperature)
print("Humidity: %d %%" % result.humidity)
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.