ESP32 UNO - Temperature Sensor - OLED
Want a pocket thermometer built with the ESP32 Uno? Connect a DS18B20 sensor and an SSD1306 OLED to the ESP32 Uno form board, and the temperature appears on the screen in big text. No computer is needed once the code is uploaded. You can also read the same value in the Serial Monitor.
By the end, you can:
- Wire a DS18B20 temperature sensor and an I2C OLED to the board
- Install the SSD1306, DallasTemperature and OneWire libraries
- Read degrees Celsius from the sensor with Arduino code
- Draw the value in the center of the OLED 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: If you want a bigger OLED display, use the 2.42 inch OLED Display 128x64 .
How the Sensor and the OLED Work Together
By the end of this part, you know what each module does. The DS18B20 measures the temperature. The OLED shows the number.
| Part | Job | Connection |
|---|---|---|
| DS18B20 | Measures temperature and sends it as digital data | One data wire (1-Wire) |
| SSD1306 OLED | Draws text and shapes on a 128x64 screen | Two wires (I2C SDA and SCL) |
Each part has its own tutorial with the pinout and more code examples:
Good to know: the ESP32 Uno runs at 3.3V logic. Both the DS18B20 and the SSD1306 work fine at 3.3V, so power them from the 3V3 pin.
ESP32 Uno Pinout
Every Uno header pin on the ESP32 Uno form board has a GPIO number, and the code uses that number. Look at the diagram to find D4, SDA and SCL before you place any wire.

How to Connect
By the end of this part, both modules are wired. The sensor data wire goes to D4 (GPIO17). The OLED uses 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 pin. On the ESP32 Uno, the DS18B20 DATA wire goes to D4 (GPIO17), not D8 as the picture may show. We will update the diagram soon. Until then, follow the wiring table and the code on this page, not the picture.
| Component Pin | ESP32 Uno Pin |
|---|---|
| DS18B20 VCC | 3.3V |
| DS18B20 GND | GND |
| DS18B20 DATA | D4 (GPIO17) |
| DS18B20 4.7kΩ pull-up | Between DATA and 3.3V |
| OLED VCC | 3.3V |
| OLED GND | GND |
| OLED SDA | SDA (GPIO21) |
| OLED SCL | SCL (GPIO22) |
Good to know: pick a DS18B20 sensor with a wiring adapter. The adapter has the pull-up resistor built in. With a bare sensor, add a 4.7kΩ resistor between DATA and 3.3V.
※ NOTE THAT:
Do not wire the OLED to A4 and A5 on this board, they are not I2C. Use the SDA (GPIO21) and SCL (GPIO22) header pins for the OLED.
ESP32 Uno Code - Show DS18B20 Temperature on the OLED
The sketch reads the sensor in a loop, builds a text like 24.37°C, prints it and draws it in the center of the screen.
| Code Part | What It Does |
|---|---|
| SENSOR_PIN 17 | Sets the 1-Wire data pin to GPIO17, which is header D4 |
| oled.begin(...0x3C) | Starts the OLED at I2C address 0x3C |
| requestTemperatures() | Tells the DS18B20 to measure |
| getTempCByIndex(0) | Returns the first sensor value in Celsius |
| oled_display_center() | Measures the text and puts it in the middle of the screen |
The result is a reading that refreshes on the OLED every time the loop runs.
Upload and Test
- 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 clicking the Libraries icon in the left bar.
- Search for "SSD1306" and find the library by Adafruit.
- Click Install to add it.
- Search for Adafruit SSD1306 created by Adafruit and click the Install button.
- Accept the dependencies. Click Install All to add Adafruit GFX and the other required libraries.
- Search for Adafruit GFX Library created by Adafruit and click the Install button.
- Search for "DallasTemperature" and find the library by Miles Burton.
- Click Install to add it.
- Search for DallasTemperature created by Miles Burton
, Tim Newsome , Guil Barros , Rob Tillaart and click the Install button.
- Accept the dependency. Click Install All to add the OneWire library.
- Search for OneWire created by Jim Studt, Tom Pollard, Robin James, Glenn Trewitt, Jason Dangel, Guillermo Lovato, Paul Stoffregen, Scott Roberts, Bertrik Sikken, Mark Tillotson, Ken Butcher, Roger Clark, Love Nystrom and click the Install button.
- Copy the sketch from the code box and paste it in a new Arduino IDE window.
- Click Upload. If the upload fails, hold the BOOT button while the upload starts.
- Change the temperature. Hold the sensor in your hand or dip it in warm or cold water.
- Look at the OLED and at the Serial Monitor (9600 baud).
- Pro tip: seal the sensor tip in a thin plastic bag before you dip it in water, unless you have the waterproof version.
※ NOTE THAT:
The code finds the middle of the screen on its own. No manual cursor values needed.
Video Tutorial
See the ESP32 Uno build in action in the video below.
ESP32 Uno vs UNO R4 for This Project
By the end of this part, you know what changes when you move this thermometer from the UNO R4 to the ESP32 Uno.
| Item | Arduino UNO R4 | ESP32 Uno |
|---|---|---|
| Logic voltage | 5V | 3.3V |
| Sensor pin in code | 8 (D8) | 17 (D4 is GPIO17) |
| OLED I2C pins | SDA and SCL header | SDA (GPIO21) and SCL (GPIO22) header |
| Libraries | Adafruit SSD1306, DallasTemperature, OneWire | same libraries, no change |
| Wireless | WiFi only on the WiFi model | WiFi and Bluetooth built in |
| Arduino IDE board | Arduino UNO R4 WiFi | ESP32 Dev Module |
The wiring is almost the same on both boards. Power the modules from 3.3V on the ESP32 Uno, but move the DATA wire to D4 (GPIO17). D8 (GPIO12) is a boot pin on the ESP32 Uno, so the picture pin does not work.
Go Wireless: Temperature on Your Phone
By the end of this part, you know how to read this sensor without looking at the OLED.
The ESP32 Uno has WiFi and Bluetooth. You can send the DS18B20 value to a web page or to a phone app, then watch it live or draw a graph. The OLED stays as a local display.
Try These Next
- Show the temperature in Fahrenheit with getTempFByIndex(0)
- Use the 128x32 OLED and change OLED_HEIGHT to 32
- Print the highest and lowest temperature on a second line
- Turn on a fan or a buzzer when the value goes above a limit
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port in Arduino IDE | CH340 driver missing or charge-only cable | Install the CH340 driver and use a USB cable that carries data |
| Failed to connect or Waiting for download | Board not in download mode | Hold the BOOT button while the upload starts |
| OLED stays blank | Wrong wires or wrong I2C address | Use SDA (GPIO21) and SCL (GPIO22), not A4 and A5, and try address 0x3D |
| Serial Monitor shows SSD1306 allocation failed | OLED not found on the I2C bus | Check the power and the two I2C wires, then press RESET |
| Display shows -127.00°C | The sensor is not found on the 1-Wire bus | Check DATA on D4, GND, and the 4.7kΩ pull-up to 3.3V |
| Display shows 85.00°C | The sensor did not finish the measurement or has weak power | Check the VCC wire and the 3.3V supply |
| Text is off-center on a 128x32 screen | OLED_HEIGHT is still 64 | Set OLED_HEIGHT to 32 |
| Compile error about a missing header | A library is not installed | Install SSD1306, GFX, DallasTemperature and OneWire |
FAQ
How does a DS18B20 send the temperature to the ESP32 Uno?
It uses one data wire and the 1-Wire protocol. The sensor sends a digital number, so you do not need an ADC pin. The DallasTemperature library turns the number into degrees.
How accurate is the DS18B20?
It is about plus or minus 0.5°C between -10°C and +85°C. It reads from -55°C to +125°C.
Can I power the DS18B20 from 5V on the ESP32 Uno?
Avoid it. The ESP32 Uno pins are not 5V tolerant, and a 5V pull-up would push 5V into the DATA pin. The sensor works from 3.0V to 5.5V, so use 3.3V.
Do I need a pull-up resistor?
Yes, a 4.7kΩ resistor from DATA to 3.3V. The sensor adapter board already has one. A bare sensor needs it added.
Why is SENSOR_PIN 17 in the code and not 4?
The Uno header label is D4, but the code uses the GPIO number. D4 is GPIO17 on the ESP32 Uno.
Which I2C pins does the OLED use on the ESP32 Uno?
Pins SDA (GPIO21) and SCL (GPIO22) on the header. The default Wire.begin() call picks them. A4 and A5 are analog input pins only.
Do I need an ADC setting for this sensor?
No. The DS18B20 is a digital sensor, so the code never calls analogRead(). The ADC range does not matter here.
Can I use more than one DS18B20?
Yes. All sensors share the same data wire. Use getTempCByIndex(1) for the second one, and so on.
Can I show the temperature on a web page with the ESP32 Uno?
Yes. The board has WiFi and Bluetooth. See the Go Wireless section for ready tutorials.
What if my project needs more pins than the Uno headers give?
The ESP32 Uno has a few extra holes near the power header. GPIO32 and GPIO33 are I/O, PWM and analog pins on ADC1, so they also work while WiFi is on. GPIO15 is I/O, PWM and analog on ADC2. Solder pin headers to use them and write the GPIO number in code. For a second 1-Wire 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, and a wrong connection can stop the board from booting or uploading code, so use GPIO32 and GPIO33 first. Second, never use the six holes under the digital header (SD0 to SD3, CMD, CLK = GPIO6 to GPIO11). They are wired to the flash chip, and using them crashes the board.