const int tempPin = A2; // Analog pin connected to TMP36
void setup() {
// Start the Serial Monitor
Serial.begin(115200);
}
void loop() {
// Read the analog value from the TMP36
int analogValue = analogRead(tempPin);
// Convert the analog value to voltage
float voltage = analogValue * (3.3 / 4095.0);
// Convert the voltage to temperature in Celsius
// TMP36 outputs 0.5V at 0°C and 10mV per °C
float temperatureC = (voltage - 0.5) * 100.0;
// Print the temperature to the Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
// Wait for a short period before taking another reading
delay(1000);
}