From e5ccca564042da4dcc54165231a97c413b0db63a Mon Sep 17 00:00:00 2001 From: Kshitij Date: Mon, 7 Oct 2024 00:43:47 +0530 Subject: [PATCH] Specified PIN 16 and added some comments. --- temp-calc.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/temp-calc.py b/temp-calc.py index 6843426..cabddd5 100644 --- a/temp-calc.py +++ b/temp-calc.py @@ -1,12 +1,13 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# SPDX-License-Identifier: MIT +# Specify the pin you'll be connecting the data/signal PIN of DHT11 to here: +PIN = 16 +DPIN = "D" + PIN import time -import board +from board import PIN # By default I'm using GPIO PIN 16 import adafruit_dht # Initial the dht device, with data pin connected to: -dhtDevice = adafruit_dht.DHT22(board.D18) +dhtDevice = adafruit_dht.DHT11(DPIN) # you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio. # This may be necessary on a Linux single board computer like the Raspberry Pi, @@ -16,8 +17,8 @@ dhtDevice = adafruit_dht.DHT22(board.D18) while True: try: # Print the values to the serial port - temperature_c = dhtDevice.temperature - temperature_f = temperature_c * (9 / 5) + 32 + temperature_c = dhtDevice.temperature # Celsius + temperature_f = temperature_c * (9 / 5) + 32 # Fahrenheit humidity = dhtDevice.humidity print( "Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format(