Skip to content

Instantly share code, notes, and snippets.

@ugeugeHigh
Created June 20, 2019 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugeugeHigh/a1d5b360b715905152c4213c073b8bfa to your computer and use it in GitHub Desktop.
Save ugeugeHigh/a1d5b360b715905152c4213c073b8bfa to your computer and use it in GitHub Desktop.
# 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