ESP32 S3 UNO - Temperature Sensor - LCD

This ESP32 S3 Uno temperature sensor LCD tutorial shows you how to build a small digital thermometer. The ESP32 S3 Uno form board reads a DS18B20 one-wire temperature sensor and shows the value on a 16x2 LCD I2C display. You see the temperature in both Celsius and Fahrenheit, updated twice per second.

In this tutorial, you will:

  1. Wire a DS18B20 temperature sensor and an LCD I2C to the ESP32 S3 Uno
  2. Install the DallasTemperature, OneWire and DIYables LCD I2C libraries in Arduino IDE
  3. Read the DS18B20 temperature in °C and convert it to °F
  4. Display the temperature on the LCD I2C screen
ESP32 S3 Uno temperature sensor LCD

Hardware Preparation

1×ESP32 S3 Uno-form Board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×LCD I2C Display 3.3V
1×Alternatively, LCD I2C 20x4
1×DS18B20 Temperature Sensor (WITH Adapter)
1×DS18B20 Temperature Sensor (WITHOUT Adapter)
1×Jumper Wires
1×5V to 3.3V Level Converter (Optional, for SDA and SCL)

Or you can buy the following kits:

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 .

Buy Note: Many DS18B20 sensors available in the market are unreliable. We strongly recommend buying the sensor from the DIYables brand using the link provided above. We tested it, and it worked reliably.

Buy Note: Most LCD I2C displays available on the market are 5V displays. They may work with this board, but it is unsafe and can damage the board. We strongly recommend using the 3.3V LCD I2C display recommended above.

Overview of Temperature Sensor and LCD

This project joins two parts that each have their own tutorial. If you have never used one of them, read its tutorial first. There you learn the pinout, how the part works, and the basic code.

  1. ESP32 S3 Uno - Temperature Sensor tutorial covers the DS18B20 sensor and the one-wire bus.
  2. ESP32 S3 Uno - LCD I2C tutorial covers the 16x2 LCD, its I2C address and how to print text.

The DS18B20 sends a digital value over a single data wire, so the ESP32 S3 Uno does not need its ADC here. The LCD only needs the two I2C lines, SDA and SCL.

ESP32 S3 Uno Pinout

The image below shows the pinout of the ESP32 S3 Uno form board. Use it to find the D2, SDA and SCL header pins and their GPIO numbers before you wire the circuit.

ESP32 S3 Uno pinout diagram

Wiring Diagram

The DS18B20 data pin goes to D2, and the LCD goes to the SDA and SCL header pins. Follow the diagram and the table below.

The wiring diagram between ESP32 S3 Uno Temperature Sensor LCD

This image is created using Fritzing. Click to enlarge image

Component Pin ESP32 S3 Uno Pin
DS18B20 VCC 3.3V
DS18B20 GND GND
DS18B20 DQ (data) D2 (GPIO18)
LCD VCC 5V
LCD GND GND
LCD SDA SDA (GPIO8)
LCD SCL SCL (GPIO9)

If you use the DS18B20 without an adapter, add a 4.7 kΩ pull-up resistor between the DQ pin and 3.3V. The adapter module already has this resistor.

WARNING

The ESP32 S3 Uno pins work at 3.3V and are NOT 5V tolerant. Power the DS18B20 from 3.3V, so its pull-up keeps the data line at 3.3V. Many LCD I2C backpacks pull SDA and SCL up to their own 5V supply. To keep the board safe, pass SDA and SCL through a bidirectional 5V to 3.3V level converter, or remove the pull-up resistors on the LCD backpack.

※ NOTE THAT:

On the ESP32 S3 Uno, A4 and A5 are NOT I2C pins. Always wire the LCD to the SDA and SCL header pins.

ESP32 S3 Uno Code

The sketch asks the DS18B20 for a new reading every 500 ms. It reads the temperature in Celsius, converts it to Fahrenheit, then prints °C on the first LCD row and °F on the second row. The sensor data pin is set to GPIO18, which is the D2 header pin.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-temperature-sensor-lcd */ #include <OneWire.h> #include <DallasTemperature.h> #include <DIYables_LCD_I2C.h> #define SENSOR_PIN 18 // The ESP32 S3 Uno pin D2 (GPIO18) connected to DS18B20 sensor's DQ pin OneWire oneWire(SENSOR_PIN); // setup a oneWire instance DallasTemperature DS18B20(&oneWire); // pass oneWire to DallasTemperature library DIYables_LCD_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 of an LCD can be different from one maker to another. The code uses 0x27, which is the address of the DIYables LCD. If your screen stays empty, scan for the address and change it in the code.

Detailed Instructions

Do these steps in order:

  1. New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
  2. Wire it up as shown in the diagram.
  3. Connect the board to your computer with a USB Type-C cable.
  4. Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
  5. Open the Library Manager by clicking the Libraries icon on the left side of Arduino IDE.
  6. Install DallasTemperature: search for DallasTemperature, find the library by Miles Burton and click Install.
  • Search for DallasTemperature created by Miles Burton , Tim Newsome , Guil Barros , Rob Tillaart and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
DallasTemperature by Miles Burton , Tim Newsome , Guil Barros , Rob Tillaart
Supports DS18B20, DS18S20, DS1822, DS1820 More info
3.9.0
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. Install the dependency: Arduino IDE asks to install the OneWire library too. Click Install All.
  2. Install the LCD library: search for DIYables LCD I2C, find the DIYables_LCD_I2C library by DIYables and click Install.
  • Search for DIYables LCD I2C created by DIYables.io and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
DIYables LCD I2C by DIYables.io
This library is designed for HD44780-based I2C LCD displays. It provides LiquidCrystal-compatible API plus helper functions (text alignment, progress bars, predefined custom characters). Supports multiple I2C buses (Wire, Wire1, Wire2) for advanced boards like Arduino Giga, Due, and ESP32. Compatible with all Arduino-based platforms including Arduino Uno, Mega, Nano, ESP32, ESP8266, STM32, and Raspberry Pi Pico. More info
1.0.0
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. Copy the code above and paste it into Arduino IDE.
  2. Upload the code by clicking the Upload button.
Arduino IDE Upload Code
  1. Test it: hold the sensor in your hand, or put it in hot or cold water.
  2. Look at the LCD: the first row shows °C and the second row shows °F. The numbers change as the sensor warms up or cools down.
  3. Tip: if the LCD shows -127.00, the board cannot find the sensor. Check the DQ wire on D2 (GPIO18) and the pull-up resistor.

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

Code Explanation

The comments in the code explain each line. In short, DS18B20.begin() starts the one-wire sensor, and lcd.init() with lcd.backlight() starts the screen. In the loop, requestTemperatures() starts a new reading and getTempCByIndex(0) gets the value from the first sensor on the bus. The code prints (char)223 to show the degree sign (°) on the LCD.

Video Tutorial

Watch the video below to see this ESP32 S3 Uno project step by step.

FAQ

Can I power the DS18B20 from 3.3V on the ESP32 S3 Uno?

Yes. The DS18B20 works from 3.0V to 5.5V, so 3.3V is fine. Powering it from 3.3V is the safe choice, because the pull-up resistor then keeps the data line at 3.3V, which the ESP32 S3 Uno pins can handle.

Why is the LCD wired to SDA and SCL and not to A4 and A5?

On the UNO R4, A4 and A5 are the I2C pins. On the ESP32 S3 Uno they are only analog pins. I2C is on the separate SDA (GPIO8) and SCL (GPIO9) header pins, and Wire.begin() uses them by default.

Why does the LCD show -127.00?

The value -127 means the DallasTemperature library could not talk to the sensor. Usually the DQ wire is loose, it is on the wrong pin, or the 4.7 kΩ pull-up resistor is missing when you use the sensor without an adapter.

Can I use other pins for the DS18B20?

Yes. Any normal I/O pin works for a one-wire bus. Change SENSOR_PIN to the GPIO number, not the D label. For example, D7 is 14. Avoid D6 (GPIO3) and D9 (GPIO46), because they are boot strapping pins.

Can I connect more than one DS18B20 to the same pin?

Yes. All DS18B20 sensors can share one data wire. Read each one with getTempCByIndex(0), getTempCByIndex(1) and so on, then print them on the LCD rows.

What if my project needs more pins than the Uno headers give?

The ESP32 S3 Uno has two extra rows of holes with more GPIOs. GPIO15 and GPIO16 support I/O, PWM and analog. GPIO45 and GPIO35 to GPIO42 support I/O and PWM. GPIO47 and GPIO48 are output only, with PWM. Solder pin headers to use them and write the GPIO number in code. For an extra DS18B20 bus or a button, GPIO35 to GPIO42 are a good choice. Do not use GPIO47/GPIO48 for inputs. Be careful with two things. First, GPIO47 and GPIO48 may run at 1.8V instead of 3.3V on some modules (especially ones with "V" in the name, like R8V or R16V), so 3.3V devices can be damaged or act strangely. Second, GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code. Use the other extra pins first.

Troubleshooting

Problem Possible Cause Solution
No COM port in Arduino IDE USB driver is missing or the board is not in upload mode Install the CP210x or CH340 driver, or hold BOOT while pressing RESET
LCD shows nothing at all LCD not powered, or SDA/SCL wired to A4/A5 Power the LCD from 5V and wire SDA and SCL to the SDA (GPIO8) and SCL (GPIO9) header pins
LCD backlight is on but there is no text Wrong I2C address or low contrast Run an I2C scanner, set the right address in the code, and turn the contrast screw on the backpack
LCD shows -127.00 The board cannot find the DS18B20 Check the DQ wire on D2 (GPIO18), the GND wire, and the 4.7 kΩ pull-up resistor
LCD shows 85.00 all the time The sensor gives its power-on value, often from weak power Check the VCC and GND wires and power the sensor from 3.3V
Compile error about DallasTemperature.h or DIYables_LCD_I2C.h A library is not installed Install DallasTemperature, OneWire and DIYables_LCD_I2C from the Library Manager
Temperature looks wrong or jumps Sensor is touching a warm part, or the wires are long and noisy Keep the sensor away from the board and use shorter wires

※ 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!