import machine
from machine import Pin
import time
from math import log
BETA = 3950
led_status = Pin(23, Pin.OUT)
adc= machine.ADC(machine.Pin(32))
adc.atten(machine.ADC.ATTN_11DB)
adc.width(machine.ADC.WIDTH_12BIT)
def blink_led (k):
if k==1 :
led_status.value(1)
time.sleep_ms(50)
led_status.value(0)
time.sleep_ms(50)
elif k==0 :
led.status.value(0)
while True :
analog_adc_input=adc.read()
celsius = 1 / (log(1 / (4095. / analog_adc_input - 1)) / BETA + 1.0 / 298.15) - 273.15
if celsius >= 35 :
blink_led(1)
print("FIRE ALERT !!!!")
print(f"Current sensor reading : {celsius} °C")
else :
print(f"Current sensor reading : {celsius} °C")
led_status.value(0)
time.sleep(0.5)