Example Code for Arduino-Temperature Measurement
Last revision 2026/01/06
This article presents a step-by-step guide for measuring temperature using Arduino, including a sample code for the LM35 temperature sensor and a wiring diagram to assist in the hardware setup.
Wiring Diagram

Sample Code
void setup()
{
Serial.begin(9600);//Set Baud Rate to 9600 bps
}
void loop()
{
uint16_t val;
double dat;
val=analogRead(A0);//Connect LM35 on Analog 0
dat = (double) val * (5/10.24);
Serial.print("Tep:"); //Display the temperature on Serial monitor
Serial.print(dat);
Serial.println("C");
delay(500);
}
Was this article helpful?
