Specified PIN 16 and added some comments.

This commit is contained in:
K 2024-10-07 00:43:47 +05:30
parent 0f6cdc5ee3
commit 6c71b27f3f
Signed by: notkshitij
GPG Key ID: C5B8BC7530F8F43F

View File

@ -1,12 +1,13 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # Specify the pin you'll be connecting the data/signal PIN of DHT11 to here:
# SPDX-License-Identifier: MIT PIN = 16
DPIN = "D" + PIN
import time import time
import board from board import PIN # By default I'm using GPIO PIN 16
import adafruit_dht import adafruit_dht
# Initial the dht device, with data pin connected to: # 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. # 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, # 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: while True:
try: try:
# Print the values to the serial port # Print the values to the serial port
temperature_c = dhtDevice.temperature temperature_c = dhtDevice.temperature # Celsius
temperature_f = temperature_c * (9 / 5) + 32 temperature_f = temperature_c * (9 / 5) + 32 # Fahrenheit
humidity = dhtDevice.humidity humidity = dhtDevice.humidity
print( print(
"Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format( "Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format(