When this low temperature alarm runs, it's supposed to print the start time, the temperature, humidity, then when it rea
- /RaspberryPi
- Corporate
- Posts: 2449
- Joined: Wed Jun 05, 2019 1:29 am
When this low temperature alarm runs, it's supposed to print the start time, the temperature, humidity, then when it rea
##
import sys
import time
from time import sleep # Import Sleep module from time library
import subprocess
import Adafruit_DHT # Import the Adafruit_DHT module
from datetime import datetime
t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
pin = 4 # Set pin to pin 4
dly = 2 # Set delay to 2000ms (2 seconds) Can be changed to 1 for DHT22
sensor_type = 22 # Sensor type: Change this to 22 if using DHT22, or leave
# at 11 for DHT11
TEMPLIMIT = 18.333 #60 Degrees in Celcius before conversion
print (current_time)
try:
while True:
# Introduce our delay
sleep(dly)
# Read from sensor
humidity, temperature = Adafruit_DHT.read_retry(sensor_type, pin)
# Sensor defaults to Celsius, convert to Fahrenheit.
fahrenheit = (temperature * 1.8) + 32
celsius = temperature
# Check if data from sensor read is valid. Print data if it is. Else, fail.
if humidity is not None or temperature is not None:
print ("Temperature: {0:0.1f} Humidity: {1:0.1f}% ".format(fahrenheit, humidity))
else:
print ("Cannot read from device")
#Play sound when temperature drops below limit
if temperature < TEMPLIMIT:
print (current_time)
subprocess.run(['vlc', '/home/pi/lowtempwarning.mp3'])
except KeyboardInterrupt:
sys.exit()
submitted by /u/jamfan03
[link] [comments]
Source: https://www.reddit.com/r/raspberry_pi/c ... _supposed/
/RaspberryPi