Introduction
The LM35 is a popular analog temperature sensor known for its high accuracy and simple interface. It provides temperature readings in Celsius with minimal calibration required. In this tutorial, you'll learn how to wire an LM35 sensor, write Arduino code to read temperature values, and use these readings in practical applications.
This project is perfect for beginners looking to explore sensors and data logging with Arduino.
Required Components
- 1x LM35 temperature sensor
- 1x Arduino board (e.g., Uno, Mega, or Nano)
- 1x Breadboard
- 3x Jumper wires (male-to-male)
- 1x USB cable (to connect Arduino to PC)
- Optional: Multimeter (for testing connections)
Ensure all components are in good condition to avoid potential troubleshooting issues during the project.
Wiring Instructions
Follow these steps to connect the LM35 temperature sensor to your Arduino:
- VCC: Connect the VCC pin of the LM35 sensor to the 5V or 3.3V pin on the Arduino board. Ensure the power level matches the specifications of the LM35.
-
Output: Connect the Output pin of the LM35 sensor to an analog input pin on the Arduino, such as
A0
. - GND: Connect the GND pin of the LM35 sensor to the GND pin on the Arduino.
Once connected, double-check the wiring to ensure proper connections before powering up the Arduino.
Arduino Code
const int lm35Pin = A0; // Analog pin connected to LM35
void setup() {
Serial.begin(9600); // Start the serial communication
}
void loop() {
int analogValue = analogRead(lm35Pin); // Read analog value from LM35
float voltage = analogValue * (5.0 / 1023.0); // Convert to voltage
float temperatureC = voltage * 100; // Convert voltage to temperature (Celsius)
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0; // Convert to Fahrenheit
Serial.print("Temperature (C): ");
Serial.print(temperatureC);
Serial.print(" °C | Temperature (F): ");
Serial.print(temperatureF);
Serial.println(" °F");
delay(1000); // Wait for 1 second before next reading
}
Upload this code to your Arduino and open the Serial Monitor to see real-time temperature readings in both Celsius and Fahrenheit.
Calibration
For the most accurate results, calibrate the LM35 sensor by comparing its output with a known accurate thermometer:
- Place the LM35 sensor and a reference thermometer in the same environment (e.g., a room or container).
- Compare the temperature readings from the LM35 and the thermometer.
- Adjust the calculations in your code if necessary. For example, you might add or subtract an offset value to align the readings.
Troubleshooting
If you encounter issues, check the following:
- No Serial Monitor Output: Ensure the correct COM port is selected in the Arduino IDE and the baud rate matches the code (9600).
- Inaccurate Readings: Verify the sensor's connections and calibrate the sensor as described earlier.
- Overheating Sensor: Check for incorrect power connections (e.g., reversed VCC and GND).
- Random Readings: Use shorter jumper wires or a breadboard with good connections.
Applications
The LM35 sensor is commonly used in:
- Room temperature monitoring
- Weather stations
- Industrial equipment monitoring
- DIY projects and experiments
- Automotive temperature sensing
- Temperature-triggered control systems
Further Experiments
Expand your project by trying these ideas:
- Log temperature data over time using an SD card module.
- Display temperature readings on an LCD or OLED screen.
- Send temperature data wirelessly using a Bluetooth or Wi-Fi module.
- Trigger a fan or heater when the temperature exceeds a certain threshold.
Conclusion
By completing this tutorial, you’ve learned how to wire and program an LM35 temperature sensor with an Arduino. With these skills, you can create a variety of temperature monitoring and control projects. Experiment further to take your project to the next level!