Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Monitoring temperature is crucial in various applications such as weather stations, home automation systems, and industrial processes. The LM35 is a popular temperature sensor that provides a linear output proportional to the temperature in Celsius. When integrated with an Arduino, it allows for real-time temperature monitoring and data logging. This article will guide you through setting up the LM35 sensor with an Arduino, explaining its importance and providing a detailed project example.
Project: In this project, we will create a simple temperature monitoring system using the LM35 temperature sensor and an Arduino. The objective is to read the temperature data from the LM35 sensor and display it on the serial monitor. This project can be extended to include features such as data logging, triggering alarms when the temperature exceeds a threshold, or displaying the temperature on an LCD.
Components List:
Examples:
// Define the pin where the LM35 is connected
const int lm35Pin = A0; // LM35 output connected to analog pin A0
void setup() {
// Initialize the serial communication
Serial.begin(9600);
}
void loop() {
// Read the analog value from the LM35
int analogValue = analogRead(lm35Pin);
// Convert the analog value to voltage (assuming 5V power supply)
float voltage = analogValue * (5.0 / 1023.0);
// Convert the voltage to temperature in Celsius
float temperatureC = voltage * 100.0;
// Print the temperature to the serial monitor
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
// Wait for a second before taking another reading
delay(1000);
}
Code Explanation:
const int lm35Pin = A0;
: Defines the analog pin A0 where the LM35 sensor is connected.void setup() { Serial.begin(9600); }
: Initializes serial communication at 9600 baud rate for data output.int analogValue = analogRead(lm35Pin);
: Reads the analog value from the LM35 sensor.float voltage = analogValue * (5.0 / 1023.0);
: Converts the analog value to a corresponding voltage.float temperatureC = voltage * 100.0;
: Converts the voltage to temperature in Celsius (LM35 provides 10mV per degree Celsius).Serial.print("Temperature: "); Serial.print(temperatureC); Serial.println(" °C");
: Prints the temperature value to the serial monitor.delay(1000);
: Waits for one second before taking another reading.This simple project can be the foundation for more complex temperature monitoring systems. For instance, you could add an LCD display to show the temperature, use an SD card module for data logging, or implement a relay module to control a fan or heater based on the temperature readings.