import machine
import onewire
import ds18x20
import utime
# Define the DS18B20 data pin and LED pin
ds_pin = machine.Pin(4)
led_pin = machine.Pin(15, machine.Pin.OUT)
# Initialize the DS18B20 sensor
ow = onewire.OneWire(ds_pin)
ds_sensor = ds18x20.DS18X20(ow)
# Temperature alarm threshold
alarm_threshold = 35.0
while True:
scan = ds_sensor.scan()[0]
if scan:
ds_sensor.convert_temp()
utime.sleep(0.2)
temp = ds_sensor.read_temp(scan)
print("Temperature: {:.2f}°C".format(temp))
# Check if temperature exceeds the alarm threshold
if temp > alarm_threshold:
led_pin.on()
else:
led_pin.off()