Arduino UNO R4 - Temperature Sensor - LCD

This tutorial instructs you how to use Arduino UNO R4 to read temperature value from DS18B20 one-wire temperature sensor and display it on LCD I2C.

Arduino UNO R4 Temperature Sensor LCD I2C

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Arduino UNO R4 Minima (Alternatively)
1×USB Cable Type-C
1×LCD I2C
1×DS18B20 Temperature Sensor (WITH Adapter)
1×DS18B20 Temperature Sensor (WITHOUT Adapter)
1×Jumper Wires
1×(Recommended) Screw Terminal Block Shield for Arduino UNO R4
1×(Recommended) Breadboard Shield For Arduino UNO R4
1×(Recommended) Enclosure For Arduino UNO R4

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of Temperature Sensor and LCD

Learn about temperature sensors and LCDs, including their pinout, functions, and programming, in the tutorials linked below:

Wiring Diagram

The wiring diagram between Arduino UNO R4 Temperature Sensor LCD

This image is created using Fritzing. Click to enlarge image

Arduino UNO R4 Code

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-temperature-sensor-lcd */ #include <OneWire.h> #include <DallasTemperature.h> #include <LiquidCrystal_I2C.h> #define SENSOR_PIN 2 // The Arduino UNO R4 pin connected to DS18B20 sensor's DQ pin OneWire oneWire(SENSOR_PIN); // setup a oneWire instance DallasTemperature DS18B20(&oneWire); // pass oneWire to DallasTemperature library LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27 (from DIYables LCD), 16 column and 2 rows float temperature_C; // temperature in Celsius float temperature_F; // temperature in Fahrenheit void setup() { DS18B20.begin(); // initialize the sensor lcd.init(); // initialize the lcd lcd.backlight(); // open the backlight } void loop() { DS18B20.requestTemperatures(); // send the command to get temperatures temperature_C = DS18B20.getTempCByIndex(0); // read temperature in Celsius temperature_F = temperature_C * 9 / 5 + 32; // convert Celsius to Fahrenheit lcd.clear(); lcd.setCursor(0, 0); // start to print at the first row lcd.print(temperature_C); // print the temperature in Celsius lcd.print((char)223); // print ° character lcd.print("C"); lcd.setCursor(0, 1); // start to print at the second row lcd.print(temperature_F); // print the temperature in Fahrenheit lcd.print((char)223); // print ° character lcd.print("F"); delay(500); }

※ NOTE THAT:

The I2C address for the LCD might change depending on the maker. In our code, we used 0x27, which is the address given by the manufacturer DIYables.

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Connect the Arduino Uno R4 to the DS18B20 temperature sensor and LCD I2C according to the provided diagram.
  • Connect the Arduino Uno R4 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Click on the Libraries icon on the left side of the Arduino IDE.
  • Search for DallasTemperature and find the library by Miles Burton.
  • Click the Install button to add the DallasTemperature library.
Arduino UNO R4 Dallas Temperature library
  • You need to install a library dependency
  • Click the Install All button to install the OneWire library.
Arduino UNO R4 onewire library
  • Search for LiquidCrystal I2C and find the LiquidCrystal_I2C library by Frank de Brabander.
  • Click the Install button to install the LiquidCrystal_I2C library.
Arduino UNO R4 LiquidCrystal I2C library
  • Copy the code and open it using Arduino IDE
  • Click the Upload button in Arduino IDE to send the code to Arduino UNO R4
Arduino IDE Upload Code
  • Place the sensor on hot or cold water, or hold it in your hand.
  • Check the display on the LCD screen.

If the LCD shows nothing, check Troubleshooting for LCD I2C.

Code Explanation

Check the explanation in the source code comments for details on each line!

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!