Monitoring Temperature Using Arduino and LM35 Temperature Sensor

by Lisleapex Blog in Circuits > Arduino

6 Views, 0 Favorites, 0 Comments

Monitoring Temperature Using Arduino and LM35 Temperature Sensor

Connecting to Arduino.png

How to use Arduino and LM35 temperature sensor to monitor temperature? Here I will give you a brief introduction

Supplies

LM35 temperatore sensor

arduino

breadboard

Place the Sensor on the Breadboard

Place the sensor on the breadboard.png

Let's connect these things first. Put the sensor on the breadboard, and then connect it to the Arduino according to the schematic below.

Connecting to Arduino

Connecting to Arduino.png

The left pin is the power pin, connected to the 5V power hole of Arduino with a red wire, the rightmost is the ground, connected to the GND hole of Arduino with a black wire, and the middle pin is the temperature data output, which we connect to the analog signal port 0 (A0). Below is the code to read the temperature value from A0. If yours doesn't work, it is likely that the left and right are reversed, just change the direction and reconnect it.

Notice

You may have noticed that there is a red CC3000 WIFI shield expansion board on the Arduino. I use this to connect to the Internet. I won’t use it now, so you can ignore it.

Coding

Now it’s time to write some code. Open the Arduino IDE and enter the following code:

float temp = 0;


// the setup routine runs once when you press reset:
void setup() {

Serial.begin(115200);

Serial.println(F("reading temperature begin. \n"));

}

// the loop routine runs over and over again forever:
void loop() {
static unsigned long sensortStamp = 0;
if(millis() - sensortStamp > 100){
sensortStamp = millis();
// read the LM35 sensor value and convert to the degrees every 100ms.

int reading = analogRead(0); //注意到我们是把LM35的输出端连接到了A0,所以这里是analogRead(0)
temp = reading *0.0048828125*100;
Serial.print(F("Real Time Temp: "));
Serial.println(temp);
}
}


Upload the Code to Arduino

Upload the code to Arduino.png

After writing the code, you can upload it to the Arduino and execute it. After uploading, open the serial editor and you should be able to see the current temperature output. You can find the "Serial Monitor" in the "Tools" menu of the Arduino IDE. You can choose the baud rate in the lower right corner of the serial monitor. We have to choose 115200 baud because we set it in setup: Serial.begin(115200); Otherwise you may not see the output.

To verify, you can use a hair dryer to heat the sensor to see if the temperature changes. :)