Created
June 20, 2019 23:53
-
-
Save ugeugeHigh/a1d5b360b715905152c4213c073b8bfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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