Specified PIN 16 and added some comments.

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

View File

@ -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(