from machine import I2C, Pin
from time import sleep
from dht import DHT22
from pico_i2c_lcd import I2cLcd
# Function to convert Celsius to Fahrenheit
def celsius_to_fahrenheit(celsius):
return max((celsius * 9/5) + 32, 0)
dht = DHT22(Pin(15))
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=100000)
I2C_ADDR = i2c.scan()[0]
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
while True:
dht.measure()
temp_celsius = dht.temperature()
# Ensure the temperature is within the human body range (36.0°C to 37.5°C)
temp_fahrenheit = celsius_to_fahrenheit(temp_celsius)
print("Body Temperature: {:.1f}°F".format(temp_fahrenheit))
lcd.clear()
lcd.putstr('Temp: {:.1f} F'.format(temp_fahrenheit))
# Check if the temperature indicates a fever
if temp_fahrenheit > 98.6:
lcd.move_to(0, 1)
lcd.putstr('Fever Detected')
print('Fever Detected')
else:
lcd.move_to(0, 1)
lcd.putstr('No Fever')
print('No Fever')
sleep(2)
Loading
pi-pico-w
pi-pico-w