Temperature Monitor
Read temperature sensor and display on serial monitor.
- Beginner
- Sensors
- 2 parts
Opens in your browser with the parts, wiring and code already in place. Press Run to watch it work, then change anything you like.
How it works
The temperature sensor has three pins: 5V, ground, and an output whose voltage rises with temperature, by 10 millivolts for each degree Celsius, like the common LM35 chip. The output is wired to analog pin A0.
loop() reads A0 as a number from 0 to 1023 and converts it to volts by multiplying by 5.0 and dividing by 1024. Because the sensor gives 0.01 volts per degree, multiplying the voltage by 100 gives degrees Celsius. The result prints once a second as “Temp: … C”. Select the sensor in the editor and change its temperature in the properties panel to watch the reading follow.
Parts
- Arduino Uno
- Temperature Sensor
Wiring
- Arduino Uno 5V → Temperature Sensor VCC
- Temperature Sensor OUT → Arduino Uno A0
- Arduino Uno GND → Temperature Sensor GND
Arduino code
// Temperature Monitor
void setup() {
Serial.begin(9600);
}
void loop() {
int reading = analogRead(A0);
float voltage = reading * 5.0 / 1024.0;
float tempC = voltage * 100;
Serial.print("Temp: ");
Serial.print(tempC);
Serial.println(" C");
delay(1000);
}
Try changing it
- Print Fahrenheit as well: after the existing print lines add Serial.println(tempC * 9.0 / 5.0 + 32.0);
- Take readings five times a second by changing delay(1000) to delay(200).