ESP32 UNO - Temperature Sensor - LCD
Need a small thermometer that works without a computer? Connect a DS18B20 to the ESP32 Uno form board and print the temperature on a 16x2 LCD I2C screen. The top row shows degrees Celsius and the bottom row shows Fahrenheit, so one glance tells you how warm the water or the room is.
By the end, you can:
- Connect a DS18B20 probe and a 16x2 I2C screen to the ESP32 Uno
- Add three libraries from the Library Manager
- Read the sensor with getTempCByIndex() and convert °C to °F
- Show both values on the LCD screen

Components You Need
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
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.
The Two Parts in Short
After this part, you know what each part does in the circuit.
| Part | Job | Connection | Supply |
|---|---|---|---|
| DS18B20 | Measures the temperature | One data wire (one-wire bus) | 3.0V to 5.5V |
| LCD I2C 16x2 | Shows two lines of 16 characters | I2C (SDA and SCL) | 5V |
The DS18B20 sends a digital number, so the ADC is not used here. The LCD needs only the two I2C lines.
Want the pinout and the basic sketch of each part? Read these guides first:
ESP32 Uno Pinout
Header labels such as D2, SDA and SCL are not the numbers you type in code. Look at the picture to match each label with its GPIO number before you place a wire.

How to Connect
When this step is done, the sensor data wire is on D2 and the screen is on the SDA and SCL header pins.

This image is created using Fritzing. Click to enlarge image
※ NOTE THAT:
The wiring diagram may not show the correct wiring for the ESP32 Uno. The LCD backpack pulls SDA and SCL up to 5V, but ESP32 Uno pins are 3.3V only. The picture shows the LCD wired straight to SDA and SCL. We suggest a level converter between the LCD and the board, as the hardware list shows. We will update the diagram soon. Until then, follow the wiring table and the text on this page, not the picture.
| Component Pin | ESP32 Uno Pin |
|---|---|
| DS18B20 VCC | 3.3V |
| DS18B20 GND | GND |
| DS18B20 DQ (data) | D2 (GPIO26) |
| LCD VCC | 5V |
| LCD GND | GND |
| LCD SDA | SDA (GPIO21) |
| LCD SCL | SCL (GPIO22) |
Good to know: the adapter version of the DS18B20 has a pull-up resistor on board. A bare sensor needs a 4.7 kΩ resistor between DQ and 3.3V.
WARNING
The signal pins of the ESP32 Uno work at 3.3V and cannot take 5V. Some LCD backpacks tie SDA and SCL to 5V with pull-up resistors. If yours does, use a 5V to 3.3V level converter on SDA and SCL, or remove the pull-up resistors from the backpack.
※ NOTE THAT:
Do not wire the LCD to A4 and A5 here. The LCD belongs on the pins marked SDA and SCL.
Code
The sketch measures every 500 ms, turns the Celsius value into Fahrenheit, and writes both on the LCD.
※ NOTE THAT:
LCD makers use different I2C addresses. The sketch uses 0x27, the address of the DIYables LCD. If the screen stays blank, scan for the real address and change it in the code.
Upload and Test
Follow these steps in order:
- First time with this board? Set it up with ESP32 Uno - Getting Started before you continue.
- Build the circuit by following the wiring table above.
- Plug in the USB Type-C cable between the ESP32 Uno and your computer.
- Select the board in Arduino IDE: pick ESP32 Dev Module and the COM port of the board (CH340).
- Open the Library Manager by pressing the Libraries button in the side bar of Arduino IDE.
- Get DallasTemperature: type DallasTemperature in the search box, choose the one by Miles Burton, then press Install.
- Search for DallasTemperature created by Miles Burton
, Tim Newsome , Guil Barros , Rob Tillaart and click the Install button.
- Install the dependency: click Install All when the IDE offers the OneWire library.
- Get the LCD library: type DIYables LCD I2C, choose DIYables_LCD_I2C from DIYables, then press Install.
- Search for DIYables LCD I2C created by DIYables.io and click the Install button.
- Copy the code into Arduino IDE.
- Send the sketch to the board with the Upload arrow.

- Test it: hold the sensor between your fingers, or dip it in cold or warm water.
- Watch the LCD: the numbers rise or fall within a few seconds.
- Pro tip: put the sensor in a glass of ice water. A good sensor shows a value close to 0°C.
If the LCD shows nothing, read Troubleshooting for LCD I2C.
On the LCD you will see something like this:
| LCD Row | Example Text |
|---|---|
| Row 1 | 23.81°C |
| Row 2 | 74.86°F |
Video Tutorial
See the ESP32 Uno build in action in the video below.
Code Explanation
Each line has a comment, and this table gives the big picture.
| Code Part | What It Does |
|---|---|
| SENSOR_PIN 26 | Sets D2 (GPIO26) as the one-wire data pin |
| DS18B20.begin() | Starts the sensor on the bus |
| lcd.init() and lcd.backlight() | Starts the screen and turns on the light |
| requestTemperatures() | Tells the sensor to take a new measurement |
| getTempCByIndex(0) | Gets the Celsius value of the first sensor on the bus |
| (char)223 | Prints the degree sign on the LCD |
The loop clears the screen, prints both rows, and waits 500 ms.
ESP32 Uno vs UNO R4 for This Project
Moving this thermometer from the UNO R4 to the ESP32 Uno needs only a new pin number in the code.
| Item | Arduino UNO R4 | ESP32 Uno |
|---|---|---|
| Logic voltage | 5V | 3.3V |
| DS18B20 data pin | D2 | D2 (GPIO26), so SENSOR_PIN is 26 |
| LCD I2C pins | SDA and SCL | SDA (GPIO21) and SCL (GPIO22) |
| Libraries | DallasTemperature, OneWire, DIYables_LCD_I2C | same libraries |
| Arduino IDE board | Arduino UNO R4 WiFi | ESP32 Dev Module |
The wiring stays on the same header positions. Power the sensor from 3.3V and check the LCD I2C lines if the backpack pulls them up to 5V.
Go Wireless: Thermometer on Your Phone
Show the same temperature on a phone as well as on the LCD.
The ESP32 Uno has WiFi and Bluetooth. You can send the DS18B20 value to a web page or to a Bluetooth app, so you can read the room temperature from another room. Pick one of these guides to add it:
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port in Arduino IDE | CH340 driver missing or a charge-only USB cable | Install the CH340 driver and use a data USB cable |
| Failed to connect or Waiting for download | Board is not in upload mode | Hold the BOOT button while the upload starts |
| LCD shows nothing | No power, or wires on A4 and A5 | Power the LCD from 5V and use the SDA (GPIO21) and SCL (GPIO22) header pins |
| Backlight on but no text | Wrong I2C address or low contrast | Scan for the address, fix it in the code, and turn the contrast screw |
| LCD shows -127.00 | The sensor is not found | Check DQ on D2 (GPIO26), GND, and the 4.7 kΩ pull-up |
| LCD shows 85.00 | Sensor reports its power-on value | Check the VCC and GND wires and power the sensor from 3.3V |
| Compile error for a missing header | Library not installed | Install DallasTemperature, OneWire and DIYables_LCD_I2C |
| Values jump around | Long wires or a warm board close to the sensor | Use shorter wires and keep the sensor away from the board |
FAQ
What is the DS18B20 and how accurate is it?
It is a digital one-wire temperature sensor. Its range is -55°C to 125°C, and it is within ±0.5°C from -10°C to 85°C.
Can the DS18B20 run from 3.3V on the ESP32 Uno?
Yes. The supply range is 3.0V up to 5.5V. At 3.3V the data line stays at a level that the ESP32 Uno pins accept.
Why is the LCD on SDA and SCL and not on A4 and A5?
On this board A4 and A5 are only input pins and they are not I2C. The I2C bus sits on its own header pins, SDA (GPIO21) and SCL (GPIO22). Wire.begin() picks them automatically.
Do I need a pull-up resistor for the DS18B20?
The adapter version has one already. A bare sensor needs a 4.7 kΩ resistor between DQ and 3.3V.
Can I use a different pin for the data wire?
Yes. Most I/O pins work for a one-wire bus. Change SENSOR_PIN to a GPIO number, for example 14 for D7. Avoid D8 (GPIO12) and D10 (GPIO5), because they are boot strapping pins.
How do I connect two DS18B20 sensors?
Join all DQ wires on the same pin. Read the first sensor with getTempCByIndex(0) and the second with getTempCByIndex(1), then print each on its own LCD row.
Why does the LCD show 85.00 or -127.00?
85.00 is the power-on value and -127.00 means the library lost the sensor. Both point to a loose wire, weak power or a missing pull-up resistor.
Does this sketch need analogSetAttenuation on the ESP32 Uno?
No. The DS18B20 is digital, so the ADC is not used and no attenuation line is needed.
Can I use an LCD shield from the UNO on the ESP32 Uno?
Not this one. This project uses an I2C LCD with four wires, which fits the board. Shields that expect 5V logic or the R4 pin layout may not work, so check the pins first.
Can I read the temperature on my phone with the ESP32 Uno?
Yes. The ESP32 Uno has WiFi and Bluetooth, so you can send the same value to a web page or a Bluetooth app. See the Go Wireless section for links.
What if I run out of pins on the Uno headers?
The ESP32 Uno has a few extra holes near the power header. GPIO32 and GPIO33 are I/O, PWM and analog on ADC1, so they also work while WiFi is on. GPIO15 is I/O, PWM and analog on ADC2. Solder headers on the holes first. Then type the GPIO number in your sketch. For a second sensor bus, GPIO32 or GPIO33 is a good choice. Two warnings. First, GPIO15 and GPIO0 (the IO0 pin at the unused Uno NC position) are boot strapping pins, so a wrong connection can stop the board from booting or uploading code. Use GPIO32 and GPIO33 first. Second, never use the six holes under the digital header (SD0 to SD3, CMD and CLK, which are GPIO6 to GPIO11). They are wired to the flash chip and using them crashes the board.