Added code and softcopy for assignment 4.
This commit is contained in:
parent
30a5b7e7f4
commit
20bb617826
36
Practical/Assignment-4/IoT - Code-4.py
Normal file
36
Practical/Assignment-4/IoT - Code-4.py
Normal file
@ -0,0 +1,36 @@
|
||||
"""
|
||||
THIS CODE HAS BEEN TESTED ON RASPBERRY PI 3B, 4B AND IS FULLY OPERATIONAL.
|
||||
|
||||
Problem Statement: Temperature and humidity sensing using DHT11.
|
||||
|
||||
Code from InternetOfThingsAndEmbeddedSystems (SPPU - Third Year - Computer Engineering - Content) repository on KSKA Git: https://git.kska.io/sppu-te-comp-content/InternetOfThingsAndEmbeddedSystems
|
||||
"""
|
||||
|
||||
# BEGINNING OF CODE
|
||||
# NOTE: GPIO PIN 16 used
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import dht11
|
||||
import time
|
||||
|
||||
# initialize GPIO
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.cleanup()
|
||||
|
||||
try:
|
||||
while True:
|
||||
# read data using pin 16
|
||||
instance = dht11.DHT11(pin = 16)
|
||||
result = instance.read()
|
||||
|
||||
if result.is_valid():
|
||||
print("Temperature: %-3.1f C" % result.temperature)
|
||||
print("Humidity: %-3.1f %%" % result.humidity)
|
||||
else:
|
||||
print("Error: %d" % result.error_code)
|
||||
time.sleep(3)
|
||||
except KeyboardInterrupt:
|
||||
print("Program stopped by user.")
|
||||
GPIO.cleanup()
|
||||
# END OF CODE
|
BIN
Practical/Assignment-4/IoT - Softcopy-4.pdf
Normal file
BIN
Practical/Assignment-4/IoT - Softcopy-4.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user