from machine import ADC
from machine import Pin
from machine import read_u16
import utime
# Define the pin numbers
led_pin = machine.Pin(0, machine.Pin.OUT) # GPIO pin 25 for the LED
temp_sensor_pin = machine.ADC(11) # GPIO pin 26 for the analog temperature sensor
# Main loop
while True:
# Read analog value from temperature sensor
temp_value = temp_sensor_pin.read_u16()
# Convert analog value to temperature in Celsius
voltage = temp_value / 65535 * 3.3
temperature_celsius = (voltage - 0.5) * 100
# Print temperature value
print("Temperature: {:.2f} C".format(temperature_celsius))
# Control LED based on temperature
if temperature_celsius > 25:
led_pin.on()
else:
led_pin.off()
# Wait for a moment before the next reading
utime.sleep(1)