🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X
Questions
























Write a program in Arduino to interface a temperature sensor (LM35) to detect the temperature of a room.

Last Updated : 16 Jul 2025

Solution:

const int lm35 = A2;  // LM35 temperature sensor connected to analog pin A2

void setup(){
    Serial.begin(9600);  // Initialize serial communication at 9600 baud rate
}

void loop(){
    int adcvalue = analogRead(lm35);          // Read the ADC value from the LM35
    float tempVoltage = adcvalue * 4.88;      // Convert the ADC value to voltage (assuming 5V reference)
    float tempval = tempVoltage / 10;         // Convert voltage to temperature (LM35: 10mV per °C)
    Serial.print(tempval);                    // Print the temperature value to the serial monitor
    Serial.println(" °C");                    // Print the unit (°C)
    delay(2000);                             // Wait for 2 seconds before taking the next reading
}
Report an error

Meanwhile you can watch this video

Watch Video
Latest Updates