from machine import Pin
import machine
import utime
import math
# Sensor Connections
thermistor_pin = Pin(26)
adc = machine.ADC(thermistor_pin)
led_k = Pin(5, machine.Pin.OUT)
led_y = Pin (28 ,Pin.OUT)
led_s = Pin(11,Pin.OUT)
def pulseE():
e.value(1)
utime.sleep_us(40)
e.value(0)
utime.sleep_us(40)
def read_temperature():
beta = 3950
series_resistor = 10000
adc_value = adc.read_u16()
resistance = series_resistor / (65535 / adc_value - 1)
# Using the Steinhart-Hart equation to calculate the temperature
steinhart = resistance / 10000 # (R/Ro)
steinhart = math.log(steinhart) # ln(R/Ro)
steinhart /= beta # 1/B * ln(R/Ro)
steinhart += 1.0 / (25 + 273.15) # + (1/To)
steinhart = 1.0 / steinhart # Invert
steinhart -= 273.15 # Convert to Celsius
return steinhart
# Main loop
while True:
temperature = read_temperature()
print("Derece :", temperature, "°C")
if temperature > 45:
led_k.on()
led_y.off()
led_s.off()
#send_string_to_lcd("Temperature>45C")
print("Tehlike var!")
utime.sleep(2)
if temperature < 30:
led_k.off()
led_y.on()
led_s.off()
print("Güvenli")
utime.sleep(2)
if 30>temperature<45:
led_k.off()
led_y.off()
led_s.on()
print("Tehlike olabilir")
utime.sleep(2)