Loading... Please wait...

LM35DZ Temperature Sensor

LM35DZ Temperature Sensor

This example shows the simplest thing you can do with an Arduino to see physical output: it blinks an LED.

Hardware Required

  • Arduino Board
  • LM35DZ Temperature Sensor


First of all, let’s identify which pins are which on the LM35 itself. One side of the sensor will be rounded, and the other will be flat. With the flat side facing towards you, and the pins facing down, the pins from left to right are: 1, 2 and 3, as can be seen in the illustration below.



Plug the LM35 into your breadboard and place jumper cables from pin 1 to 5v on the Arduino, pin 2 to an analogue pin on your Arduino (for this example we’ll use analogue pin 5) and pin 3 to the GND pin on the Arduino.

We now have our circuit, which should look like this:




click the image to enlarge



Now that our circuit is done, we can put some code behind it. Load up the Arduino IDE and copy and paste this code into a new sketch:

float temperature;  
int reading;  
int lm35Pin = 5;

void setup()  

void loop()  
    reading = analogRead(lm35Pin);
    temperature = reading / 9.31;

At the top of the file we have three variables that we need later on:

  • temperature – this is where we will store the temperature in centigrade (if you want to use fahreinheit just alter the calculation accordingly)
  • reading – this is where we will store the raw reading from the analogue pin prior to any calculations
  • lm35Pin - this is where we will store the pin number that we are reading from

In the setup method we make a call to the analogReference method. This allows us to set the reference voltage of the Arduino (i.e. the value used as the top of the input range). The reason we are using this is because the LM35 only produces voltages from 0 to +1V, and setting the reference voltage to INTERNAL will set it to 1.1 volts, as a result significantly improving the precision. The second line of the setup method is simply to allow us to read the data we are gathering via the Serial Monitor window (found under the Tools menu).

Inside the loop method, we begin by reading the value from the analogue input, and then divide that reading by 9.31. The reason we divide by 9.31 is because the range of our reading is 1024 and as we have set our reference voltage to be 1.1 volts we calculate each “step” in the analog reading as being approximately equal to 0.001074 volts, or 1.0742 millivolts. As the LM35 reports 1 degree Celsius per 10 millivolts, this means that for every (10 / 1.0742), we detect a one degree change i.e. every 9.31; so by dividing the reading by 9.31 we get our temperature reading in Celsius.



What's News


Copyright 2019 oddWires. All Rights Reserved.
 Sitemap | oddWires