import time
import onewire, ds18x20
from machine import Pin
# Configure the DS18B20 sensor
ow = onewire.OneWire(Pin(15)) # Pin 15 is connected to the DS18B20 data line
temp_sensor = ds18x20.DS18X20(ow)
# Function to read temperature from DS18B20
def read_temp():
temp_sensor.convert_temp()
time.sleep_ms(750)
return temp_sensor.read_temp()
# Main loop
while True:
temp = read_temp()
print("Temperature: {}C".format(temp))
time.sleep(1) # Wait for 1 second before reading temperature again