#include <stdio.h>
#include <pico/stdlib.h>
#include "hardware/adc.h"
int main() {
stdio_init_all();
adc_init();
adc_select_input(4); // Select internal temperature sensor (ADC4)
while (true) {
uint16_t raw = adc_read();
// Convert ADC reading to voltage (assuming 3.3V reference)
float voltage = raw * 3.3f / 4095.0f;
// Convert voltage to temperature in Celsius per RP2040 datasheet
float temperature = 27.0f - (voltage - 0.706f) / 0.001721f;
printf("Raw ADC: %d, Voltage: %.3f V, Temperature: %.2f °C\n", raw, voltage, temperature);
sleep_ms(1000);
}
}