Project Description:
This project will demonstrate how to use an Arduino Uno R3 microcontroller and an LM35 temperature sensor to construct a temperature monitoring system.
This system will monitor the ambient temperature and show the data on the serial monitor in both Celsius and Fahrenheit.
It's a simple but efficient approach to measuring temperature changes in real time. And we'll go over how to build your own temperature monitoring system.
read more : Interfacing GPS Module with Arduino
LM35 sensor :
The LM35 sensor is a popular and useful device in the field of electronics and temperature monitoring. Its simplicity and precision make it popular among both fans and professionals.
The sensor operates by presenting a clear and understandable readout of the temperature it detects.
This makes it an ideal companion for microcontrollers such as Arduino and Raspberry Pi, which excel at projects requiring exact temperature data.
The LM35 sensor is flexible and dependable, with applications ranging from detecting ambient temperature to enhancing machine efficiency and even building a DIY weather station.
It's a popular option among IT enthusiasts and engineers because of its dependability and ease of use.
read more: 5 Arduino Project Ideas – Expert Level
How Does LM35 Sensor Work?
The LM35 sensor is an important device for measuring temperature and converting it into a simple electrical voltage. Its usefulness is based on a diode's capacity to raise voltage with growing temperature.
The LM35 has carefully constructed transistors that provide a voltage proportional to the absolute temperature, which is accurately calibrated to the Celsius scale.
The LM35 outputs a voltage that increases by 10 millivolts for every 1-degree Celsius rise in temperature.
Consider a scenario where you have a device that has to keep track of a room's temperature.
The LM35 sensor measures temperature upon connection and generates an output voltage that varies according to the ambient temperature.
Ten millivolts more will be produced in the output voltage for every degree Celsius as the room temperature rises.
Consequently, the output voltage will be 250 millivolts (25 degrees * 10 millivolts per degree) if the sensor registers a temperature of 25 degrees Celsius.
Components Required:
- LM35 Temperature Sensor
- Arduino Uno R3 Microcontroller
- Breadboard
- Jumper wires
LM35 Sensor Pin Diagram:
The LM35 sensor has a simple pinout that allows for fast and seamless integration into your designs.
VCC: The VCC pin is the power supply input for the LM35 sensor, which allows voltages ranging from 4 to 32 volts.
GND: To ensure proper functionality within your setup, connect the LM35's ground pin to the circuit ground.
Analog OUT: The sensor's analog output pin generates a voltage proportional to the detected temperature. The output voltage increases by 10 millivolts for every 1-degree Celsius change in temperature. This functionality facilitates the understanding and use of sensor data in your applications.
Connections:
- Attach the VCC (power) pin of the LM35 temperature sensor to the +5V pin on the Arduino board.
- Attach the GND (ground) pin of the LM35 temperature sensor to the GND pin on the Arduino board.
- Attach the Vout pin to the Analog Pin A1.
Circuit Diagram:
read more : Arduino Hacks we bet you did not know!
Code:
// Define the analog pin, the LM35's Vout pin is connected to
#define sensorPin A1
void setup() {
// Begin serial communication at 9600 baud rate
Serial.begin(9600);
}
void loop() {
// Get the voltage reading from the LM35
int reading = analogRead(sensorPin);
// Convert that reading into voltage
float voltage = reading * (5.0 / 1024.0);
// Convert the voltage into the temperature in Celsius
float temperatureC = voltage * 100;
// Print the temperature in Celsius
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.print("\xC2\xB0"); // shows degree symbol
Serial.print("C | ");
// Print the temperature in Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF);
Serial.print("\xC2\xB0"); // shows degree symbol
Serial.println("F");
delay(1000); // wait a second between readings
}
Code Explanation:
- // Define the analog pin to which the LM35's Vout pin is connected: This is a remark line that describes the code that follows it. It indicates that this line defines the analog pin that connects the LM35 temperature sensor's output (Vout).
- #Define sensorPin A1: The line of code "Define sensorPin A1" uses the preprocessor directive #define to declare a symbolic constant named sensorPin and assign it the value A1. As a result, all references to sensorPin in the code will be replaced with A1. In this context, it simplifies the code by allowing you to refer to the analog pin A1 as sensorPin.
- void setup() {: This line marks the beginning of the setup function, which is a standard Arduino function. Code placed inside this function is executed once at the beginning when the Arduino starts running.
- // Begin serial transfer at 9600 baud rate: This line demonstrates how to start serial communication at a 9600 baud rate with the next line of code.
- Serial.begin(9600);: At a baud rate of 9600 bits per second, serial communication is established using this line.The serial port is made ready for communication by it.
- void loop() {: This line marks the beginning of the loop function, another standard Arduino function. Code placed inside this function is executed repeatedly in a continuous loop once the setup function has run.
- int reading = analogRead(sensorPin);: This line reads the analog voltage from the LM35 temperature sensor, which is connected to the pin defined earlier as sensorPin (A1).
- Floating voltage = reading * (5.0 / 1024.0);: To find the voltage produced from the analog reading, multiply it by the 5.0 to 1024.0 ratio.
- Float temperature C = voltage x 100. The temperature in Celsius was estimated by multiplying the voltage by 100, as the LM35 sensor's datasheet states that every 10 mV (0.01 volt) shift equals one degree Celsius.
- Serial.print("Temperature: ");: This line initiates the process of displaying temperature information to the serial monitor.
- Serial.print(temperatureC);: This command prints the temperature in Celsius to the serial monitor.
- Serial.print("\xC2\xB0"); // display the degree symbol: This line displays the degree sign (°) on the serial monitor.
- Serial.print("C | ");: It prints "C | " to separate the temperature values.
- float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;: This line calculates the temperature in Fahrenheit by converting the Celsius temperature using the formula for Fahrenheit.
- Serial.print(temperatureF);: The temperature in Fahrenheit is reported on the serial monitor.
- Serial.print("\xC2\xB0"); displays the degree symbol: Again, the degree sign (°) is displayed.
- Serial.println("F");: Finally, "F" is displayed to show that the temperature is in Fahrenheit.
- delay(1000) will wait a second between measurements. This line adds a 1-second delay between temperature measurements in the loop to prevent overwhelming the serial monitor with data.
read more : What is the microcontroller used in Arduino UNO?
Result:
The temperature data is shown in real time in both Celsius and Fahrenheit on the serial monitor due to this Arduino project.
We can collect accurate temperature readings by attaching the LM35 temperature sensor to the Arduino board and making use of its analog-to-digital conversion capabilities.
Conclusion:
Studying the interface of the Arduino temperature sensor has proven to be an excellent approach for acquiring expertise in both electronics and coding.
We carefully assembled the wires, collected the required items, and studied the LM35 sensor's capabilities. We gained a better understanding of the entire process by providing detailed code explanations and an accurate circuit diagram.
As the project progressed, we used technologies to precisely detect and show temperature. Prepare yourself for an incredible journey enabled by sensors! This project will show you a wide range of temperature monitoring options and introduce you to the intriguing world of Arduino. Take advantage of the numerous opportunities in the fascinating realm of Arduino-powered temperature sensors!
If you appreciate our work don't forget to share this post and leave your opinion in the comment box.
Please check out other blog posts about Popular electronics
Make sure you check out our wide range of products and collections (we offer some exciting deals!)