ESP32 S3 UNO - Temperature Sensor - OLED

This ESP32 S3 Uno temperature sensor OLED tutorial shows you how to build a small digital thermometer. You will wire a DS18B20 one-wire temperature sensor and an SSD1306 OLED display to the ESP32 S3 Uno form board. The board reads the temperature in Celsius and shows it in the middle of the OLED screen.

In this tutorial, you will:

  1. Wire a DS18B20 sensor and an I2C OLED display to the ESP32 S3 Uno
  2. Install the Adafruit SSD1306, DallasTemperature and OneWire libraries in Arduino IDE
  3. Read the DS18B20 temperature with Arduino code
  4. Show the temperature on an OLED display, centered on the screen
ESP32 S3 Uno temperature sensor OLED

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×SSD1306 I2C OLED Display 128x64
1×SSD1306 I2C OLED Display 128x32
1×DS18B20 Temperature Sensor (WITH Adapter)
1×DS18B20 Temperature Sensor (WITHOUT Adapter)
1×Breadboard
1×Jumper Wires

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: If you want a bigger OLED display, use the 2.42 inch OLED Display 128x64 .

Overview of OLED and DS18B20 Temperature Sensor

This project joins a sensor and a display. The DS18B20 measures the temperature, and the OLED shows the value, so you can read it without a computer. If one of these parts is new to you, learn it alone first. The tutorials below explain the pinout, how each part works, and how to program it.

How the project works

The DS18B20 is a digital sensor. It sends the temperature over a single data wire, using the 1-Wire protocol. The DallasTemperature library asks the sensor for a new reading and turns the answer into degrees Celsius.

The OLED display talks to the ESP32 S3 Uno over I2C, with only two signal wires (SDA and SCL). The code writes the temperature as text and puts it in the center of the screen.

ESP32 S3 Uno Pinout

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

ESP32 S3 Uno pinout diagram

Wiring Diagram

The DS18B20 data wire goes to D8. The OLED display uses the SDA and SCL header pins. Both parts run fine from the 3.3V pin.

The wiring diagram between ESP32 S3 Uno DS18B20 Temperature Sensor OLED

This image is created using Fritzing. Click to enlarge image

Component Pin ESP32 S3 Uno Pin
DS18B20 VCC (red) 3.3V
DS18B20 GND (black) GND
DS18B20 DATA (yellow) D8 (GPIO21)
OLED VCC 3.3V
OLED GND GND
OLED SDA SDA (GPIO8)
OLED SCL SCL (GPIO9)

A DS18B20 sensor with a wiring adapter is the easiest choice. The adapter already has the pull-up resistor on board, so you do not need to add one. If you use the bare sensor without the adapter, put a 4.7 kΩ resistor between the DATA wire and 3.3V.

WARNING

The ESP32 S3 Uno pins are NOT 5V tolerant. Power the DS18B20 and its pull-up resistor from 3.3V, not 5V. Then the DATA line never goes above 3.3V.

※ NOTE THAT:

On the ESP32 S3 Uno, A4 and A5 are NOT I2C pins. Always connect the OLED to the SDA (GPIO8) and SCL (GPIO9) header pins.

ESP32 S3 Uno Code - Temperature from DS18B20 Temperature Sensor and display it on OLED

The sketch asks the DS18B20 for a new reading in every loop and gets the temperature in Celsius. It turns the number into text with two decimal places and a degree sign, prints it to the Serial Monitor, and shows it in the center of the OLED. The sensor pin is 21, which is the GPIO number of header D8.

/* * 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-oled */ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <OneWire.h> #include <DallasTemperature.h> #define OLED_WIDTH 128 // OLED display width, in pixels #define OLED_HEIGHT 64 // OLED display height, in pixels #define SENSOR_PIN 21 // The ESP32 S3 Uno pin GPIO21 (D8) connected to DS18B20 sensor Adafruit_SSD1306 oled(OLED_WIDTH, OLED_HEIGHT, &Wire, -1); // create SSD1306 display object connected to I2C OneWire oneWire(SENSOR_PIN); // setup a oneWire instance DallasTemperature DS18B20(&oneWire); // pass oneWire to DallasTemperature library String temperature_str; void setup() { Serial.begin(9600); // initialize OLED display with address 0x3C for 128x64 if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); while (true); } delay(2000); // wait for initializing oled.clearDisplay(); // clear display oled.setTextSize(2); // text size oled.setTextColor(WHITE); // text color oled.setCursor(0, 10); // position to display DS18B20.begin(); // initialize the sensor temperature_str.reserve(10); // to avoid fragmenting memory when using String } void loop() { DS18B20.requestTemperatures(); // send the command to get temperatures float temperature_C = DS18B20.getTempCByIndex(0); // read temperature in Celsius temperature_str = String(temperature_C, 2); // two decimal places temperature_str += char(247) + String("C"); Serial.println(temperature_str); // print the temperature in Celsius to Serial Monitor oled_display_center(temperature_str); } void oled_display_center(String text) { int16_t x1; int16_t y1; uint16_t width; uint16_t height; oled.getTextBounds(text, 0, 0, &x1, &y1, &width, &height); // center the display both horizontally and vertically oled.clearDisplay(); // clear display oled.setCursor((OLED_WIDTH - width) / 2, (OLED_HEIGHT - height) / 2); oled.println(text); // text to display oled.display(); }

Detailed Instructions

  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 the Arduino IDE.
  6. Search for "SSD1306" and find the SSD1306 library by Adafruit.
  7. Click Install to add the library.
  • Search for Adafruit SSD1306 created by Adafruit 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
Adafruit SSD1306 by Adafruit
SSD1306 oled driver library for monochrome 128x64 and 128x32 displays More info
2.5.9
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. Install the dependencies. The IDE asks for extra libraries. Click the Install All button.
  2. Search for "DallasTemperature" and find the DallasTemperature library by Miles Burton.
  3. Click Install to add the DallasTemperature library.
  • 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 OneWire library. The IDE asks for this dependency. Click the Install All button.
  2. Copy the code above and paste it into the Arduino IDE.
  3. Upload the code by clicking the Upload button.
  4. Change the temperature. Put the sensor in hot or cold water, or hold it in your hand.
  5. Check the result on the OLED screen and in the Serial Monitor at 9600 baud.
  6. Tip: if you use the 128x32 OLED, change OLED_HEIGHT to 32 so the text stays in the center.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
26.31°C 26.44°C 27.06°C 28.19°C 29.75°C
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

※ NOTE THAT:

The code puts the text in the middle of the OLED, both across and down. You do not need to set the position by hand.

Video Tutorial

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

FAQ

Why does the code use pin 21 and not 8?

The board has Uno header labels, but the code uses GPIO numbers. Header D8 is GPIO21 on the ESP32 S3 Uno. So SENSOR_PIN is 21.

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. It is also the safe choice, because the ESP32 S3 Uno pins are not 5V tolerant. Pull the DATA line up to 3.3V too.

Can I connect the OLED to A4 and A5 like on the UNO R4?

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

Why does the OLED show -127.00°C?

This value means the board cannot talk to the sensor. Check the DATA wire on D8, the GND wire, and the pull-up resistor. A bare DS18B20 without the adapter needs a 4.7 kΩ resistor between DATA and 3.3V.

How can I show the temperature in Fahrenheit?

Use DS18B20.getTempFByIndex(0) instead of getTempCByIndex(0), and change the "C" in the text to "F". You can also convert it yourself with F = C × 1.8 + 32.

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 (I/O, PWM, analog), GPIO45 and GPIO35 to GPIO42 (I/O, PWM), and GPIO47/GPIO48 (output only, PWM). Solder pin headers to them and write the GPIO number in code. For a second 1-Wire bus or more sensors, use GPIO35 to GPIO42. Do not use GPIO47/GPIO48 for a DS18B20, because 1-Wire needs input too. Be careful with two things. First, GPIO47/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 missing or bad cable Install the CP210x or CH340 driver, try a data USB cable, or hold BOOT while pressing RESET
OLED shows nothing Wrong I2C pins or wrong address Wire SDA to GPIO8 and SCL to GPIO9 (not A4/A5) and try address 0x3D
Serial Monitor shows SSD1306 allocation failed OLED not found on the I2C bus Check the OLED power and I2C wires, then press RESET
OLED shows -127.00°C Sensor not found on the 1-Wire bus Check the DATA wire on D8 and GND, and add a 4.7 kΩ pull-up to 3.3V
Temperature always shows 85.00°C Sensor read before the conversion ended or power is weak Check the VCC wire and use normal power mode, not parasite power
Text is not centered on a 128x32 OLED OLED_HEIGHT is still 64 Set OLED_HEIGHT to 32 in the code
Missing library error when compiling SSD1306, GFX, DallasTemperature or OneWire not installed Install all four libraries from the Library Manager
Serial Monitor shows strange characters Wrong baud rate Set the Serial Monitor to 9600 baud

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