/* * Lab 1 - Task 7: Analog Sensor (LM35)
* Objective: Read temperature using mathematical ADC conversion.
*/
const int lm35Pin = 35; // LM35 VOUT connected to GPIO 35 (Analog Input)
void setup() {
Serial.begin(115200);
Serial.println("Task 7 Ready: LM35 Analog Temperature Test!");
}
void loop() {
// 1. Read the raw 12-bit ADC value (0 to 4095)
int adcValue = analogRead(lm35Pin);
// 2. Convert the ADC value to Voltage in millivolts (mV)
// ESP32 operates at 3.3V, which is 3300mV.
float voltage_mV = (adcValue / 4095.0) * 3300.0;
// 3. Convert the voltage to Temperature in Celsius
// The LM35 outputs 10mV per degree Celsius.
float temperature = voltage_mV / 10.0;
// 4. Display the results
Serial.print("Raw ADC: ");
Serial.print(adcValue);
Serial.print(" \tVoltage: ");
Serial.print(voltage_mV);
Serial.print(" mV \tTemperature: ");
Serial.print(temperature);
Serial.println(" °C");
// Wait 1 second before the next reading
delay(1000);
}