{"id":87221,"date":"2019-07-15T13:43:00","date_gmt":"2019-07-15T13:43:00","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=87221"},"modified":"2019-07-15T13:43:05","modified_gmt":"2019-07-15T13:43:05","slug":"arduino-lm35-lm335-lm34-temperature-sensor","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/arduino-lm35-lm335-lm34-temperature-sensor\/","title":{"rendered":"Guide for LM35, LM335 and LM34 Temperature Sensors with Arduino"},"content":{"rendered":"\n<p>This guide shows how to use the LM35 (LM35DZ), LM335 and LM34 temperature sensors with the Arduino board. We&#8217;ll show you how to wire the sensors and write the code to get temperature readings. Lastly, we&#8217;ll build a project example to display the sensor readings on an OLED display.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-LM35DZ-LM34-LM335-Arduino-board-OLED-Temperature.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LM35 LM35DZ LM34 LM335 Arduino board OLED temperature Celsius Fahrenheit readings\" class=\"wp-image-87269\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-LM35DZ-LM34-LM335-Arduino-board-OLED-Temperature.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-LM35DZ-LM34-LM335-Arduino-board-OLED-Temperature.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-LM35DZ-LM34-LM335-Arduino-board-OLED-Temperature.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-LM35DZ-LM34-LM335-Arduino-board-OLED-Temperature.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Introducing LM35, LM335 and LM34 Temperature Sensors<\/h2>\n\n\n\n<p>The LM35, LM335 and LM34 are linear temperature sensors that output a voltage proportional to the temperature value.<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td><strong>Temperature Sensor<\/strong><\/td><td><strong>Output Voltage <\/strong><\/td><td><strong>Linearity<\/strong><\/td><\/tr><tr><td><strong>LM35<\/strong> (LM35DZ)<\/td><td>proportional to temperature in <strong>Celsius<\/strong> (\u00baC)<\/td><td>10mV\/\u00baC<\/td><\/tr><tr><td><strong>LM335<\/strong><\/td><td>proportional to temperature in <strong>Kelvin<\/strong> (\u00baK)<\/td><td>10mV\/\u00baK<\/td><\/tr><tr><td><strong>LM34<\/strong><\/td><td>proportional to temperature in <strong>Fahrenheit<\/strong> (\u00baF)<\/td><td>10mV\/\u00baF<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>These sensors work in a similar way, but are calibrated differently to output a voltage proportional to the different temperature units.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>For example, if the LM35 outputs a voltage of 345 mV, that means we have a temperature value of 34.5\u00baC.<\/p>\n\n\n\n<p>For more information about these sensors, you can consult their datasheet:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"http:\/\/www.ti.com\/lit\/ds\/symlink\/lm35.pdf\" target=\"_blank\">LM35 (LM35DZ) datasheet<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"http:\/\/www.ti.com\/lit\/ds\/symlink\/lm135.pdf\" target=\"_blank\">LM335 datasheet<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"http:\/\/www.ti.com\/lit\/ds\/symlink\/lm34.pdf\" target=\"_blank\">LM34 datasheet<\/a><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Where to Buy?<\/h3>\n\n\n\n<p>You can go to <a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/\" target=\"_blank\">Maker Advisor<\/a>&nbsp;to find the Temperature sensors&#8217; best price at different stores:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/lm35-lm35dz-temperature-sensor\/\" target=\"_blank\">LM35 (LM35DZ) Temperature Sensor<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/lm335-temperature-sensor\/\" target=\"_blank\">LM335 Temperature Sensor<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/lm34-temperature-sensor\/\" target=\"_blank\">LM34 Temperature Sensor<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">LM35 (LM35DZ) Pinout<\/h2>\n\n\n\n<p>The LM35 has only three pins, <span class=\"rnthl rntcred\">VCC<\/span>, <span class=\"rnthl rntcyellow\">Vout<\/span> and <span class=\"rnthl rntcblack\">GND<\/span>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"363\" height=\"465\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-Temperature-Sensor-Pinout.png?resize=363%2C465&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LM35 LM35DZ Pinout. Pins: VCC, Vout and GND\" class=\"wp-image-87255\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-Temperature-Sensor-Pinout.png?w=363&amp;quality=100&amp;strip=all&amp;ssl=1 363w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-Temperature-Sensor-Pinout.png?resize=234%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 234w\" sizes=\"(max-width: 363px) 100vw, 363px\" \/><\/figure><\/div>\n\n\n\n<p>Here&#8217;s the connections you need to make between the LM35 and the Arduino:<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td><strong>LM35 \/ LM34<\/strong><\/td><td><strong>Arduino<\/strong><\/td><\/tr><tr><td><span class=\"rnthl rntcred\">VCC<\/span><\/td><td>5V<\/td><\/tr><tr><td><span class=\"rnthl rntcyellow\">Vout<\/span><\/td><td>Any Analog Pin<\/td><\/tr><tr><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><td>GND<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p class=\"rntbox rntclblue\"><strong>Note: <\/strong> if you&#8217;re using an LM34 temperature sensor, the pinout is the same of the LM35.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">LM335 Pinout<\/h2>\n\n\n\n<p>The pinout of the LM335 temperature sensor is slightly different.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"364\" height=\"463\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM335Z-Temperature-Sensor-Pinout.png?resize=364%2C463&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LM335 LM335Z Pinout. Pins: VCC, Vout and GND\" class=\"wp-image-87260\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM335Z-Temperature-Sensor-Pinout.png?w=364&amp;quality=100&amp;strip=all&amp;ssl=1 364w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM335Z-Temperature-Sensor-Pinout.png?resize=236%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 236w\" sizes=\"(max-width: 364px) 100vw, 364px\" \/><\/figure><\/div>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td><strong>LM335<\/strong><\/td><td><strong>Arduino<\/strong><\/td><\/tr><tr><td><span class=\"rnthl rntclgray\">Adj<\/span><\/td><td>Don&#8217;t connect<\/td><\/tr><tr><td><span class=\"rnthl rntcyellow\">Vout<\/span><\/td><td>Any Analog Pin (pull up with 2k Ohm resistor)<\/td><\/tr><tr><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><td>GND<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>The <span class=\"rnthl rntclgray\">adj<\/span> pin can be used to calibrate the sensor and obtain more accurate temperature readings. We won&#8217;t use that pin in this tutorial, so it should be left unconnected.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Schematic Diagram<\/h2>\n\n\n\n<p>You should follow the same schematic diagram whether you&#8217;re using an LM35 or LM34 temperature sensor. You should follow a slightly different diagram if you&#8217;re using the LM335.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">LM35 and LM34 with Arduino<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM35-Schematic-Diagram.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM35-Schematic-Diagram.png?resize=684%2C711&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LM35 \/ LM35DZ and LM34 Wiring to Arduino Schematic Diagram\" class=\"wp-image-87265\" width=\"684\" height=\"711\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM35-Schematic-Diagram.png?w=912&amp;quality=100&amp;strip=all&amp;ssl=1 912w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM35-Schematic-Diagram.png?resize=289%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 289w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM35-Schematic-Diagram.png?resize=768%2C798&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 684px) 100vw, 684px\" \/><\/a><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"> LM335 with Arduino<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM335-Schematic-Diagram.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"852\" height=\"1008\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM335-Schematic-Diagram.png?resize=852%2C1008&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LM335 and LM34 Wiring to Arduino Schematic Diagram\" class=\"wp-image-87266\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM335-Schematic-Diagram.png?w=852&amp;quality=100&amp;strip=all&amp;ssl=1 852w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM335-Schematic-Diagram.png?resize=254%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 254w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM335-Schematic-Diagram.png?resize=768%2C909&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 852px) 100vw, 852px\" \/><\/a><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Code &#8211; Read Temperature<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"420\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-LM35DZ-LM34-LM335-Arduino-board-OLED-wiring-schematic.jpg?resize=750%2C420&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LM35 LM35DZ LM34 LM335 Arduino board OLED wiring schematic\" class=\"wp-image-87270\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-LM35DZ-LM34-LM335-Arduino-board-OLED-wiring-schematic.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-LM35DZ-LM34-LM335-Arduino-board-OLED-wiring-schematic.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>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 &#8211; you just need to uncomment some lines in the code to use the right sensor.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * Rui Santos\n * Complete Project Details https:\/\/RandomNerdTutorials.com\n *\/\n \nconst int sensorPin = A0; \nfloat sensorValue;\nfloat voltageOut;\n\nfloat temperatureC;\nfloat temperatureF;\n\n\/\/ uncomment if using LM335\n\/\/float temperatureK;\n\nvoid setup() {\n  pinMode(sensorPin, INPUT);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  sensorValue = analogRead(sensorPin);\n  voltageOut = (sensorValue * 5000) \/ 1024;\n  \n  \/\/ calculate temperature for LM35 (LM35DZ)\n  temperatureC = voltageOut \/ 10;\n  temperatureF = (temperatureC * 1.8) + 32;\n\n  \/\/ calculate temperature for LM335\n  \/\/temperatureK = voltageOut \/ 10;\n  \/\/temperatureC = temperatureK - 273;\n  \/\/temperatureF = (temperatureC * 1.8) + 32;\n\n  \/\/ calculate temperature for LM34\n  \/\/temperatureF = voltageOut \/ 10;\n  \/\/temperatureC = (temperatureF - 32.0)*(5.0\/9.0);\n\n  Serial.print(&quot;Temperature(\u00baC): &quot;);\n  Serial.print(temperatureC);\n  Serial.print(&quot;  Temperature(\u00baF): &quot;);\n  Serial.print(temperatureF);\n  Serial.print(&quot;  Voltage(mV): &quot;);\n  Serial.println(voltageOut);\n  delay(1000);\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Arduino\/Arduino_LM35_LM335_LM34.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Code Works<\/h2>\n\n\n\n<p>You start by defining the pin that is connected to the sensor output. It must be an analog pin. We&#8217;re using pin <span class=\"rnthl rntcyellow\">A0<\/span>, but you can use any other analog pin.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const int sensorPin = A0;<\/code><\/pre>\n\n\n\n<p>Define a variable that will hold the analog value read from the sensor:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float sensorValue;<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">voltageOut<\/span> variable will store the actual voltage output value coming from the sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float voltageOut;<\/code><\/pre>\n\n\n\n<p>Then, create variables that will store the temperature value. Here, we create a <span class=\"rnthl rntliteral\">temperatureC<\/span> and a <span class=\"rnthl rntliteral\">temperatureF<\/span> variables to hold the temperature in Celsius and Fahrenheit, respectively.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float temperatureC;\nfloat temperatureF;<\/code><\/pre>\n\n\n\n<p>If you&#8217;re using the LM335 sensor, you also need a variable to hold the temperature in Kelvin. So, if you&#8217;re using that sensor you need to uncomment the following line:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/float temperatureK;<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, declare the <span class=\"rnthl rntliteral\">sensorPin<\/span> as an input:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(sensorPin, INPUT);<\/code><\/pre>\n\n\n\n<p>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:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(9600);<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, read the value coming from you sensor and save it in <span class=\"rnthl rntliteral\">voltageOut<\/span> variable. To read an analog value with Arduino you just need to use <span class=\"rnthl rntliteral\">analogRead()<\/span> function and pass the pin you want to read as an argument.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>voltageOut = analogRead(sensorPin);<\/code><\/pre>\n\n\n\n<p>As mentioned previously, these sensors output a voltage value that is proportional to the temperature.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>voltageOut = (sensorValue * 5000) \/ 1024<\/code><\/pre>\n\n\n\n<p>In case of the LM35 sensor, we&#8217;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.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>temperatureC = voltageOut \/ 10;<\/code><\/pre>\n\n\n\n<p>To get the temperature in Fahrenheit, we just need to use the Celsius -&gt; Fahrenheit conversion:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>temperatureF = (temperatureC * 1.8) + 32;<\/code><\/pre>\n\n\n\n<p>If you&#8217;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.<\/p>\n\n\n\n<p>Finally, print the sensors readings to the Serial Monitor both in Celsius and Fahrenheit degrees.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.print(\"Temperature(\u00baC): \");\nSerial.print(temperatureC);\nSerial.print(\"  Temperature(\u00baF): \");\nSerial.print(temperatureF);<\/code><\/pre>\n\n\n\n<p>For debugging purposes, we also print the voltage.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.print(\"  Voltage(mV): \");\nSerial.println(voltageOut);<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">loop()<\/span> is repeated every second.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>delay(1000);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>Upload the code to your Arduino IDE. Don&#8217;t forget to select the right board and COM port in the Tools menu.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"711\" height=\"445\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-Temperature-and-Voltage-Readings-on-Serial-Monitor.png?resize=711%2C445&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LM35\/LM35DZ, LM335 and LM34 Temperature Sensors with Arduino board. Print serial readings in Arduino IDE Serial Monitor\" class=\"wp-image-87245\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-Temperature-and-Voltage-Readings-on-Serial-Monitor.png?w=711&amp;quality=100&amp;strip=all&amp;ssl=1 711w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-Temperature-and-Voltage-Readings-on-Serial-Monitor.png?resize=300%2C188&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Temperature Readings in OLED Display<\/h2>\n\n\n\n<p>In this section we&#8217;ll show you how to display your sensor readings in an <a href=\"https:\/\/makeradvisor.com\/tools\/oled-display-128x64-0-96-inch\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"OLED display (opens in a new tab)\">OLED display<\/a>.<\/p>\n\n\n\n<p>For an in-depth tutorial on how to use the OLED display with the Arduino, follow the next guide:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-oled-display-with-arduino\/\">Guide for I2C OLED Display with Arduino<\/a><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Parts Required<\/h3>\n\n\n\n<p>For this project, you&#8217;ll need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\">Arduino board<\/a> (read <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\">Best Arduino Started Kits<\/a>)<\/li><li><a rel=\"noreferrer noopener\" aria-label=\"LM35 Temperature Sensor (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/lm35-lm35dz-temperature-sensor\/\" target=\"_blank\">LM35 Temperature Sensor<\/a> (or <a rel=\"noreferrer noopener\" aria-label=\"LM335 (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/lm335-temperature-sensor\/\" target=\"_blank\">LM335<\/a>, <a rel=\"noreferrer noopener\" aria-label=\"LM34 (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/lm34-temperature-sensor\/\" target=\"_blank\">LM34<\/a>)<\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\">2k Ohm resistor<\/a> (if using an LM335)<\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/oled-display-128x64-0-96-inch\/\" target=\"_blank\">I2C OLED Display<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\">Jumper Wires<\/a><\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Breadboard<\/a><\/li><\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic Diagram<\/h3>\n\n\n\n<p>Wire all the components as shown in the next schematic diagram:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM35-OLED-Display-Schematic-Diagram.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1183\" height=\"1016\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM35-OLED-Display-Schematic-Diagram.png?resize=1183%2C1016&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino LM35\/LM35DZ OLED Display Schematic Diagram\" class=\"wp-image-87271\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM35-OLED-Display-Schematic-Diagram.png?w=1183&amp;quality=100&amp;strip=all&amp;ssl=1 1183w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM35-OLED-Display-Schematic-Diagram.png?resize=300%2C258&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM35-OLED-Display-Schematic-Diagram.png?resize=768%2C660&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-LM35-OLED-Display-Schematic-Diagram.png?resize=1024%2C879&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1183px) 100vw, 1183px\" \/><\/a><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Installing OLED Libraries<\/h2>\n\n\n\n<p>To control the OLED display you need the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/adafruit\/Adafruit_SSD1306\" target=\"_blank\">adafruit_SSD1306.h<\/a>&nbsp;and the&nbsp;<a href=\"https:\/\/github.com\/adafruit\/Adafruit-GFX-Library\" target=\"_blank\" rel=\"noreferrer noopener\">adafruit_GFX.h<\/a>&nbsp;libraries. Follow the next instructions to install those libraries.<\/p>\n\n\n\n<p>1. Open your Arduino IDE and go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong>. The Library Manager should open.<\/p>\n\n\n\n<p>2. Type \u201c<strong>SSD1306<\/strong>\u201d in the search box and install the SSD1306 library from Adafruit.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"788\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/install-ssd1306-adafruit-library.png?resize=788%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing SSD1306 OLED Library  Arduino UNO board\" class=\"wp-image-85156\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/install-ssd1306-adafruit-library.png?w=788&amp;quality=100&amp;strip=all&amp;ssl=1 788w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/install-ssd1306-adafruit-library.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/install-ssd1306-adafruit-library.png?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 788px) 100vw, 788px\" \/><\/figure><\/div>\n\n\n\n<p>3. After installing the SSD1306 library from Adafruit, type \u201c<strong>GFX<\/strong>\u201d in the search box and install the library.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/install-gfx-library-adafruit.png?resize=786%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing GFX Library Arduino UNO board\" class=\"wp-image-85157\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/install-gfx-library-adafruit.png?w=786&amp;quality=100&amp;strip=all&amp;ssl=1 786w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/install-gfx-library-adafruit.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/install-gfx-library-adafruit.png?resize=768%2C433&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/figure><\/div>\n\n\n\n<p>4. After installing the libraries, restart your Arduino IDE.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code &#8211; Display Readings on OLED<\/h2>\n\n\n\n<p>After wiring the circuit and installing the required libraries, upload the following code to your Arduino board.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * Rui Santos\n * Complete Project Details https:\/\/RandomNerdTutorials.com\n *\/\n\n#include &lt;Wire.h&gt;\n#include &lt;Adafruit_GFX.h&gt;\n#include &lt;Adafruit_SSD1306.h&gt;\n\n#define SCREEN_WIDTH 128 \/\/ OLED display width, in pixels\n#define SCREEN_HEIGHT 64 \/\/ OLED display height, in pixels\n\n\/\/ declaration for an SSD1306 display connected to I2C (SDA, SCL pins)\nAdafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &amp;Wire, -1);\n\nconst int sensorPin = A0; \nfloat sensorValue;\nfloat voltageOut;\n\nfloat temperatureC;\nfloat temperatureF;\n\n\/\/ uncomment if using LM335\n\/\/float temperatureK;\n\nvoid setup() {\n  pinMode(sensorPin, INPUT);\n  Serial.begin(9600);\n\n  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {\n    Serial.println(F(&quot;SSD1306 allocation failed&quot;));\n    for(;;);\n  }\n  \n  delay(2000);\n  display.clearDisplay();\n  display.setTextColor(WHITE);\n}\n\nvoid loop() {\n  sensorValue = analogRead(sensorPin);\n  voltageOut = (sensorValue * 5000) \/ 1024;\n  \n  \/\/ calculate temperature for LM35 (LM35DZ)\n  temperatureC = voltageOut \/ 10;\n  temperatureF = (temperatureC * 1.8) + 32;\n\n  \/\/ calculate temperature for LM335\n  \/\/temperatureK = voltageOut \/ 10;\n  \/\/temperatureC = temperatureK - 273;\n  \/\/temperatureF = (temperatureC * 1.8) + 32;\n\n  \/\/ calculate temperature for LM34\n  \/\/temperatureF = voltageOut \/ 10;\n  \/\/temperatureC = (temperatureF - 32.0)*(5.0\/9.0);\n\n  Serial.print(&quot;Temperature(\u00baC): &quot;);\n  Serial.print(temperatureC);\n  Serial.print(&quot;  Temperature(\u00baF): &quot;);\n  Serial.print(temperatureF);\n\n  \/\/ clear display\n  display.clearDisplay();\n\n  \/\/ display temperature Celsius\n  display.setTextSize(1);\n  display.setCursor(0,0);\n  display.print(&quot;Temperature: &quot;);\n  display.setTextSize(2);\n  display.setCursor(0,10);\n  display.print(temperatureC);\n  display.print(&quot; &quot;);\n  display.setTextSize(1);\n  display.cp437(true);\n  display.write(167);\n  display.setTextSize(2);\n  display.print(&quot;C&quot;);\n\n  \/\/ display temperature Fahrenheit\n  display.setTextSize(1);\n  display.setCursor(0, 35);\n  display.print(&quot;Temperature: &quot;);\n  display.setTextSize(2);\n  display.setCursor(0, 45);\n  display.print(temperatureF);\n  display.print(&quot; &quot;);\n  display.setTextSize(1);\n  display.cp437(true);\n  display.write(167);\n  display.setTextSize(2);\n  display.print(&quot;F&quot;);\n\n  display.display();    \n  delay(1000);\n }\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Arduino\/Arduino_LM35_LM335_LM34_with_OLED.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Demonstration<\/h3>\n\n\n\n<p>Congratulations! You&#8217;ve completed the project. Now, you can check the sensor readings in the OLED display. New temperature readings are displayed every second.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"420\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-LM35DZ-LM34-LM335-Arduino-board-OLED-display-temperature-readings.jpg?resize=750%2C420&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LM35 LM35DZ LM34 LM335 Arduino board OLED display temperature readings\" class=\"wp-image-87268\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-LM35DZ-LM34-LM335-Arduino-board-OLED-display-temperature-readings.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-LM35DZ-LM34-LM335-Arduino-board-OLED-display-temperature-readings.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>The LM35, LM335 and LM34 are linear temperature sensors that output a voltage proportional to the temperature value. They can be powered by the Arduino 5V pin, and to read the voltage, you use an analog pin.<\/p>\n\n\n\n<p>Reading the voltage from the sensor is as easy as using the <span class=\"rnthl rntliteral\">analogRead()<\/span> function on the sensor pin. Then, you just need to make a simple calculation to get the temperature in your desired unit.<\/p>\n\n\n\n<p>We hope you&#8217;ve found this guide useful. We have other guides about Arduino sensors and modules that you may like:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/bme280-sensor-arduino-pressure-temperature-humidity\/\">BME280 Sensor with Arduino (Pressure, Temperature, Humidity)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-ds18b20-temperature-sensor-with-arduino\/\">DS18B20 Temperature Sensor with Arduino<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/complete-guide-for-dht11dht22-humidity-and-temperature-sensor-with-arduino\/\">DHT11\/DHT22 Humidity and Temperature Sensor With Arduino<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-oled-display-with-arduino\/\">0.96 inch I2C OLED Display with Arduino<\/a><\/li><\/ul>\n\n\n\n<p>If you like Arduino, you&#8217;ll also like our Arduino Course: <strong><a href=\"https:\/\/randomnerdtutorials.com\/arduino-step-by-step-projects\/\">Arduino Step-by-step Projects<\/a><\/strong><\/p>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide shows how to use the LM35 (LM35DZ), LM335 and LM34 temperature sensors with the Arduino board. We&#8217;ll show you how to wire the sensors and write the code &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Guide for LM35, LM335 and LM34 Temperature Sensors with Arduino\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/arduino-lm35-lm335-lm34-temperature-sensor\/#more-87221\" aria-label=\"Read more about Guide for LM35, LM335 and LM34 Temperature Sensors with Arduino\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":87269,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[267,2,302,245,264],"tags":[],"class_list":["post-87221","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino-project","category-arduino","category-0-guide","category-arduino-ide","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/LM35-LM35DZ-LM34-LM335-Arduino-board-OLED-Temperature.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/87221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=87221"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/87221\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/87269"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=87221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=87221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=87221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}