This guide shows how to use the LM35 (LM35DZ), LM335 and LM34 temperature sensors with the Arduino board. We’ll show you how to wire the sensors and write the code to get temperature readings. Lastly, we’ll build a project example to display the sensor readings on an OLED display.

The LM35, LM335 and LM34 are linear temperature sensors that output a voltage proportional to the temperature value.
| Temperature Sensor | Output Voltage | Linearity |
| LM35 (LM35DZ) | proportional to temperature in Celsius (ºC) | 10mV/ºC |
| LM335 | proportional to temperature in Kelvin (ºK) | 10mV/ºK |
| LM34 | proportional to temperature in Fahrenheit (ºF) | 10mV/ºF |
These sensors work in a similar way, but are calibrated differently to output a voltage proportional to the different temperature units.
The LM35 outputs 10 mV per degrees Celsius rise in temperature. In a similar way, the LM335 outputs 10 mV per degrees Kelvin rise in temperature and the LM34 outputs 10 mV per degrees Fahrenheit rise in temperature.
For example, if the LM35 outputs a voltage of 345 mV, that means we have a temperature value of 34.5ºC.
For more information about these sensors, you can consult their datasheet:
You can go to Maker Advisor to find the Temperature sensors’ best price at different stores:
The LM35 has only three pins, VCC, Vout and GND.

Here’s the connections you need to make between the LM35 and the Arduino:
| LM35 / LM34 | Arduino |
| VCC | 5V |
| Vout | Any Analog Pin |
| GND | GND |
Note: if you’re using an LM34 temperature sensor, the pinout is the same of the LM35.
The pinout of the LM335 temperature sensor is slightly different.

| LM335 | Arduino |
| Adj | Don’t connect |
| Vout | Any Analog Pin (pull up with 2k Ohm resistor) |
| GND | GND |
The adj pin can be used to calibrate the sensor and obtain more accurate temperature readings. We won’t use that pin in this tutorial, so it should be left unconnected.
You should follow the same schematic diagram whether you’re using an LM35 or LM34 temperature sensor. You should follow a slightly different diagram if you’re using the LM335.

The following code reads the temperature from the LM35 sensor and displays the readings in the Serial Monitor. This code is also compatible with LM335 and LM34 – you just need to uncomment some lines in the code to use the right sensor.
/* * Rui Santos * Complete Project Details https://RandomNerdTutorials.com */ const int sensorPin = A0; float sensorValue; float voltageOut; float temperatureC; float temperatureF; // uncomment if using LM335 //float temperatureK; void setup() { pinMode(sensorPin, INPUT); Serial.begin(9600); } void loop() { sensorValue = analogRead(sensorPin); voltageOut = (sensorValue * 5000) / 1024; // calculate temperature for LM35 (LM35DZ) temperatureC = voltageOut / 10; temperatureF = (temperatureC * 1.8) + 32; // calculate temperature for LM335 //temperatureK = voltageOut / 10; //temperatureC = temperatureK - 273; //temperatureF = (temperatureC * 1.8) + 32; // calculate temperature for LM34 //temperatureF = voltageOut / 10; //temperatureC = (temperatureF - 32.0)*(5.0/9.0); Serial.print("Temperature(ºC): "); Serial.print(temperatureC); Serial.print(" Temperature(ºF): "); Serial.print(temperatureF); Serial.print(" Voltage(mV): "); Serial.println(voltageOut); delay(1000); }
You start by defining the pin that is connected to the sensor output. It must be an analog pin. We’re using pin A0, but you can use any other analog pin.
const int sensorPin = A0;
Define a variable that will hold the analog value read from the sensor:
float sensorValue;
The voltageOut variable will store the actual voltage output value coming from the sensor.
float voltageOut;
Then, create variables that will store the temperature value. Here, we create a temperatureC and a temperatureF variables to hold the temperature in Celsius and Fahrenheit, respectively.
float temperatureC; float temperatureF;
If you’re using the LM335 sensor, you also need a variable to hold the temperature in Kelvin. So, if you’re using that sensor you need to uncomment the following line:
//float temperatureK;In the setup(), declare the sensorPin as an input:
pinMode(sensorPin, INPUT);
Initialize a serial communication at a baud rate of 9600. You need to initialize the serial communication so that you can display the readings on the Serial Monitor:
Serial.begin(9600);
In the loop(), read the value coming from you sensor and save it in voltageOut variable. To read an analog value with Arduino you just need to use analogRead() function and pass the pin you want to read as an argument.
voltageOut = analogRead(sensorPin);
As mentioned previously, these sensors output a voltage value that is proportional to the temperature.
The analog values read from the Arduino may have a value between 0 and 1024, in which 0 corresponds to 0V and 1024 to 5V. So, we can easily get the output voltage of the sensor in mV.
voltageOut = (sensorValue * 5000) / 1024
In case of the LM35 sensor, we’ve seen that 10mV corresponds to a Celsius degree rise in temperature. So, the temperature in Celsius corresponds to the voltage read from the sensor in mV divided by 10mV.
temperatureC = voltageOut / 10;
To get the temperature in Fahrenheit, we just need to use the Celsius -> Fahrenheit conversion:
temperatureF = (temperatureC * 1.8) + 32;
If you’re using an LM335 or an LM34, you use the same calculations to get the temperature. You just need to keep in mind that the LM335 returns the temperature in Kelvin degrees and the LM34 in Fahrenheit degrees. Then, you can convert the values to other units if needed.
Finally, print the sensors readings to the Serial Monitor both in Celsius and Fahrenheit degrees.
Serial.print("Temperature(ºC): "); Serial.print(temperatureC); Serial.print(" Temperature(ºF): "); Serial.print(temperatureF);
For debugging purposes, we also print the voltage.
Serial.print(" Voltage(mV): "); Serial.println(voltageOut);
The loop() is repeated every second.
delay(1000);
Upload the code to your Arduino IDE. Don’t forget to select the right board and COM port in the Tools menu.
After that, open the Serial Monitor at a baud rate of 9600. You should get new temperature readings every second. You can cover the sensor with your finger to see the temperature values increasing.

In this section we’ll show you how to display your sensor readings in an OLED display.
For an in-depth tutorial on how to use the OLED display with the Arduino, follow the next guide:
For this project, you’ll need the following parts:
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
Wire all the components as shown in the next schematic diagram:
To control the OLED display you need the adafruit_SSD1306.h and the adafruit_GFX.h libraries. Follow the next instructions to install those libraries.
1. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open.
2. Type “SSD1306” in the search box and install the SSD1306 library from Adafruit.

3. After installing the SSD1306 library from Adafruit, type “GFX” in the search box and install the library.

4. After installing the libraries, restart your Arduino IDE.
After wiring the circuit and installing the required libraries, upload the following code to your Arduino board.
/* * Rui Santos * Complete Project Details https://RandomNerdTutorials.com */ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // declaration for an SSD1306 display connected to I2C (SDA, SCL pins) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); const int sensorPin = A0; float sensorValue; float voltageOut; float temperatureC; float temperatureF; // uncomment if using LM335 //float temperatureK; void setup() { pinMode(sensorPin, INPUT); Serial.begin(9600); if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); for(;;); } delay(2000); display.clearDisplay(); display.setTextColor(WHITE); } void loop() { sensorValue = analogRead(sensorPin); voltageOut = (sensorValue * 5000) / 1024; // calculate temperature for LM35 (LM35DZ) temperatureC = voltageOut / 10; temperatureF = (temperatureC * 1.8) + 32; // calculate temperature for LM335 //temperatureK = voltageOut / 10; //temperatureC = temperatureK - 273; //temperatureF = (temperatureC * 1.8) + 32; // calculate temperature for LM34 //temperatureF = voltageOut / 10; //temperatureC = (temperatureF - 32.0)*(5.0/9.0); Serial.print("Temperature(ºC): "); Serial.print(temperatureC); Serial.print(" Temperature(ºF): "); Serial.print(temperatureF); // clear display display.clearDisplay(); // display temperature Celsius display.setTextSize(1); display.setCursor(0,0); display.print("Temperature: "); display.setTextSize(2); display.setCursor(0,10); display.print(temperatureC); display.print(" "); display.setTextSize(1); display.cp437(true); display.write(167); display.setTextSize(2); display.print("C"); // display temperature Fahrenheit display.setTextSize(1); display.setCursor(0, 35); display.print("Temperature: "); display.setTextSize(2); display.setCursor(0, 45); display.print(temperatureF); display.print(" "); display.setTextSize(1); display.cp437(true); display.write(167); display.setTextSize(2); display.print("F"); display.display(); delay(1000); }
Congratulations! You’ve completed the project. Now, you can check the sensor readings in the OLED display. New temperature readings are displayed every second.

Copyright ©2025. All Rights Reserved Emblab THE RAVE INNOVATION