from machine import ADC, Pin
import utime
# Define LM35 sensor pin
lm35_pin = Pin(6)
# Create ADC object
adc = ADC(0)
# Function to read temperature from LM35 sensor
def read_temperature():
# Read analog value from LM35
raw_value = adc.read_u16()
# Convert analog value to voltage (3.3V max)
voltage = (raw_value / 65535) *3.3
# LM35 outputs 10mV per degree Celsius
temperature_celsius = voltage * 100
return temperature_celsius
# Main loop
while True:
# Read temperature from LM35 sensor
temperature = read_temperature()
# Print temperature
print("Temperature: {:.2f} °C".format(temperature))
# Wait for 1 second
utime.sleep(1)