#define SENSOR_PIN A0
float voltage;
float temperature;
void setup() {
Serial.begin(9600);
}
void loop() {
int adc = analogRead(SENSOR_PIN); // 0–1023
voltage = adc * (5.0 / 100.0); // Convert to volts
temperature = voltage * 100.0; // LM35: 10mV/°C
Serial.print("ADC = ");
Serial.print(adc);
Serial.print(" Voltage = ");
Serial.print(voltage);
Serial.print(" V Temp = ");
Serial.print(temperature);
Serial.println(" °C");
delay(500);
}
Loading
st-nucleo-c031c6
st-nucleo-c031c6