const int sensorPin = A0; // Pin where potentiometer is connected
float temperatureC = 0; // Variable to store temperature in Celsius
float voltage = 0; // Variable to store the voltage value
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
// Read the analog value from the potentiometer (0-1023)
int sensorValue = analogRead(sensorPin);
// Convert the analog reading to voltage (0V to 5V)
voltage = sensorValue * (5.0 / 1023.0);
// Convert the voltage to temperature
temperatureC = voltage * 10; // 1°C per 0.1V, so multiply by 10
// Print the temperature and voltage to the Serial Monitor
Serial.print("Voltage: ");
Serial.print(voltage);
Serial.print(" V, Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
delay(500); // Delay for readability in the serial monitor
}